refactor(chatbot): change context logic, adding context to chat request instead of sending on page change
This commit is contained in:
parent
63cc2a4458
commit
11d841e868
|
|
@ -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<string> {
|
||||
const sendPageContext = await this.chatbotService.sendPageContext(body);
|
||||
return sendPageContext;
|
||||
}
|
||||
// @Post('context')
|
||||
// @ModuleAccessAllowed(ModulesEnum.chatbot)
|
||||
// async sendContext(@Body() body: PageContextDto): Promise<string> {
|
||||
// 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<boolean> {
|
||||
const sendUserContext = await this.chatbotService.sendUserContext(email);
|
||||
return sendUserContext;
|
||||
}
|
||||
// @Post('user')
|
||||
// @ModuleAccessAllowed(ModulesEnum.chatbot)
|
||||
// async sendUserCredentials(@Access('email') email: string,): Promise<boolean> {
|
||||
// const sendUserContext = await this.chatbotService.sendUserContext(email);
|
||||
// return sendUserContext;
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ export class ChatbotService {
|
|||
sessionId: string = 'testing';
|
||||
|
||||
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: 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;
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user