From 8410a3f7c69cfb82bbc0c680c12c2627840ea923 Mon Sep 17 00:00:00 2001 From: Nic D Date: Wed, 14 Jan 2026 16:06:50 -0500 Subject: [PATCH] fix(chatbot): change post address, object structure, handling of response --- src/chatbot/chatbot.controller.ts | 4 +-- src/chatbot/chatbot.service.ts | 27 +++++++------------ .../timesheet-employee-overview.service.ts | 1 + 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/chatbot/chatbot.controller.ts b/src/chatbot/chatbot.controller.ts index 73367f9..26b6f82 100644 --- a/src/chatbot/chatbot.controller.ts +++ b/src/chatbot/chatbot.controller.ts @@ -13,8 +13,8 @@ export class ChatbotController { @Post('') @ModuleAccessAllowed(ModulesEnum.chatbot) - async testConnection(@Body() body: UserMessageDto): Promise { - return await this.chatbotService.pingExternalApi(body); + async testConnection(@Body() body: UserMessageDto, @Access('email') email: string): Promise { + return await this.chatbotService.pingExternalApi(body, email); } @Post('context') diff --git a/src/chatbot/chatbot.service.ts b/src/chatbot/chatbot.service.ts index 5692bb8..a908a2f 100644 --- a/src/chatbot/chatbot.service.ts +++ b/src/chatbot/chatbot.service.ts @@ -8,35 +8,26 @@ import { Message } from 'src/chatbot/dtos/dialog-message.dto'; @Injectable() export class ChatbotService { constructor(private readonly httpService: HttpService) { } - sessionId: string; + sessionId: string = 'testing'; - async pingExternalApi(body: UserMessageDto): Promise { - const response = await firstValueFrom( - this.httpService.post( - 'https://n8nai.targo.ca/webhook/984c578e-59c7-4ca1-97f8-e225fd2acf01', - { userInput: body.userInput, userId: this.sessionId }, - ), - ); - - const cleanText = - Array.isArray(response.data) && response.data[0]?.output - ? response.data[0].output - : JSON.stringify(response); + 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 })); + console.log(data); return { - text: cleanText, + text: data[0].output, sent: false, }; } async sendPageContext(body: PageContextDto) { - const response = await firstValueFrom( + const { data } = await firstValueFrom( this.httpService.post( - 'https://n8nai.targo.ca/webhook/984c578e-59c7-4ca1-97f8-e225fd2acf01', + 'https://n8nai.targo.ca/webhook/chatty-Mcbot', { features: body, userId: this.sessionId, userInput: '' }, ), ); - return response.data; + return data; } // Will have to modify later on to accomodate newer versions of User Auth/User type Structure @@ -47,7 +38,7 @@ export class ChatbotService { const response = await firstValueFrom( this.httpService.post( - 'https://n8nai.targo.ca/webhook/984c578e-59c7-4ca1-97f8-e225fd2acf01', + 'https://n8nai.targo.ca/webhook/chatty-Mcbot', { userId: this.sessionId, userInput: '', diff --git a/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts b/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts index 17dd885..8ce539d 100644 --- a/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts +++ b/src/time-and-attendance/timesheets/services/timesheet-employee-overview.service.ts @@ -33,6 +33,7 @@ export class GetTimesheetsOverviewService { //loads the timesheets related to the fetched pay-period let rows = await this.loadTimesheets(employee_id.data, period.period_start, period.period_end); + console.log(rows); //Normalized dates from pay-period strings const normalized_start = toDateFromString(period.period_start);