From c9ff11b62a92266ca348c3f7a5bb55ce2d8607ad Mon Sep 17 00:00:00 2001 From: Ricardo Cunha Date: Thu, 12 Jun 2025 14:30:22 +0100 Subject: [PATCH] =?UTF-8?q?ChatBot=20-=20A=20funcionar=20com=20a=20estrutu?= =?UTF-8?q?ra=20mas=20com=20erros=20na=20tradu=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChatBot-Frontend/src/app/app.component.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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.' }); + } + }); }} -