mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
chore: Simplified payloads and instance endpoint
This commit is contained in:
parent
eed32a3bd9
commit
a578384e85
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* Removed excessive verbose logs
|
* Removed excessive verbose logs
|
||||||
|
* Optimization in instance registration
|
||||||
|
|
||||||
### Break changes
|
### Break changes
|
||||||
* jwt authentication removed
|
* jwt authentication removed
|
||||||
|
@ -50,14 +50,32 @@ export class InstanceController {
|
|||||||
|
|
||||||
public async createInstance({
|
public async createInstance({
|
||||||
instanceName,
|
instanceName,
|
||||||
webhook,
|
|
||||||
webhookByEvents,
|
|
||||||
webhookBase64,
|
|
||||||
webhookEvents,
|
|
||||||
qrcode,
|
qrcode,
|
||||||
number,
|
number,
|
||||||
integration,
|
integration,
|
||||||
token,
|
token,
|
||||||
|
rejectCall,
|
||||||
|
msgCall,
|
||||||
|
groupsIgnore,
|
||||||
|
alwaysOnline,
|
||||||
|
readMessages,
|
||||||
|
readStatus,
|
||||||
|
syncFullHistory,
|
||||||
|
proxyHost,
|
||||||
|
proxyPort,
|
||||||
|
proxyProtocol,
|
||||||
|
proxyUsername,
|
||||||
|
proxyPassword,
|
||||||
|
webhookUrl,
|
||||||
|
webhookByEvents,
|
||||||
|
webhookBase64,
|
||||||
|
webhookEvents,
|
||||||
|
websocketEnabled,
|
||||||
|
websocketEvents,
|
||||||
|
rabbitmqEnabled,
|
||||||
|
rabbitmqEvents,
|
||||||
|
sqsEnabled,
|
||||||
|
sqsEvents,
|
||||||
chatwootAccountId,
|
chatwootAccountId,
|
||||||
chatwootToken,
|
chatwootToken,
|
||||||
chatwootUrl,
|
chatwootUrl,
|
||||||
@ -69,19 +87,6 @@ export class InstanceController {
|
|||||||
chatwootMergeBrazilContacts,
|
chatwootMergeBrazilContacts,
|
||||||
chatwootImportMessages,
|
chatwootImportMessages,
|
||||||
chatwootDaysLimitImportMessages,
|
chatwootDaysLimitImportMessages,
|
||||||
rejectCall,
|
|
||||||
msgCall,
|
|
||||||
groupsIgnore,
|
|
||||||
alwaysOnline,
|
|
||||||
readMessages,
|
|
||||||
readStatus,
|
|
||||||
syncFullHistory,
|
|
||||||
websocketEnabled,
|
|
||||||
websocketEvents,
|
|
||||||
rabbitmqEnabled,
|
|
||||||
rabbitmqEvents,
|
|
||||||
sqsEnabled,
|
|
||||||
sqsEvents,
|
|
||||||
typebotUrl,
|
typebotUrl,
|
||||||
typebot,
|
typebot,
|
||||||
typebotExpire,
|
typebotExpire,
|
||||||
@ -89,7 +94,6 @@ export class InstanceController {
|
|||||||
typebotDelayMessage,
|
typebotDelayMessage,
|
||||||
typebotUnknownMessage,
|
typebotUnknownMessage,
|
||||||
typebotListeningFromMe,
|
typebotListeningFromMe,
|
||||||
proxy,
|
|
||||||
}: InstanceDto) {
|
}: InstanceDto) {
|
||||||
try {
|
try {
|
||||||
await this.authService.checkDuplicateToken(token);
|
await this.authService.checkDuplicateToken(token);
|
||||||
@ -123,7 +127,10 @@ export class InstanceController {
|
|||||||
|
|
||||||
const instanceId = v4();
|
const instanceId = v4();
|
||||||
|
|
||||||
const hash = await this.authService.generateHash(token);
|
let hash: string;
|
||||||
|
|
||||||
|
if (!token) hash = v4().toUpperCase();
|
||||||
|
else hash = token;
|
||||||
|
|
||||||
await this.waMonitor.saveInstance({ instanceId, integration, instanceName, hash, number });
|
await this.waMonitor.saveInstance({ instanceId, integration, instanceName, hash, number });
|
||||||
|
|
||||||
@ -145,8 +152,8 @@ export class InstanceController {
|
|||||||
|
|
||||||
let getWebhookEvents: string[];
|
let getWebhookEvents: string[];
|
||||||
|
|
||||||
if (webhook) {
|
if (webhookUrl) {
|
||||||
if (!isURL(webhook, { require_tld: false })) {
|
if (!isURL(webhookUrl, { require_tld: false })) {
|
||||||
throw new BadRequestException('Invalid "url" property in webhook');
|
throw new BadRequestException('Invalid "url" property in webhook');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +191,7 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
this.webhookService.create(instance, {
|
this.webhookService.create(instance, {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
url: webhook,
|
url: webhookUrl,
|
||||||
events: newEvents,
|
events: newEvents,
|
||||||
webhookByEvents,
|
webhookByEvents,
|
||||||
webhookBase64,
|
webhookBase64,
|
||||||
@ -348,19 +355,25 @@ export class InstanceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy) {
|
if (proxyHost && proxyPort && proxyProtocol) {
|
||||||
const testProxy = await this.proxyService.testProxy(proxy);
|
const testProxy = await this.proxyService.testProxy({
|
||||||
|
host: proxyHost,
|
||||||
|
port: proxyPort,
|
||||||
|
protocol: proxyProtocol,
|
||||||
|
username: proxyUsername,
|
||||||
|
password: proxyPassword,
|
||||||
|
});
|
||||||
if (!testProxy) {
|
if (!testProxy) {
|
||||||
throw new BadRequestException('Invalid proxy');
|
throw new BadRequestException('Invalid proxy');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.proxyService.createProxy(instance, {
|
await this.proxyService.createProxy(instance, {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
host: proxy.host,
|
host: proxyHost,
|
||||||
port: proxy.port,
|
port: proxyPort,
|
||||||
protocol: proxy.protocol,
|
protocol: proxyProtocol,
|
||||||
username: proxy.username,
|
username: proxyUsername,
|
||||||
password: proxy.password,
|
password: proxyPassword,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +442,7 @@ export class InstanceController {
|
|||||||
},
|
},
|
||||||
hash,
|
hash,
|
||||||
webhook: {
|
webhook: {
|
||||||
webhook,
|
webhookUrl,
|
||||||
webhookByEvents,
|
webhookByEvents,
|
||||||
webhookBase64,
|
webhookBase64,
|
||||||
events: getWebhookEvents,
|
events: getWebhookEvents,
|
||||||
@ -528,7 +541,7 @@ export class InstanceController {
|
|||||||
},
|
},
|
||||||
hash,
|
hash,
|
||||||
webhook: {
|
webhook: {
|
||||||
webhook,
|
webhookUrl,
|
||||||
webhookByEvents,
|
webhookByEvents,
|
||||||
webhookBase64,
|
webhookBase64,
|
||||||
events: getWebhookEvents,
|
events: getWebhookEvents,
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { WAPresence } from '@whiskeysockets/baileys';
|
import { WAPresence } from '@whiskeysockets/baileys';
|
||||||
|
|
||||||
import { ProxyDto } from './proxy.dto';
|
|
||||||
|
|
||||||
export class InstanceDto {
|
export class InstanceDto {
|
||||||
instanceName: string;
|
instanceName: string;
|
||||||
instanceId?: string;
|
instanceId?: string;
|
||||||
@ -9,7 +7,7 @@ export class InstanceDto {
|
|||||||
number?: string;
|
number?: string;
|
||||||
integration?: string;
|
integration?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
webhook?: string;
|
webhookUrl?: string;
|
||||||
webhookByEvents?: boolean;
|
webhookByEvents?: boolean;
|
||||||
webhookBase64?: boolean;
|
webhookBase64?: boolean;
|
||||||
webhookEvents?: string[];
|
webhookEvents?: string[];
|
||||||
@ -44,7 +42,11 @@ export class InstanceDto {
|
|||||||
typebotDelayMessage?: number;
|
typebotDelayMessage?: number;
|
||||||
typebotUnknownMessage?: string;
|
typebotUnknownMessage?: string;
|
||||||
typebotListeningFromMe?: boolean;
|
typebotListeningFromMe?: boolean;
|
||||||
proxy?: ProxyDto;
|
proxyHost?: string;
|
||||||
|
proxyPort?: string;
|
||||||
|
proxyProtocol?: string;
|
||||||
|
proxyUsername?: string;
|
||||||
|
proxyPassword?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetPresenceDto {
|
export class SetPresenceDto {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export class ProxyDto {
|
export class ProxyDto {
|
||||||
enabled: boolean;
|
enabled?: boolean;
|
||||||
host: string;
|
host: string;
|
||||||
port: string;
|
port: string;
|
||||||
protocol: string;
|
protocol: string;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { chatwootSchema, instanceNameSchema } from '../../../../validate/validate.schema';
|
import { chatwootSchema, instanceSchema } from '../../../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../../../abstract/abstract.router';
|
import { RouterBroker } from '../../../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { HttpStatus } from '../../../routes/index.router';
|
import { HttpStatus } from '../../../routes/index.router';
|
||||||
@ -24,7 +24,7 @@ export class ChatwootRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => chatwootController.findChatwoot(instance),
|
execute: (instance) => chatwootController.findChatwoot(instance),
|
||||||
});
|
});
|
||||||
@ -34,7 +34,7 @@ export class ChatwootRouter extends RouterBroker {
|
|||||||
.post(this.routerPath('webhook'), async (req, res) => {
|
.post(this.routerPath('webhook'), async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance, data) => chatwootController.receiveWebhook(instance, data),
|
execute: (instance, data) => chatwootController.receiveWebhook(instance, data),
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { instanceNameSchema, rabbitmqSchema } from '../../../../validate/validate.schema';
|
import { instanceSchema, rabbitmqSchema } from '../../../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../../../abstract/abstract.router';
|
import { RouterBroker } from '../../../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { HttpStatus } from '../../../routes/index.router';
|
import { HttpStatus } from '../../../routes/index.router';
|
||||||
@ -24,7 +24,7 @@ export class RabbitmqRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => rabbitmqController.findRabbitmq(instance),
|
execute: (instance) => rabbitmqController.findRabbitmq(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { instanceNameSchema, sqsSchema } from '../../../../validate/validate.schema';
|
import { instanceSchema, sqsSchema } from '../../../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../../../abstract/abstract.router';
|
import { RouterBroker } from '../../../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { HttpStatus } from '../../../routes/index.router';
|
import { HttpStatus } from '../../../routes/index.router';
|
||||||
@ -24,7 +24,7 @@ export class SqsRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => sqsController.findSqs(instance),
|
execute: (instance) => sqsController.findSqs(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
instanceNameSchema,
|
instanceSchema,
|
||||||
typebotSchema,
|
typebotSchema,
|
||||||
typebotStartSchema,
|
typebotStartSchema,
|
||||||
typebotStatusSchema,
|
typebotStatusSchema,
|
||||||
@ -29,7 +29,7 @@ export class TypebotRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => typebotController.findTypebot(instance),
|
execute: (instance) => typebotController.findTypebot(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { instanceNameSchema, websocketSchema } from '../../../../validate/validate.schema';
|
import { instanceSchema, websocketSchema } from '../../../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../../../abstract/abstract.router';
|
import { RouterBroker } from '../../../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../../../dto/instance.dto';
|
import { InstanceDto } from '../../../dto/instance.dto';
|
||||||
import { HttpStatus } from '../../../routes/index.router';
|
import { HttpStatus } from '../../../routes/index.router';
|
||||||
@ -24,7 +24,7 @@ export class WebsocketRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => websocketController.findWebsocket(instance),
|
execute: (instance) => websocketController.findWebsocket(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { ConfigService } from '../../config/env.config';
|
import { ConfigService } from '../../config/env.config';
|
||||||
import { instanceNameSchema, presenceOnlySchema } from '../../validate/validate.schema';
|
import { instanceSchema, presenceOnlySchema } from '../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
|
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
|
||||||
import { instanceController } from '../server.module';
|
import { instanceController } from '../server.module';
|
||||||
@ -14,7 +14,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
.post('/create', ...guards, async (req, res) => {
|
.post('/create', ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.createInstance(instance),
|
execute: (instance) => instanceController.createInstance(instance),
|
||||||
});
|
});
|
||||||
@ -24,7 +24,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
.put(this.routerPath('restart'), ...guards, async (req, res) => {
|
.put(this.routerPath('restart'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: null,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.restartInstance(instance),
|
execute: (instance) => instanceController.restartInstance(instance),
|
||||||
});
|
});
|
||||||
@ -34,7 +34,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('connect'), ...guards, async (req, res) => {
|
.get(this.routerPath('connect'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: null,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.connectToWhatsapp(instance),
|
execute: (instance) => instanceController.connectToWhatsapp(instance),
|
||||||
});
|
});
|
||||||
@ -44,7 +44,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('connectionState'), ...guards, async (req, res) => {
|
.get(this.routerPath('connectionState'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: null,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.connectionState(instance),
|
execute: (instance) => instanceController.connectionState(instance),
|
||||||
});
|
});
|
||||||
@ -76,7 +76,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
.delete(this.routerPath('logout'), ...guards, async (req, res) => {
|
.delete(this.routerPath('logout'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: null,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.logout(instance),
|
execute: (instance) => instanceController.logout(instance),
|
||||||
});
|
});
|
||||||
@ -86,7 +86,7 @@ export class InstanceRouter extends RouterBroker {
|
|||||||
.delete(this.routerPath('delete'), ...guards, async (req, res) => {
|
.delete(this.routerPath('delete'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: null,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => instanceController.deleteInstance(instance),
|
execute: (instance) => instanceController.deleteInstance(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { instanceNameSchema, proxySchema } from '../../validate/validate.schema';
|
import { instanceSchema, proxySchema } from '../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { ProxyDto } from '../dto/proxy.dto';
|
import { ProxyDto } from '../dto/proxy.dto';
|
||||||
@ -24,7 +24,7 @@ export class ProxyRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => proxyController.findProxy(instance),
|
execute: (instance) => proxyController.findProxy(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { instanceNameSchema, settingsSchema } from '../../validate/validate.schema';
|
import { instanceSchema, settingsSchema } from '../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { SettingsDto } from '../dto/settings.dto';
|
import { SettingsDto } from '../dto/settings.dto';
|
||||||
@ -24,7 +24,7 @@ export class SettingsRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => settingsController.findSettings(instance),
|
execute: (instance) => settingsController.findSettings(instance),
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler, Router } from 'express';
|
import { RequestHandler, Router } from 'express';
|
||||||
|
|
||||||
import { ConfigService, WaBusiness } from '../../config/env.config';
|
import { ConfigService, WaBusiness } from '../../config/env.config';
|
||||||
import { instanceNameSchema, webhookSchema } from '../../validate/validate.schema';
|
import { instanceSchema, webhookSchema } from '../../validate/validate.schema';
|
||||||
import { RouterBroker } from '../abstract/abstract.router';
|
import { RouterBroker } from '../abstract/abstract.router';
|
||||||
import { InstanceDto } from '../dto/instance.dto';
|
import { InstanceDto } from '../dto/instance.dto';
|
||||||
import { WebhookDto } from '../dto/webhook.dto';
|
import { WebhookDto } from '../dto/webhook.dto';
|
||||||
@ -25,7 +25,7 @@ export class WebhookRouter extends RouterBroker {
|
|||||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance) => webhookController.findWebhook(instance),
|
execute: (instance) => webhookController.findWebhook(instance),
|
||||||
});
|
});
|
||||||
@ -35,7 +35,7 @@ export class WebhookRouter extends RouterBroker {
|
|||||||
.post(this.routerPath('whatsapp'), async (req, res) => {
|
.post(this.routerPath('whatsapp'), async (req, res) => {
|
||||||
const response = await this.dataValidate<InstanceDto>({
|
const response = await this.dataValidate<InstanceDto>({
|
||||||
request: req,
|
request: req,
|
||||||
schema: instanceNameSchema,
|
schema: instanceSchema,
|
||||||
ClassRef: InstanceDto,
|
ClassRef: InstanceDto,
|
||||||
execute: (instance, data) => webhookController.receiveWebhook(instance, data),
|
execute: (instance, data) => webhookController.receiveWebhook(instance, data),
|
||||||
});
|
});
|
||||||
|
@ -52,7 +52,7 @@ export const waMonitor = new WAMonitoringService(
|
|||||||
baileysCache,
|
baileysCache,
|
||||||
);
|
);
|
||||||
|
|
||||||
const authService = new AuthService(waMonitor, configService, prismaRepository);
|
const authService = new AuthService(prismaRepository);
|
||||||
|
|
||||||
const typebotService = new TypebotService(waMonitor, configService, eventEmitter);
|
const typebotService = new TypebotService(waMonitor, configService, eventEmitter);
|
||||||
export const typebotController = new TypebotController(typebotService);
|
export const typebotController = new TypebotController(typebotService);
|
||||||
|
@ -1,40 +1,18 @@
|
|||||||
import { v4 } from 'uuid';
|
|
||||||
|
|
||||||
import { ConfigService } from '../../config/env.config';
|
|
||||||
import { Logger } from '../../config/logger.config';
|
|
||||||
import { BadRequestException } from '../../exceptions';
|
import { BadRequestException } from '../../exceptions';
|
||||||
import { PrismaRepository } from '../repository/repository.service';
|
import { PrismaRepository } from '../repository/repository.service';
|
||||||
import { WAMonitoringService } from './monitor.service';
|
|
||||||
|
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
constructor(
|
constructor(private readonly prismaRepository: PrismaRepository) {}
|
||||||
private readonly waMonitor: WAMonitoringService,
|
|
||||||
private readonly configService: ConfigService,
|
|
||||||
private readonly prismaRepository: PrismaRepository,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
private readonly logger = new Logger(AuthService.name);
|
|
||||||
|
|
||||||
private async apikey(token?: string) {
|
|
||||||
const apikey = token ? token : v4().toUpperCase();
|
|
||||||
|
|
||||||
return apikey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async checkDuplicateToken(token: string) {
|
public async checkDuplicateToken(token: string) {
|
||||||
const instances = await this.waMonitor.instanceInfo();
|
const instances = await this.prismaRepository.instance.findMany({
|
||||||
|
where: { token },
|
||||||
|
});
|
||||||
|
|
||||||
const instance = instances.find((instance) => instance.instance.token === token);
|
if (instances.length > 0) {
|
||||||
|
|
||||||
if (instance) {
|
|
||||||
throw new BadRequestException('Token already exists');
|
throw new BadRequestException('Token already exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async generateHash(token?: string) {
|
|
||||||
const hash = await this.apikey(token);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -369,6 +369,15 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
status: 'closed',
|
status: 'closed',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.configService.get<Database>('DATABASE').ENABLED) {
|
||||||
|
await this.prismaRepository.instance.update({
|
||||||
|
where: { id: this.instanceId },
|
||||||
|
data: {
|
||||||
|
connectionStatus: 'close',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.STATUS_INSTANCE,
|
Events.STATUS_INSTANCE,
|
||||||
@ -404,6 +413,17 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
`,
|
`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.configService.get<Database>('DATABASE').ENABLED) {
|
||||||
|
await this.prismaRepository.instance.update({
|
||||||
|
where: { id: this.instanceId },
|
||||||
|
data: {
|
||||||
|
ownerJid: this.instance.wuid,
|
||||||
|
profilePicUrl: this.instance.profilePictureUrl,
|
||||||
|
connectionStatus: 'open',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||||
this.chatwootService.eventWhatsapp(
|
this.chatwootService.eventWhatsapp(
|
||||||
Events.CONNECTION_UPDATE,
|
Events.CONNECTION_UPDATE,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
|
import { Integration } from '../api/types/wa.types';
|
||||||
|
|
||||||
// Integrations Schema
|
// Integrations Schema
|
||||||
export * from '../api/integrations/chatwoot/validate/chatwoot.schema';
|
export * from '../api/integrations/chatwoot/validate/chatwoot.schema';
|
||||||
export * from '../api/integrations/rabbitmq/validate/rabbitmq.schema';
|
export * from '../api/integrations/rabbitmq/validate/rabbitmq.schema';
|
||||||
@ -26,62 +28,127 @@ const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Events = [
|
||||||
|
'APPLICATION_STARTUP',
|
||||||
|
'QRCODE_UPDATED',
|
||||||
|
'MESSAGES_SET',
|
||||||
|
'MESSAGES_UPSERT',
|
||||||
|
'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',
|
||||||
|
];
|
||||||
|
|
||||||
// Instance Schema
|
// Instance Schema
|
||||||
export const instanceNameSchema: JSONSchema7 = {
|
export const instanceSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
// Instance
|
||||||
instanceName: { type: 'string' },
|
instanceName: { type: 'string' },
|
||||||
webhook: { type: 'string' },
|
token: { type: 'string' },
|
||||||
webhook_by_events: { type: 'boolean' },
|
number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },
|
||||||
events: {
|
qrcode: { type: 'boolean' },
|
||||||
|
Integration: {
|
||||||
|
type: 'string',
|
||||||
|
enum: Object.values(Integration),
|
||||||
|
},
|
||||||
|
// Settings
|
||||||
|
rejectCall: { type: 'boolean' },
|
||||||
|
msgCall: { type: 'string' },
|
||||||
|
groupsIgnore: { type: 'boolean' },
|
||||||
|
alwaysOnline: { type: 'boolean' },
|
||||||
|
readMessages: { type: 'boolean' },
|
||||||
|
readStatus: { type: 'boolean' },
|
||||||
|
syncFullHistory: { type: 'boolean' },
|
||||||
|
// Proxy
|
||||||
|
proxyHost: { type: 'string' },
|
||||||
|
proxyPort: { type: 'string' },
|
||||||
|
proxyProtocol: { type: 'string' },
|
||||||
|
proxyUsername: { type: 'string' },
|
||||||
|
proxyPassword: { type: 'string' },
|
||||||
|
// Webhook
|
||||||
|
webhookUrl: { type: 'string' },
|
||||||
|
webhookByEvents: { type: 'boolean' },
|
||||||
|
webhookBase64: { type: 'boolean' },
|
||||||
|
webhookEvents: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
minItems: 0,
|
minItems: 0,
|
||||||
items: {
|
items: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: [
|
enum: Events,
|
||||||
'APPLICATION_STARTUP',
|
|
||||||
'QRCODE_UPDATED',
|
|
||||||
'MESSAGES_SET',
|
|
||||||
'MESSAGES_UPSERT',
|
|
||||||
'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',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
qrcode: { type: 'boolean', enum: [true, false] },
|
// RabbitMQ
|
||||||
number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },
|
rabbitmqEnabled: { type: 'boolean' },
|
||||||
token: { type: 'string' },
|
rabbitmqEvents: {
|
||||||
|
type: 'array',
|
||||||
|
minItems: 0,
|
||||||
|
items: {
|
||||||
|
type: 'string',
|
||||||
|
enum: Events,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// SQS
|
||||||
|
sqsEnabled: { type: 'boolean' },
|
||||||
|
sqsEvents: {
|
||||||
|
type: 'array',
|
||||||
|
minItems: 0,
|
||||||
|
items: {
|
||||||
|
type: 'string',
|
||||||
|
enum: Events,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Chatwoot
|
||||||
|
chatwootAccountId: { type: 'string' },
|
||||||
|
chatwootToken: { type: 'string' },
|
||||||
|
chatwootUrl: { type: 'string' },
|
||||||
|
chatwootSignMsg: { type: 'boolean' },
|
||||||
|
chatwootReopenConversation: { type: 'boolean' },
|
||||||
|
chatwootConversationPending: { type: 'boolean' },
|
||||||
|
chatwootImportContacts: { type: 'boolean' },
|
||||||
|
chatwootNameInbox: { type: 'string' },
|
||||||
|
chatwootMergeBrazilContacts: { type: 'boolean' },
|
||||||
|
chatwootImportMessages: { type: 'boolean' },
|
||||||
|
chatwootDaysLimitImportMessages: { type: 'number' },
|
||||||
|
// Typebot
|
||||||
|
typebotUrl: { type: 'string' },
|
||||||
|
typebot: { type: 'boolean' },
|
||||||
|
typebotExpire: { type: 'number' },
|
||||||
|
typebotKeywordFinish: { type: 'string' },
|
||||||
|
typebotDelayMessage: { type: 'number' },
|
||||||
|
typebotUnknownMessage: { type: 'string' },
|
||||||
|
typebotListeningFromMe: { type: 'boolean' },
|
||||||
},
|
},
|
||||||
...isNotEmpty('instanceName'),
|
...isNotEmpty('instanceName'),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const oldTokenSchema: JSONSchema7 = {
|
export const presenceOnlySchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
oldToken: { type: 'string' },
|
presence: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['unavailable', 'available', 'composing', 'recording', 'paused'],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
required: ['oldToken'],
|
required: ['presence'],
|
||||||
...isNotEmpty('oldToken'),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const quotedOptionsSchema: JSONSchema7 = {
|
const quotedOptionsSchema: JSONSchema7 = {
|
||||||
@ -165,18 +232,6 @@ export const presenceSchema: JSONSchema7 = {
|
|||||||
required: ['options', 'number'],
|
required: ['options', 'number'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const presenceOnlySchema: JSONSchema7 = {
|
|
||||||
$id: v4(),
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
presence: {
|
|
||||||
type: 'string',
|
|
||||||
enum: ['unavailable', 'available', 'composing', 'recording', 'paused'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
required: ['presence'],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const pollMessageSchema: JSONSchema7 = {
|
export const pollMessageSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
Loading…
Reference in New Issue
Block a user