async sendMessage()

in frontend/src/app/customer-service-agent/customer/customer.component.ts [169:195]


  async sendMessage(event?: any) {
    event.preventDefault();
    let conversationId = "new";
    if (this.conversationId) {
      conversationId = this.conversationId;
    }
    const message: ChatMessage = {
      author: "User",
      language: this.userLanguage,
      text: this.msgFormGroup.value.msgCtrl,
    }
    this.msgFormGroup.setValue({ msgCtrl: "" });

    this.customerServiceAgentService.addMessage(this.userId, conversationId, message).subscribe((res: any) => {
      if (!this.conversationId && res.conversation_id) {
        this.conversationId = res.conversation_id;
        let chatMessages$ = this.firebaseService.getChatMessages(this.userId, this.conversationId!) as Observable<ChatMessage[]>;
        this.chatMessageSubscription = chatMessages$.subscribe(async (res: ChatMessage[]) => {
          this.messages = await Promise.all(res.map(async (message: ChatMessage) => {
            const translateRes: any = await firstValueFrom(this.customerServiceAgentService.translateText(message.text, this.userLanguage))
            message.text = translateRes.output_text;
            return message;
          }));
        });
      }
    })
  }