mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-20 04:12:23 -06:00
refactor: integrations router folder structure
This commit is contained in:
18
src/api/routes/chatbot.router.ts
Normal file
18
src/api/routes/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);
|
||||
}
|
||||
}
|
||||
19
src/api/routes/event.router.ts
Normal file
19
src/api/routes/event.router.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { RabbitmqRouter } from '@api/integrations/event/rabbitmq/routes/rabbitmq.router';
|
||||
import { SqsRouter } from '@api/integrations/event/sqs/routes/sqs.router';
|
||||
import { WebsocketRouter } from '@api/integrations/event/websocket/routes/websocket.router';
|
||||
import { Router } from 'express';
|
||||
|
||||
import { WebhookRouter } from './webhook.router';
|
||||
|
||||
export class EventRouter {
|
||||
public readonly router: Router;
|
||||
|
||||
constructor(configService: any, ...guards: any[]) {
|
||||
this.router = Router();
|
||||
|
||||
this.router.use('/webhook', new WebhookRouter(configService, ...guards).router);
|
||||
this.router.use('/websocket', new WebsocketRouter(...guards).router);
|
||||
this.router.use('/rabbitmq', new RabbitmqRouter(...guards).router);
|
||||
this.router.use('/sqs', new SqsRouter(...guards).router);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
import { authGuard } from '@api/guards/auth.guard';
|
||||
import { instanceExistsGuard, instanceLoggedGuard } from '@api/guards/instance.guard';
|
||||
import Telemetry from '@api/guards/telemetry.guard';
|
||||
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 { RabbitmqRouter } from '@api/integrations/event/rabbitmq/routes/rabbitmq.router';
|
||||
import { SqsRouter } from '@api/integrations/event/sqs/routes/sqs.router';
|
||||
import { WebsocketRouter } from '@api/integrations/event/websocket/routes/websocket.router';
|
||||
import { S3Router } from '@api/integrations/storage/s3/routes/s3.router';
|
||||
import { webhookController } from '@api/server.module';
|
||||
import { configService, WaBusiness } from '@config/env.config';
|
||||
import { Router } from 'express';
|
||||
@@ -17,15 +9,17 @@ 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';
|
||||
import { WebhookRouter } from './webhook.router';
|
||||
|
||||
enum HttpStatus {
|
||||
OK = 200,
|
||||
@@ -87,19 +81,10 @@ router
|
||||
.use('/message', new MessageRouter(...guards).router)
|
||||
.use('/chat', new ChatRouter(...guards).router)
|
||||
.use('/group', new GroupRouter(...guards).router)
|
||||
.use('/webhook', new WebhookRouter(configService, ...guards).router)
|
||||
.use('/template', new TemplateRouter(configService, ...guards).router)
|
||||
.use('/chatwoot', new ChatwootRouter(...guards).router)
|
||||
.use('/settings', new SettingsRouter(...guards).router)
|
||||
.use('/websocket', new WebsocketRouter(...guards).router)
|
||||
.use('/rabbitmq', new RabbitmqRouter(...guards).router)
|
||||
.use('/sqs', new SqsRouter(...guards).router)
|
||||
.use('/typebot', new TypebotRouter(...guards).router)
|
||||
.use('/proxy', new ProxyRouter(...guards).router)
|
||||
.use('/label', new LabelRouter(...guards).router)
|
||||
.use('/s3', new S3Router(...guards).router)
|
||||
.use('/openai', new OpenaiRouter(...guards).router)
|
||||
.use('/dify', new DifyRouter(...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']);
|
||||
@@ -110,6 +95,9 @@ router
|
||||
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);
|
||||
|
||||
export { HttpStatus, router };
|
||||
|
||||
12
src/api/routes/storage.router.ts
Normal file
12
src/api/routes/storage.router.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { S3Router } from '@api/integrations/storage/s3/routes/s3.router';
|
||||
import { Router } from 'express';
|
||||
|
||||
export class StorageRouter {
|
||||
public readonly router: Router;
|
||||
|
||||
constructor(...guards: any[]) {
|
||||
this.router = Router();
|
||||
|
||||
this.router.use('/s3', new S3Router(...guards).router);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user