diff --git a/ChatBot-Frontend/src/app/app.component.ts b/ChatBot-Frontend/src/app/app.component.ts index 594a5ad..ca4d997 100644 --- a/ChatBot-Frontend/src/app/app.component.ts +++ b/ChatBot-Frontend/src/app/app.component.ts @@ -28,11 +28,16 @@ export class AppComponent { } enviarMensagem() { - if (!this.userMessage.trim()) return; - this.chatHistory.push({ sender: 'user', text: this.userMessage }); - this.userMessage = ''; - setTimeout(() => { - this.chatHistory.push({ sender: 'bot', text: 'Resposta do bot!' }); - }, 300); + if (!this.userMessage.trim()) return; + const mensagem = this.userMessage; + this.chatHistory.push({ sender: 'user', text: mensagem }); + this.userMessage = ''; + this.chatService.sendMessage(mensagem).subscribe({ + next: (res: any) => { + this.chatHistory.push({ sender: 'bot', text: res.reply || 'Sem resposta do bot.' }); + }, + error: () => { + this.chatHistory.push({ sender: 'bot', text: 'Erro ao contactar o servidor.' }); + } + }); }} -