diff --git a/src/chatbot/chatbot.controller.ts b/src/chatbot/chatbot.controller.ts index 26b6f82..392a9ad 100644 --- a/src/chatbot/chatbot.controller.ts +++ b/src/chatbot/chatbot.controller.ts @@ -17,18 +17,18 @@ export class ChatbotController { return await this.chatbotService.pingExternalApi(body, email); } - @Post('context') - @ModuleAccessAllowed(ModulesEnum.chatbot) - async sendContext(@Body() body: PageContextDto): Promise { - const sendPageContext = await this.chatbotService.sendPageContext(body); - return sendPageContext; - } + // @Post('context') + // @ModuleAccessAllowed(ModulesEnum.chatbot) + // async sendContext(@Body() body: PageContextDto): Promise { + // const sendPageContext = await this.chatbotService.sendPageContext(body); + // return sendPageContext; + // } // Will have to modify later on to accomodate newer versions of User Auth/User type Structure - @Post('user') - @ModuleAccessAllowed(ModulesEnum.chatbot) - async sendUserCredentials(@Access('email') email: string,): Promise { - const sendUserContext = await this.chatbotService.sendUserContext(email); - return sendUserContext; - } + // @Post('user') + // @ModuleAccessAllowed(ModulesEnum.chatbot) + // async sendUserCredentials(@Access('email') email: string,): Promise { + // const sendUserContext = await this.chatbotService.sendUserContext(email); + // return sendUserContext; + // } } diff --git a/src/chatbot/chatbot.service.ts b/src/chatbot/chatbot.service.ts index ed95920..6fe900d 100644 --- a/src/chatbot/chatbot.service.ts +++ b/src/chatbot/chatbot.service.ts @@ -11,7 +11,10 @@ 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: email })); + 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, @@ -19,33 +22,33 @@ export class ChatbotService { }; } - async sendPageContext(body: PageContextDto) { - const { data } = await firstValueFrom( - this.httpService.post( - 'https://n8nai.targo.ca/webhook/chatty-Mcbot', - { features: body, userId: this.sessionId, userInput: '' }, - ), - ); - return data; - } + // async sendPageContext(body: PageContextDto, email: string) { + // const { data } = await firstValueFrom( + // this.httpService.post( + // 'https://n8nai.targo.ca/webhook/chatty-Mcbot', + // { features: body, userId: email, userInput: '' }, + // ), + // ); + // return data; + // } // Will have to modify later on to accomodate newer versions of User Auth/User type Structure - async sendUserContext(user_email: string) { - if (!this.sessionId) { - this.sessionId = 'SessionId = ' + user_email; - } + // async sendUserContext(user_email: string) { + // if (!this.sessionId) { + // this.sessionId = 'SessionId = ' + user_email; + // } - const response = await firstValueFrom( - this.httpService.post( - 'https://n8nai.targo.ca/webhook/chatty-Mcbot', - { - userId: this.sessionId, - userInput: '', - features: '', - }, - { headers: { 'Content-Tyoe': 'application/json' } }, - ), - ); - return response.data; - } + // const response = await firstValueFrom( + // this.httpService.post( + // 'https://n8nai.targo.ca/webhook/chatty-Mcbot', + // { + // userId: this.sessionId, + // userInput: '', + // features: '', + // }, + // { headers: { 'Content-Tyoe': 'application/json' } }, + // ), + // ); + // return response.data; + // } } diff --git a/src/chatbot/dtos/user-message.dto.ts b/src/chatbot/dtos/user-message.dto.ts index 5ee99b1..39cb1c6 100644 --- a/src/chatbot/dtos/user-message.dto.ts +++ b/src/chatbot/dtos/user-message.dto.ts @@ -1,9 +1,11 @@ -import { Transform } from 'class-transformer'; -import { IsNotEmpty, IsString } from 'class-validator'; +import { Transform, Type } from 'class-transformer'; +import { IsNotEmpty, IsOptional, IsString } from 'class-validator'; +import { PageContextDto } from './page-context.dto'; export class UserMessageDto { @IsString() @IsNotEmpty() @Transform(({ value }) => value.trim()) userInput!: string; + @IsOptional() @Type(() => PageContextDto) pageContext?: PageContextDto | undefined; }