diff --git a/src/chatbot/chatbot.module.ts b/src/chatbot/chatbot.module.ts index 0e61e04..13db2e3 100644 --- a/src/chatbot/chatbot.module.ts +++ b/src/chatbot/chatbot.module.ts @@ -4,7 +4,11 @@ import { HttpModule } from '@nestjs/axios'; import { ChatbotService } from 'src/chatbot/chatbot.service'; @Module({ - imports: [HttpModule], + imports: [ + HttpModule.register({ + timeout: 5 * 60 * 1000, // 5 minutes in milliseconds + }) + ], controllers: [ChatbotController], providers: [ChatbotService], exports: [], diff --git a/src/chatbot/chatbot.service.ts b/src/chatbot/chatbot.service.ts index 6fe900d..3df19d7 100644 --- a/src/chatbot/chatbot.service.ts +++ b/src/chatbot/chatbot.service.ts @@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common'; import { UserMessageDto } from 'src/chatbot/dtos/user-message.dto'; import { HttpService } from '@nestjs/axios'; import { firstValueFrom } from 'rxjs'; -import { PageContextDto } from 'src/chatbot/dtos/page-context.dto'; import { Message } from 'src/chatbot/dtos/dialog-message.dto'; +import { AxiosError, isAxiosError } from 'axios'; @Injectable() export class ChatbotService { @@ -11,15 +11,24 @@ export class ChatbotService { sessionId: string = 'testing'; async pingExternalApi(body: UserMessageDto, email: string): Promise { - const { data } = await firstValueFrom(this.httpService.post( - 'https://n8nai.targo.ca/webhook/chatty-Mcbot', - { userInput: body.userInput, userId: email, sessionId: this.sessionId, pageContext: body.pageContext ?? undefined } - )); + try { + const { data } = await firstValueFrom(this.httpService.post( + 'https://n8nai.targo.ca/webhook/chatty-Mcbot', + { userInput: body.userInput, userId: email, sessionId: this.sessionId, pageContext: body.pageContext ?? undefined } + )); + + return { + text: data[0].output, + sent: false, + }; + } catch (error) { + console.error(error); - return { - text: data[0].output, - sent: false, - }; + return { + text: 'chatbot.error.GENERIC_RESPONSE_ERROR', + sent: false, + } + } } // async sendPageContext(body: PageContextDto, email: string) {