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