fix(chatbot): minor fixes to chatbot implementation, add chatbot to module access

This commit is contained in:
Nicolas Drolet 2026-01-12 14:11:50 -05:00
parent 28f90c027d
commit 8f93c2b0f7
6 changed files with 16 additions and 3 deletions

View File

@ -4,17 +4,21 @@ import { UserMessageDto } from 'src/chatbot/dtos/user-message.dto';
import { ChatbotService } from 'src/chatbot/chatbot.service';
import { PageContextDto } from 'src/chatbot/dtos/page-context.dto';
import { Access } from 'src/common/decorators/module-access.decorators';
import { ModuleAccessAllowed } from 'src/common/decorators/modules-guard.decorators';
import { Modules as ModulesEnum } from ".prisma/client";
@Controller('chatbot')
export class ChatbotController {
constructor(private readonly chatbotService: ChatbotService) {}
@Post('')
@ModuleAccessAllowed(ModulesEnum.chatbot)
async testConnection(@Body() body: UserMessageDto): Promise<Message> {
return await this.chatbotService.pingExternalApi(body);
}
@Post('context')
@ModuleAccessAllowed(ModulesEnum.chatbot)
async sendContext(@Body() body: PageContextDto): Promise<string> {
const sendPageContext = await this.chatbotService.sendPageContext(body);
return sendPageContext;
@ -22,6 +26,7 @@ export class ChatbotController {
// 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;

View File

@ -19,9 +19,11 @@ export class ChatbotService {
),
);
console.log('chatbot response: ', response);
const cleanText =
Array.isArray(response) && response[0]?.output
? response[0].output
Array.isArray(response.data) && response.data[0]?.output
? response.data[0].output
: JSON.stringify(response);
return {

View File

@ -6,7 +6,8 @@ export type Modules =
| 'employee_list'
| 'employee_management'
| 'personal_profile'
| 'dashboard';
| 'dashboard'
| 'chatbot';
export const module_list = [
'timesheets',
@ -15,4 +16,5 @@ export const module_list = [
'employee_management',
'personal_profile',
'dashboard',
'chatbot',
] as const;

View File

@ -154,6 +154,7 @@ export class EmployeesGetService {
personal_profile: true,
timesheets: true,
timesheets_approval: true,
chatbot: true,
},
},
},

View File

@ -53,6 +53,7 @@ export class EmployeesUpdateService {
personal_profile: normalized_access.personal_profile,
timesheets: normalized_access.timesheets,
timesheets_approval: normalized_access.timesheets_approval,
chatbot: normalized_access.chatbot,
},
create: {
user_id: user_id.data,
@ -62,6 +63,7 @@ export class EmployeesUpdateService {
personal_profile: normalized_access.personal_profile,
timesheets: normalized_access.timesheets,
timesheets_approval: normalized_access.timesheets_approval,
chatbot: normalized_access.chatbot,
},
});

View File

@ -19,6 +19,7 @@ export abstract class AbstractUserService {
personal_profile: true,
timesheets: true,
timesheets_approval: true,
chatbot: true,
},
},
},