fix(chatbot): change post address, object structure, handling of response

This commit is contained in:
Nic D 2026-01-14 16:06:50 -05:00
parent e259851b87
commit 8410a3f7c6
3 changed files with 12 additions and 20 deletions

View File

@ -13,8 +13,8 @@ export class ChatbotController {
@Post('')
@ModuleAccessAllowed(ModulesEnum.chatbot)
async testConnection(@Body() body: UserMessageDto): Promise<Message> {
return await this.chatbotService.pingExternalApi(body);
async testConnection(@Body() body: UserMessageDto, @Access('email') email: string): Promise<Message> {
return await this.chatbotService.pingExternalApi(body, email);
}
@Post('context')

View File

@ -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<Message> {
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<Message> {
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: '',

View File

@ -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);