mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 12:22:21 -06:00
refactor: integrations folder
This commit is contained in:
71
src/api/integrations/chatbot/chatbot.controller.ts
Normal file
71
src/api/integrations/chatbot/chatbot.controller.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import {
|
||||
difyController,
|
||||
openaiController,
|
||||
typebotController,
|
||||
websocketController,
|
||||
} from '@api/integrations/integration.module';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
|
||||
export class ChatbotController {
|
||||
public prismaRepository: PrismaRepository;
|
||||
public waMonitor: WAMonitoringService;
|
||||
|
||||
constructor(prismaRepository: PrismaRepository, waMonitor: WAMonitoringService) {
|
||||
this.prisma = prismaRepository;
|
||||
this.monitor = waMonitor;
|
||||
}
|
||||
|
||||
public set prisma(prisma: PrismaRepository) {
|
||||
this.prismaRepository = prisma;
|
||||
}
|
||||
|
||||
public get prisma() {
|
||||
return this.prismaRepository;
|
||||
}
|
||||
|
||||
public set monitor(waMonitor: WAMonitoringService) {
|
||||
this.waMonitor = waMonitor;
|
||||
}
|
||||
|
||||
public get monitor() {
|
||||
return this.waMonitor;
|
||||
}
|
||||
|
||||
public async emit({
|
||||
instance,
|
||||
remoteJid,
|
||||
msg,
|
||||
pushName,
|
||||
}: {
|
||||
instance: InstanceDto;
|
||||
remoteJid: string;
|
||||
msg: any;
|
||||
pushName?: string;
|
||||
}): Promise<void> {
|
||||
const emitData = {
|
||||
instance,
|
||||
remoteJid,
|
||||
msg,
|
||||
pushName,
|
||||
};
|
||||
// typebot
|
||||
await typebotController.emit(emitData);
|
||||
|
||||
// openai
|
||||
await openaiController.emit(emitData);
|
||||
|
||||
// dify
|
||||
await difyController.emit(emitData);
|
||||
}
|
||||
|
||||
public async setInstance(instanceName: string, data: any): Promise<any> {
|
||||
// chatwoot
|
||||
if (data.websocketEnabled)
|
||||
await websocketController.set(instanceName, {
|
||||
enabled: true,
|
||||
events: data.websocketEvents,
|
||||
});
|
||||
}
|
||||
}
|
||||
18
src/api/integrations/chatbot/chatbot.router.ts
Normal file
18
src/api/integrations/chatbot/chatbot.router.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ChatwootRouter } from '@api/integrations/chatbot/chatwoot/routes/chatwoot.router';
|
||||
import { DifyRouter } from '@api/integrations/chatbot/dify/routes/dify.router';
|
||||
import { OpenaiRouter } from '@api/integrations/chatbot/openai/routes/openai.router';
|
||||
import { TypebotRouter } from '@api/integrations/chatbot/typebot/routes/typebot.router';
|
||||
import { Router } from 'express';
|
||||
|
||||
export class ChatbotRouter {
|
||||
public readonly router: Router;
|
||||
|
||||
constructor(...guards: any[]) {
|
||||
this.router = Router();
|
||||
|
||||
this.router.use('/chatwoot', new ChatwootRouter(...guards).router);
|
||||
this.router.use('/typebot', new TypebotRouter(...guards).router);
|
||||
this.router.use('/openai', new OpenaiRouter(...guards).router);
|
||||
this.router.use('/dify', new DifyRouter(...guards).router);
|
||||
}
|
||||
}
|
||||
4
src/api/integrations/chatbot/chatbot.schema.ts
Normal file
4
src/api/integrations/chatbot/chatbot.schema.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from '@api/integrations/chatbot/chatwoot/validate/chatwoot.schema';
|
||||
export * from '@api/integrations/chatbot/dify/validate/dify.schema';
|
||||
export * from '@api/integrations/chatbot/openai/validate/openai.schema';
|
||||
export * from '@api/integrations/chatbot/typebot/validate/typebot.schema';
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Constructor } from '@api/dto/integration.dto';
|
||||
import { Constructor } from '@api/integrations/integration.dto';
|
||||
|
||||
export class ChatwootDto {
|
||||
enabled?: boolean;
|
||||
|
||||
@@ -66,4 +66,19 @@ export class DifyController {
|
||||
|
||||
return this.difyService.ignoreJid(instance, data);
|
||||
}
|
||||
|
||||
public async emit({
|
||||
instance,
|
||||
remoteJid,
|
||||
msg,
|
||||
}: {
|
||||
instance: InstanceDto;
|
||||
remoteJid: string;
|
||||
msg: any;
|
||||
pushName?: string;
|
||||
}) {
|
||||
if (!configService.get<Dify>('DIFY').ENABLED) return;
|
||||
|
||||
await this.difyService.sendDify(instance, remoteJid, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { DifyDto, DifyIgnoreJidDto, DifySettingDto } from '@api/integrations/chatbot/dify/dto/dify.dto';
|
||||
import { difyController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { difyController } from '@api/server.module';
|
||||
import {
|
||||
difyIgnoreJidSchema,
|
||||
difySchema,
|
||||
|
||||
@@ -90,4 +90,20 @@ export class OpenaiController {
|
||||
|
||||
return this.openaiService.ignoreJid(instance, data);
|
||||
}
|
||||
|
||||
public async emit({
|
||||
instance,
|
||||
remoteJid,
|
||||
msg,
|
||||
pushName,
|
||||
}: {
|
||||
instance: InstanceDto;
|
||||
remoteJid: string;
|
||||
msg: any;
|
||||
pushName?: string;
|
||||
}) {
|
||||
if (!configService.get<Openai>('OPENAI').ENABLED) return;
|
||||
|
||||
await this.openaiService.sendOpenai(instance, remoteJid, pushName, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
OpenaiIgnoreJidDto,
|
||||
OpenaiSettingDto,
|
||||
} from '@api/integrations/chatbot/openai/dto/openai.dto';
|
||||
import { openaiController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { openaiController } from '@api/server.module';
|
||||
import {
|
||||
instanceSchema,
|
||||
openaiCredsSchema,
|
||||
|
||||
@@ -72,4 +72,19 @@ export class TypebotController {
|
||||
|
||||
return this.typebotService.ignoreJid(instance, data);
|
||||
}
|
||||
|
||||
public async emit({
|
||||
instance,
|
||||
remoteJid,
|
||||
msg,
|
||||
}: {
|
||||
instance: InstanceDto;
|
||||
remoteJid: string;
|
||||
msg: any;
|
||||
pushName?: string;
|
||||
}) {
|
||||
if (!configService.get<Typebot>('TYPEBOT').ENABLED) return;
|
||||
|
||||
await this.typebotService.sendTypebot(instance, remoteJid, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { TypebotDto, TypebotIgnoreJidDto, TypebotSettingDto } from '@api/integrations/chatbot/typebot/dto/typebot.dto';
|
||||
import { typebotController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { typebotController } from '@api/server.module';
|
||||
import {
|
||||
instanceSchema,
|
||||
typebotIgnoreJidSchema,
|
||||
|
||||
Reference in New Issue
Block a user