in ChatbotUI/src/app/components/main/chat/chatbar/chatbar.component.ts [209:255]
async submitMessage(event: any) {
this.outOfContextAnswerResponseObject = {
like: false,
dislike: false
};
this.removeSuggestionElement();
this.pushQuestion(this.chatQuery);
this.botStartTime = new Date().getTime();
// keeps the scrollbar to the bottom
const parentElement = document.getElementsByClassName('chat-body');
parentElement[0].scrollTo(0, parentElement[0].scrollHeight);
if (event instanceof KeyboardEvent || event instanceof MouseEvent) {
event.preventDefault();
}
if (!this.chatQuery || this.chatQuery === '') {
return;
}
if (!this.initialQuestion) this.initialQuestion = this.chatQuery;
let singleMessage: Message = {
body: this.chatQuery,
type: 'user',
shareable: true,
}
this.conversation.unshift(singleMessage);
this.chatQuery = '';
this.showLoader = true;
this.setTimeoutForLoaderText();
this.setCyclicBackgroundImages();
this.chatService.postChat([...this.conversation]).subscribe({
next: (event: HttpEvent<string>) => {
if (event.type === HttpEventType.DownloadProgress) {
this.handleBotResponse(
(event as HttpDownloadProgressEvent).partialText as string
);
} else if (event.type === HttpEventType.Response) {
this.handleBotResponse(event.body as string);
}
},
error: () => {
console.log("Error getting stream events");
},
});
}