Skip to content

Commit 19e2911

Browse files
committed
refactor: streamline integration checks and parameter handling in chatbot controllers
This commit refines the Flowise and Typebot integrations by simplifying the integration enablement checks in their respective controllers. Key changes include: - Consolidated the integration checks in the createBot method of FlowiseController and startBot method of TypebotController for improved readability. - Removed unnecessary line breaks to enhance code clarity. These updates contribute to a cleaner and more maintainable codebase for chatbot integrations.
1 parent 7682a67 commit 19e2911

File tree

4 files changed

+6
-13
lines changed

4 files changed

+6
-13
lines changed

src/api/integrations/chatbot/flowise/controllers/flowise.controller.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ export class FlowiseController extends BaseChatbotController<FlowiseModel, Flowi
8989

9090
// Override createBot to add module availability check and Flowise-specific validation
9191
public async createBot(instance: InstanceDto, data: FlowiseDto) {
92-
if (!this.integrationEnabled)
93-
throw new BadRequestException('Flowise is disabled');
92+
if (!this.integrationEnabled) throw new BadRequestException('Flowise is disabled');
9493

9594
const instanceId = await this.prismaRepository.instance
9695
.findFirst({

src/api/integrations/chatbot/openai/services/openai.service.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
173173
}
174174

175175
// Process with the appropriate API based on bot type
176-
await this.sendMessageToBot(instance, session, settings, openaiBot, remoteJid, pushName || '', content, msg);
176+
await this.sendMessageToBot(instance, session, settings, openaiBot, remoteJid, pushName || '', content);
177177
} catch (error) {
178178
this.logger.error(`Error in process: ${error.message || JSON.stringify(error)}`);
179179
return;
@@ -191,7 +191,6 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
191191
remoteJid: string,
192192
pushName: string,
193193
content: string,
194-
msg?: any,
195194
): Promise<void> {
196195
this.logger.log(`Sending message to bot for remoteJid: ${remoteJid}, bot type: ${openaiBot.botType}`);
197196

@@ -223,11 +222,10 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
223222
pushName,
224223
false, // Not fromMe
225224
content,
226-
msg,
227225
);
228226
} else {
229227
this.logger.log('Processing with ChatCompletion API');
230-
message = await this.processChatCompletionMessage(instance, openaiBot, remoteJid, content, msg);
228+
message = await this.processChatCompletionMessage(instance, openaiBot, remoteJid, content);
231229
}
232230

233231
this.logger.log(`Got response from OpenAI: ${message?.substring(0, 50)}${message?.length > 50 ? '...' : ''}`);
@@ -270,7 +268,6 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
270268
pushName: string,
271269
fromMe: boolean,
272270
content: string,
273-
msg?: any,
274271
): Promise<string> {
275272
const messageData: any = {
276273
role: fromMe ? 'assistant' : 'user',
@@ -379,7 +376,6 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
379376
openaiBot: OpenaiBot,
380377
remoteJid: string,
381378
content: string,
382-
msg?: any,
383379
): Promise<string> {
384380
this.logger.log('Starting processChatCompletionMessage');
385381

src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ export class TypebotController extends BaseChatbotController<TypebotModel, Typeb
9696

9797
// TypeBot specific method for starting a bot from API
9898
public async startBot(instance: InstanceDto, data: any) {
99-
if (!this.integrationEnabled)
100-
throw new BadRequestException('Typebot is disabled');
99+
if (!this.integrationEnabled) throw new BadRequestException('Typebot is disabled');
101100

102101
if (data.remoteJid === 'status@broadcast') return;
103102

src/api/integrations/chatbot/typebot/routes/typebot.router.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { RouterBroker } from '@api/abstract/abstract.router';
12
import { IgnoreJidDto } from '@api/dto/chatbot.dto';
23
import { InstanceDto } from '@api/dto/instance.dto';
34
import { TypebotDto, TypebotSettingDto } from '@api/integrations/chatbot/typebot/dto/typebot.dto';
45
import { HttpStatus } from '@api/routes/index.router';
6+
import { typebotController } from '@api/server.module';
57
import {
68
instanceSchema,
79
typebotIgnoreJidSchema,
@@ -10,11 +12,8 @@ import {
1012
typebotStartSchema,
1113
typebotStatusSchema,
1214
} from '@validate/validate.schema';
13-
import { typebotController } from '@api/server.module';
1415
import { RequestHandler, Router } from 'express';
1516

16-
import { RouterBroker } from '@api/abstract/abstract.router';
17-
1817
export class TypebotRouter extends RouterBroker {
1918
constructor(...guards: RequestHandler[]) {
2019
super();

0 commit comments

Comments
 (0)