mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 07:04:50 -06:00
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.
This commit is contained in:
parent
7682a679d1
commit
19e291178c
@ -89,8 +89,7 @@ export class FlowiseController extends BaseChatbotController<FlowiseModel, Flowi
|
||||
|
||||
// Override createBot to add module availability check and Flowise-specific validation
|
||||
public async createBot(instance: InstanceDto, data: FlowiseDto) {
|
||||
if (!this.integrationEnabled)
|
||||
throw new BadRequestException('Flowise is disabled');
|
||||
if (!this.integrationEnabled) throw new BadRequestException('Flowise is disabled');
|
||||
|
||||
const instanceId = await this.prismaRepository.instance
|
||||
.findFirst({
|
||||
|
@ -173,7 +173,7 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
||||
}
|
||||
|
||||
// Process with the appropriate API based on bot type
|
||||
await this.sendMessageToBot(instance, session, settings, openaiBot, remoteJid, pushName || '', content, msg);
|
||||
await this.sendMessageToBot(instance, session, settings, openaiBot, remoteJid, pushName || '', content);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error in process: ${error.message || JSON.stringify(error)}`);
|
||||
return;
|
||||
@ -191,7 +191,6 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
||||
remoteJid: string,
|
||||
pushName: string,
|
||||
content: string,
|
||||
msg?: any,
|
||||
): Promise<void> {
|
||||
this.logger.log(`Sending message to bot for remoteJid: ${remoteJid}, bot type: ${openaiBot.botType}`);
|
||||
|
||||
@ -223,11 +222,10 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
||||
pushName,
|
||||
false, // Not fromMe
|
||||
content,
|
||||
msg,
|
||||
);
|
||||
} else {
|
||||
this.logger.log('Processing with ChatCompletion API');
|
||||
message = await this.processChatCompletionMessage(instance, openaiBot, remoteJid, content, msg);
|
||||
message = await this.processChatCompletionMessage(instance, openaiBot, remoteJid, content);
|
||||
}
|
||||
|
||||
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>
|
||||
pushName: string,
|
||||
fromMe: boolean,
|
||||
content: string,
|
||||
msg?: any,
|
||||
): Promise<string> {
|
||||
const messageData: any = {
|
||||
role: fromMe ? 'assistant' : 'user',
|
||||
@ -379,7 +376,6 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
||||
openaiBot: OpenaiBot,
|
||||
remoteJid: string,
|
||||
content: string,
|
||||
msg?: any,
|
||||
): Promise<string> {
|
||||
this.logger.log('Starting processChatCompletionMessage');
|
||||
|
||||
|
@ -96,8 +96,7 @@ export class TypebotController extends BaseChatbotController<TypebotModel, Typeb
|
||||
|
||||
// TypeBot specific method for starting a bot from API
|
||||
public async startBot(instance: InstanceDto, data: any) {
|
||||
if (!this.integrationEnabled)
|
||||
throw new BadRequestException('Typebot is disabled');
|
||||
if (!this.integrationEnabled) throw new BadRequestException('Typebot is disabled');
|
||||
|
||||
if (data.remoteJid === 'status@broadcast') return;
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { IgnoreJidDto } from '@api/dto/chatbot.dto';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { TypebotDto, TypebotSettingDto } from '@api/integrations/chatbot/typebot/dto/typebot.dto';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { typebotController } from '@api/server.module';
|
||||
import {
|
||||
instanceSchema,
|
||||
typebotIgnoreJidSchema,
|
||||
@ -10,11 +12,8 @@ import {
|
||||
typebotStartSchema,
|
||||
typebotStatusSchema,
|
||||
} from '@validate/validate.schema';
|
||||
import { typebotController } from '@api/server.module';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
|
||||
export class TypebotRouter extends RouterBroker {
|
||||
constructor(...guards: RequestHandler[]) {
|
||||
super();
|
||||
|
Loading…
Reference in New Issue
Block a user