mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-18 04:56:30 -06:00
refactor: integrations folder
This commit is contained in:
parent
884362e70c
commit
2ec0b842c1
@ -1,7 +1,6 @@
|
||||
import { IntegrationDto } from '@api/integrations/integration.dto';
|
||||
import { WAPresence } from 'baileys';
|
||||
|
||||
import { IntegrationDto } from './integration.dto';
|
||||
|
||||
export class InstanceDto extends IntegrationDto {
|
||||
instanceName: string;
|
||||
instanceId?: string;
|
||||
|
@ -48,7 +48,7 @@ import { chatwootImport } from '@api/integrations/chatbot/chatwoot/utils/chatwoo
|
||||
import * as s3Service from '@api/integrations/storage/s3/libs/minio.server';
|
||||
import { ProviderFiles } from '@api/provider/sessions';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { waMonitor } from '@api/server.module';
|
||||
import { chatbotController, waMonitor } from '@api/server.module';
|
||||
import { CacheService } from '@api/services/cache.service';
|
||||
import { ChannelStartupService } from '@api/services/channel.service';
|
||||
import { Events, MessageSubtype, TypeMediaMessage, wa } from '@api/types/wa.types';
|
||||
@ -1223,39 +1223,12 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
|
||||
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
|
||||
|
||||
if (this.configService.get<Typebot>('TYPEBOT').ENABLED) {
|
||||
if (type === 'notify') {
|
||||
if (messageRaw.messageType !== 'reactionMessage')
|
||||
await this.typebotService.sendTypebot(
|
||||
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
messageRaw.key.remoteJid,
|
||||
messageRaw,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.configService.get<Openai>('OPENAI').ENABLED) {
|
||||
if (type === 'notify') {
|
||||
if (messageRaw.messageType !== 'reactionMessage')
|
||||
await this.openaiService.sendOpenai(
|
||||
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
messageRaw.key.remoteJid,
|
||||
messageRaw.pushName,
|
||||
messageRaw,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.configService.get<Dify>('DIFY').ENABLED) {
|
||||
if (type === 'notify') {
|
||||
if (messageRaw.messageType !== 'reactionMessage')
|
||||
await this.difyService.sendDify(
|
||||
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
messageRaw.key.remoteJid,
|
||||
messageRaw,
|
||||
);
|
||||
}
|
||||
}
|
||||
await chatbotController.emit({
|
||||
instance: { instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
remoteJid: messageRaw.key.remoteJid,
|
||||
msg: messageRaw,
|
||||
pushName: messageRaw.pushName,
|
||||
});
|
||||
|
||||
const contact = await this.prismaRepository.contact.findFirst({
|
||||
where: { remoteJid: received.key.remoteJid, instanceId: this.instanceId },
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
import * as s3Service from '@api/integrations/storage/s3/libs/minio.server';
|
||||
import { ProviderFiles } from '@api/provider/sessions';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { chatbotController } from '@api/server.module';
|
||||
import { CacheService } from '@api/services/cache.service';
|
||||
import { ChannelStartupService } from '@api/services/channel.service';
|
||||
import { Events, wa } from '@api/types/wa.types';
|
||||
@ -481,6 +482,13 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
|
||||
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
|
||||
|
||||
await chatbotController.emit({
|
||||
instance: { instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
remoteJid: messageRaw.key.remoteJid,
|
||||
msg: messageRaw,
|
||||
pushName: messageRaw.pushName,
|
||||
});
|
||||
|
||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
|
||||
Events.MESSAGES_UPSERT,
|
||||
@ -495,34 +503,6 @@ export class BusinessStartupService extends ChannelStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.configService.get<Typebot>('TYPEBOT').ENABLED) {
|
||||
if (messageRaw.messageType !== 'reactionMessage')
|
||||
await this.typebotService.sendTypebot(
|
||||
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
messageRaw.key.remoteJid,
|
||||
messageRaw,
|
||||
);
|
||||
}
|
||||
|
||||
if (this.configService.get<Openai>('OPENAI').ENABLED) {
|
||||
if (messageRaw.messageType !== 'reactionMessage')
|
||||
await this.openaiService.sendOpenai(
|
||||
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
messageRaw.key.remoteJid,
|
||||
pushName,
|
||||
messageRaw,
|
||||
);
|
||||
}
|
||||
|
||||
if (this.configService.get<Dify>('DIFY').ENABLED) {
|
||||
if (messageRaw.messageType !== 'reactionMessage')
|
||||
await this.difyService.sendDify(
|
||||
{ instanceName: this.instance.name, instanceId: this.instanceId },
|
||||
messageRaw.key.remoteJid,
|
||||
messageRaw,
|
||||
);
|
||||
}
|
||||
|
||||
await this.prismaRepository.message.create({
|
||||
data: messageRaw,
|
||||
});
|
||||
|
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,
|
||||
});
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -1,5 +1,10 @@
|
||||
import {
|
||||
rabbitmqController,
|
||||
sqsController,
|
||||
webhookController,
|
||||
websocketController,
|
||||
} from '@api/integrations/integration.module';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { rabbitmqController, sqsController, webhookController, websocketController } from '@api/server.module';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
import { Server } from 'http';
|
||||
|
4
src/api/integrations/event/event.schema.ts
Normal file
4
src/api/integrations/event/event.schema.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from '@api/integrations/event/rabbitmq/validate/rabbitmq.schema';
|
||||
export * from '@api/integrations/event/sqs/validate/sqs.schema';
|
||||
export * from '@api/integrations/event/webhook/validate/webhook.schema';
|
||||
export * from '@api/integrations/event/websocket/validate/websocket.schema';
|
@ -1,4 +1,3 @@
|
||||
import { EventController } from '@api/controllers/event.controller';
|
||||
import { RabbitmqDto } from '@api/integrations/event/rabbitmq/dto/rabbitmq.dto';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
@ -8,6 +7,8 @@ import { Logger } from '@config/logger.config';
|
||||
import { NotFoundException } from '@exceptions';
|
||||
import * as amqp from 'amqplib/callback_api';
|
||||
|
||||
import { EventController } from '../../event.controller';
|
||||
|
||||
export class RabbitmqController extends EventController {
|
||||
public amqpChannel: amqp.Channel | null = null;
|
||||
private readonly logger = new Logger(RabbitmqController.name);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Constructor } from '@api/dto/integration.dto';
|
||||
import { Constructor } from '@api/integrations/integration.dto';
|
||||
|
||||
export class RabbitmqDto {
|
||||
enabled: boolean;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { RabbitmqDto } from '@api/integrations/event/rabbitmq/dto/rabbitmq.dto';
|
||||
import { rabbitmqController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { rabbitmqController } from '@api/server.module';
|
||||
import { instanceSchema, rabbitmqSchema } from '@validate/validate.schema';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { EventController } from '@api/controllers/event.controller';
|
||||
import { SqsDto } from '@api/integrations/event/sqs/dto/sqs.dto';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
@ -8,6 +7,8 @@ import { configService, Log, Sqs } from '@config/env.config';
|
||||
import { Logger } from '@config/logger.config';
|
||||
import { NotFoundException } from '@exceptions';
|
||||
|
||||
import { EventController } from '../../event.controller';
|
||||
|
||||
export class SqsController extends EventController {
|
||||
private sqs: SQS;
|
||||
private readonly logger = new Logger(SqsController.name);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Constructor } from '@api/dto/integration.dto';
|
||||
import { Constructor } from '@api/integrations/integration.dto';
|
||||
|
||||
export class SqsDto {
|
||||
enabled: boolean;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { SqsDto } from '@api/integrations/event/sqs/dto/sqs.dto';
|
||||
import { sqsController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { sqsController } from '@api/server.module';
|
||||
import { instanceSchema, sqsSchema } from '@validate/validate.schema';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { EventController } from '@api/controllers/event.controller';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
import { wa } from '@api/types/wa.types';
|
||||
@ -8,6 +7,7 @@ import { BadRequestException, NotFoundException } from '@exceptions';
|
||||
import axios from 'axios';
|
||||
import { isURL } from 'class-validator';
|
||||
|
||||
import { EventController } from '../../event.controller';
|
||||
import { WebhookDto } from '../dto/webhook.dto';
|
||||
|
||||
export class WebhookController extends EventController {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Constructor } from '@api/dto/integration.dto';
|
||||
import { Constructor } from '@api/integrations/integration.dto';
|
||||
|
||||
export class WebhookDto {
|
||||
enabled?: boolean;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { webhookController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { webhookController } from '@api/server.module';
|
||||
import { ConfigService } from '@config/env.config';
|
||||
import { ConfigService, WaBusiness } from '@config/env.config';
|
||||
import { instanceSchema, webhookSchema } from '@validate/validate.schema';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
@ -31,6 +31,17 @@ export class WebhookRouter extends RouterBroker {
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.get('meta', async (req, res) => {
|
||||
if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK)
|
||||
res.send(req.query['hub.challenge']);
|
||||
else res.send('Error, wrong validation token');
|
||||
})
|
||||
.post('meta', async (req, res) => {
|
||||
const { body } = req;
|
||||
const response = await webhookController.receiveWebhook(body);
|
||||
|
||||
return res.status(200).json(response);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,65 +0,0 @@
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||
const properties = {};
|
||||
propertyNames.forEach(
|
||||
(property) =>
|
||||
(properties[property] = {
|
||||
minLength: 1,
|
||||
description: `The "${property}" cannot be empty`,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
if: {
|
||||
propertyNames: {
|
||||
enum: [...propertyNames],
|
||||
},
|
||||
},
|
||||
then: { properties },
|
||||
};
|
||||
};
|
||||
|
||||
export const websocketSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
enabled: { type: 'boolean', enum: [true, false] },
|
||||
events: {
|
||||
type: 'array',
|
||||
minItems: 0,
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: [
|
||||
'APPLICATION_STARTUP',
|
||||
'QRCODE_UPDATED',
|
||||
'MESSAGES_SET',
|
||||
'MESSAGES_UPSERT',
|
||||
'MESSAGES_EDITED',
|
||||
'MESSAGES_UPDATE',
|
||||
'MESSAGES_DELETE',
|
||||
'SEND_MESSAGE',
|
||||
'CONTACTS_SET',
|
||||
'CONTACTS_UPSERT',
|
||||
'CONTACTS_UPDATE',
|
||||
'PRESENCE_UPDATE',
|
||||
'CHATS_SET',
|
||||
'CHATS_UPSERT',
|
||||
'CHATS_UPDATE',
|
||||
'CHATS_DELETE',
|
||||
'GROUPS_UPSERT',
|
||||
'GROUP_UPDATE',
|
||||
'GROUP_PARTICIPANTS_UPDATE',
|
||||
'CONNECTION_UPDATE',
|
||||
'LABELS_EDIT',
|
||||
'LABELS_ASSOCIATION',
|
||||
'CALL',
|
||||
'TYPEBOT_START',
|
||||
'TYPEBOT_CHANGE_STATUS',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['enabled'],
|
||||
...isNotEmpty('enabled'),
|
||||
};
|
@ -1,4 +1,3 @@
|
||||
import { EventController } from '@api/controllers/event.controller';
|
||||
import { WebsocketDto } from '@api/integrations/event/websocket/dto/websocket.dto';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
@ -9,6 +8,8 @@ import { NotFoundException } from '@exceptions';
|
||||
import { Server } from 'http';
|
||||
import { Server as SocketIO } from 'socket.io';
|
||||
|
||||
import { EventController } from '../../event.controller';
|
||||
|
||||
export class WebsocketController extends EventController {
|
||||
private io: SocketIO;
|
||||
private corsConfig: Array<any>;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Constructor } from '@api/dto/integration.dto';
|
||||
import { Constructor } from '@api/integrations/integration.dto';
|
||||
|
||||
export class WebsocketDto {
|
||||
enabled: boolean;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { RouterBroker } from '@api/abstract/abstract.router';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { WebsocketDto } from '@api/integrations/event/websocket/dto/websocket.dto';
|
||||
import { websocketController } from '@api/integrations/integration.module';
|
||||
import { HttpStatus } from '@api/routes/index.router';
|
||||
import { websocketController } from '@api/server.module';
|
||||
import { instanceSchema, websocketSchema } from '@validate/validate.schema';
|
||||
import { RequestHandler, Router } from 'express';
|
||||
|
||||
|
29
src/api/integrations/integration.module.ts
Normal file
29
src/api/integrations/integration.module.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { prismaRepository, waMonitor } from '@api/server.module';
|
||||
import { configService } from '@config/env.config';
|
||||
|
||||
import { DifyController } from './chatbot/dify/controllers/dify.controller';
|
||||
import { DifyService } from './chatbot/dify/services/dify.service';
|
||||
import { OpenaiController } from './chatbot/openai/controllers/openai.controller';
|
||||
import { OpenaiService } from './chatbot/openai/services/openai.service';
|
||||
import { TypebotController } from './chatbot/typebot/controllers/typebot.controller';
|
||||
import { TypebotService } from './chatbot/typebot/services/typebot.service';
|
||||
import { RabbitmqController } from './event/rabbitmq/controllers/rabbitmq.controller';
|
||||
import { SqsController } from './event/sqs/controllers/sqs.controller';
|
||||
import { WebhookController } from './event/webhook/controllers/webhook.controller';
|
||||
import { WebsocketController } from './event/websocket/controllers/websocket.controller';
|
||||
|
||||
// events
|
||||
export const websocketController = new WebsocketController(prismaRepository, waMonitor);
|
||||
export const rabbitmqController = new RabbitmqController(prismaRepository, waMonitor);
|
||||
export const sqsController = new SqsController(prismaRepository, waMonitor);
|
||||
export const webhookController = new WebhookController(prismaRepository, waMonitor);
|
||||
|
||||
// chatbots
|
||||
const typebotService = new TypebotService(waMonitor, configService, prismaRepository);
|
||||
export const typebotController = new TypebotController(typebotService);
|
||||
|
||||
const openaiService = new OpenaiService(waMonitor, configService, prismaRepository);
|
||||
export const openaiController = new OpenaiController(openaiService);
|
||||
|
||||
const difyService = new DifyService(waMonitor, configService, prismaRepository);
|
||||
export const difyController = new DifyController(difyService);
|
@ -1,23 +1,22 @@
|
||||
import { authGuard } from '@api/guards/auth.guard';
|
||||
import { instanceExistsGuard, instanceLoggedGuard } from '@api/guards/instance.guard';
|
||||
import Telemetry from '@api/guards/telemetry.guard';
|
||||
import { webhookController } from '@api/server.module';
|
||||
import { configService, WaBusiness } from '@config/env.config';
|
||||
import { ChatbotRouter } from '@api/integrations/chatbot/chatbot.router';
|
||||
import { EventRouter } from '@api/integrations/event/event.router';
|
||||
import { StorageRouter } from '@api/integrations/storage/storage.router';
|
||||
import { configService } from '@config/env.config';
|
||||
import { Router } from 'express';
|
||||
import fs from 'fs';
|
||||
import mime from 'mime';
|
||||
import path from 'path';
|
||||
|
||||
import { ChatRouter } from './chat.router';
|
||||
import { ChatbotRouter } from './chatbot.router';
|
||||
import { EventRouter } from './event.router';
|
||||
import { GroupRouter } from './group.router';
|
||||
import { InstanceRouter } from './instance.router';
|
||||
import { LabelRouter } from './label.router';
|
||||
import { ProxyRouter } from './proxy.router';
|
||||
import { MessageRouter } from './sendMessage.router';
|
||||
import { SettingsRouter } from './settings.router';
|
||||
import { StorageRouter } from './storage.router';
|
||||
import { TemplateRouter } from './template.router';
|
||||
import { ViewsRouter } from './view.router';
|
||||
|
||||
@ -85,17 +84,6 @@ router
|
||||
.use('/settings', new SettingsRouter(...guards).router)
|
||||
.use('/proxy', new ProxyRouter(...guards).router)
|
||||
.use('/label', new LabelRouter(...guards).router)
|
||||
.get('/webhook/meta', async (req, res) => {
|
||||
if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK)
|
||||
res.send(req.query['hub.challenge']);
|
||||
else res.send('Error, wrong validation token');
|
||||
})
|
||||
.post('/webhook/meta', async (req, res) => {
|
||||
const { body } = req;
|
||||
const response = await webhookController.receiveWebhook(body);
|
||||
|
||||
return res.status(200).json(response);
|
||||
})
|
||||
.use('', new EventRouter(configService, ...guards).router)
|
||||
.use('', new ChatbotRouter(...guards).router)
|
||||
.use('', new StorageRouter(...guards).router);
|
||||
|
@ -4,7 +4,6 @@ import { eventEmitter } from '@config/event.config';
|
||||
import { Logger } from '@config/logger.config';
|
||||
|
||||
import { ChatController } from './controllers/chat.controller';
|
||||
import { EventController } from './controllers/event.controller';
|
||||
import { GroupController } from './controllers/group.controller';
|
||||
import { InstanceController } from './controllers/instance.controller';
|
||||
import { LabelController } from './controllers/label.controller';
|
||||
@ -12,18 +11,10 @@ import { ProxyController } from './controllers/proxy.controller';
|
||||
import { SendMessageController } from './controllers/sendMessage.controller';
|
||||
import { SettingsController } from './controllers/settings.controller';
|
||||
import { TemplateController } from './controllers/template.controller';
|
||||
import { ChatbotController } from './integrations/chatbot/chatbot.controller';
|
||||
import { ChatwootController } from './integrations/chatbot/chatwoot/controllers/chatwoot.controller';
|
||||
import { ChatwootService } from './integrations/chatbot/chatwoot/services/chatwoot.service';
|
||||
import { DifyController } from './integrations/chatbot/dify/controllers/dify.controller';
|
||||
import { DifyService } from './integrations/chatbot/dify/services/dify.service';
|
||||
import { OpenaiController } from './integrations/chatbot/openai/controllers/openai.controller';
|
||||
import { OpenaiService } from './integrations/chatbot/openai/services/openai.service';
|
||||
import { TypebotController } from './integrations/chatbot/typebot/controllers/typebot.controller';
|
||||
import { TypebotService } from './integrations/chatbot/typebot/services/typebot.service';
|
||||
import { RabbitmqController } from './integrations/event/rabbitmq/controllers/rabbitmq.controller';
|
||||
import { SqsController } from './integrations/event/sqs/controllers/sqs.controller';
|
||||
import { WebhookController } from './integrations/event/webhook/controllers/webhook.controller';
|
||||
import { WebsocketController } from './integrations/event/websocket/controllers/websocket.controller';
|
||||
import { EventController } from './integrations/event/event.controller';
|
||||
import { S3Controller } from './integrations/storage/s3/controllers/s3.controller';
|
||||
import { S3Service } from './integrations/storage/s3/services/s3.service';
|
||||
import { ProviderFiles } from './provider/sessions';
|
||||
@ -61,15 +52,6 @@ export const waMonitor = new WAMonitoringService(
|
||||
baileysCache,
|
||||
);
|
||||
|
||||
const typebotService = new TypebotService(waMonitor, configService, prismaRepository);
|
||||
export const typebotController = new TypebotController(typebotService);
|
||||
|
||||
const openaiService = new OpenaiService(waMonitor, configService, prismaRepository);
|
||||
export const openaiController = new OpenaiController(openaiService);
|
||||
|
||||
const difyService = new DifyService(waMonitor, configService, prismaRepository);
|
||||
export const difyController = new DifyController(difyService);
|
||||
|
||||
const s3Service = new S3Service(prismaRepository);
|
||||
export const s3Controller = new S3Controller(s3Service);
|
||||
|
||||
@ -77,11 +59,7 @@ const templateService = new TemplateService(waMonitor, prismaRepository, configS
|
||||
export const templateController = new TemplateController(templateService);
|
||||
|
||||
export const eventController = new EventController(prismaRepository, waMonitor);
|
||||
|
||||
export const websocketController = new WebsocketController(prismaRepository, waMonitor);
|
||||
export const rabbitmqController = new RabbitmqController(prismaRepository, waMonitor);
|
||||
export const sqsController = new SqsController(prismaRepository, waMonitor);
|
||||
export const webhookController = new WebhookController(prismaRepository, waMonitor);
|
||||
export const chatbotController = new ChatbotController(prismaRepository, waMonitor);
|
||||
|
||||
const proxyService = new ProxyService(waMonitor);
|
||||
export const proxyController = new ProxyController(proxyService, waMonitor);
|
||||
|
@ -1,4 +0,0 @@
|
||||
export * from './webhook.schema';
|
||||
export * from './websocket.schema';
|
||||
export * from '@api/integrations/event/rabbitmq/validate/rabbitmq.schema';
|
||||
export * from '@api/integrations/event/sqs/validate/sqs.schema';
|
@ -1,7 +1,5 @@
|
||||
// Integrations Schema
|
||||
export * from './chat.schema';
|
||||
export * from './chatbot.schema';
|
||||
export * from './event.schema';
|
||||
export * from './group.schema';
|
||||
export * from './instance.schema';
|
||||
export * from './label.schema';
|
||||
@ -9,3 +7,5 @@ export * from './message.schema';
|
||||
export * from './proxy.schema';
|
||||
export * from './settings.schema';
|
||||
export * from './template.schema';
|
||||
export * from '@api/integrations/chatbot/chatbot.schema';
|
||||
export * from '@api/integrations/event/event.schema';
|
||||
|
@ -1,65 +0,0 @@
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
||||
const properties = {};
|
||||
propertyNames.forEach(
|
||||
(property) =>
|
||||
(properties[property] = {
|
||||
minLength: 1,
|
||||
description: `The "${property}" cannot be empty`,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
if: {
|
||||
propertyNames: {
|
||||
enum: [...propertyNames],
|
||||
},
|
||||
},
|
||||
then: { properties },
|
||||
};
|
||||
};
|
||||
|
||||
export const websocketSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
properties: {
|
||||
enabled: { type: 'boolean', enum: [true, false] },
|
||||
events: {
|
||||
type: 'array',
|
||||
minItems: 0,
|
||||
items: {
|
||||
type: 'string',
|
||||
enum: [
|
||||
'APPLICATION_STARTUP',
|
||||
'QRCODE_UPDATED',
|
||||
'MESSAGES_SET',
|
||||
'MESSAGES_UPSERT',
|
||||
'MESSAGES_EDITED',
|
||||
'MESSAGES_UPDATE',
|
||||
'MESSAGES_DELETE',
|
||||
'SEND_MESSAGE',
|
||||
'CONTACTS_SET',
|
||||
'CONTACTS_UPSERT',
|
||||
'CONTACTS_UPDATE',
|
||||
'PRESENCE_UPDATE',
|
||||
'CHATS_SET',
|
||||
'CHATS_UPSERT',
|
||||
'CHATS_UPDATE',
|
||||
'CHATS_DELETE',
|
||||
'GROUPS_UPSERT',
|
||||
'GROUP_UPDATE',
|
||||
'GROUP_PARTICIPANTS_UPDATE',
|
||||
'CONNECTION_UPDATE',
|
||||
'LABELS_EDIT',
|
||||
'LABELS_ASSOCIATION',
|
||||
'CALL',
|
||||
'TYPEBOT_START',
|
||||
'TYPEBOT_CHANGE_STATUS',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['enabled'],
|
||||
...isNotEmpty('enabled'),
|
||||
};
|
Loading…
Reference in New Issue
Block a user