diff --git a/CHANGELOG.md b/CHANGELOG.md index c1daeb6c..38dd0066 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed * Removed excessive verbose logs +* Optimization in instance registration ### Break changes * jwt authentication removed diff --git a/src/api/controllers/instance.controller.ts b/src/api/controllers/instance.controller.ts index 03614e88..4954248c 100644 --- a/src/api/controllers/instance.controller.ts +++ b/src/api/controllers/instance.controller.ts @@ -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, diff --git a/src/api/dto/instance.dto.ts b/src/api/dto/instance.dto.ts index f7b54679..3fbcb9d0 100644 --- a/src/api/dto/instance.dto.ts +++ b/src/api/dto/instance.dto.ts @@ -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 { diff --git a/src/api/dto/proxy.dto.ts b/src/api/dto/proxy.dto.ts index 18432d34..2e5b2f4d 100644 --- a/src/api/dto/proxy.dto.ts +++ b/src/api/dto/proxy.dto.ts @@ -1,5 +1,5 @@ export class ProxyDto { - enabled: boolean; + enabled?: boolean; host: string; port: string; protocol: string; diff --git a/src/api/integrations/chatwoot/routes/chatwoot.router.ts b/src/api/integrations/chatwoot/routes/chatwoot.router.ts index 24799a06..20dc3183 100644 --- a/src/api/integrations/chatwoot/routes/chatwoot.router.ts +++ b/src/api/integrations/chatwoot/routes/chatwoot.router.ts @@ -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({ 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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance, data) => chatwootController.receiveWebhook(instance, data), }); diff --git a/src/api/integrations/rabbitmq/routes/rabbitmq.router.ts b/src/api/integrations/rabbitmq/routes/rabbitmq.router.ts index 4c822184..d1a0a891 100644 --- a/src/api/integrations/rabbitmq/routes/rabbitmq.router.ts +++ b/src/api/integrations/rabbitmq/routes/rabbitmq.router.ts @@ -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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => rabbitmqController.findRabbitmq(instance), }); diff --git a/src/api/integrations/sqs/routes/sqs.router.ts b/src/api/integrations/sqs/routes/sqs.router.ts index 552d8e69..3d740770 100644 --- a/src/api/integrations/sqs/routes/sqs.router.ts +++ b/src/api/integrations/sqs/routes/sqs.router.ts @@ -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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => sqsController.findSqs(instance), }); diff --git a/src/api/integrations/typebot/routes/typebot.router.ts b/src/api/integrations/typebot/routes/typebot.router.ts index 413f91b2..9e4400d2 100644 --- a/src/api/integrations/typebot/routes/typebot.router.ts +++ b/src/api/integrations/typebot/routes/typebot.router.ts @@ -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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => typebotController.findTypebot(instance), }); diff --git a/src/api/integrations/websocket/routes/websocket.router.ts b/src/api/integrations/websocket/routes/websocket.router.ts index a99466b2..b8f86fcb 100644 --- a/src/api/integrations/websocket/routes/websocket.router.ts +++ b/src/api/integrations/websocket/routes/websocket.router.ts @@ -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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => websocketController.findWebsocket(instance), }); diff --git a/src/api/routes/instance.router.ts b/src/api/routes/instance.router.ts index bae8832d..ca74f807 100644 --- a/src/api/routes/instance.router.ts +++ b/src/api/routes/instance.router.ts @@ -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({ 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({ 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({ 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({ 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({ 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({ request: req, - schema: instanceNameSchema, + schema: null, ClassRef: InstanceDto, execute: (instance) => instanceController.deleteInstance(instance), }); diff --git a/src/api/routes/proxy.router.ts b/src/api/routes/proxy.router.ts index e568efbe..5ffde824 100644 --- a/src/api/routes/proxy.router.ts +++ b/src/api/routes/proxy.router.ts @@ -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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => proxyController.findProxy(instance), }); diff --git a/src/api/routes/settings.router.ts b/src/api/routes/settings.router.ts index b04ef04b..211fdc05 100644 --- a/src/api/routes/settings.router.ts +++ b/src/api/routes/settings.router.ts @@ -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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance) => settingsController.findSettings(instance), }); diff --git a/src/api/routes/webhook.router.ts b/src/api/routes/webhook.router.ts index 57c92330..db930620 100644 --- a/src/api/routes/webhook.router.ts +++ b/src/api/routes/webhook.router.ts @@ -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({ 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({ request: req, - schema: instanceNameSchema, + schema: instanceSchema, ClassRef: InstanceDto, execute: (instance, data) => webhookController.receiveWebhook(instance, data), }); diff --git a/src/api/server.module.ts b/src/api/server.module.ts index cb117883..153e89d9 100644 --- a/src/api/server.module.ts +++ b/src/api/server.module.ts @@ -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); diff --git a/src/api/services/auth.service.ts b/src/api/services/auth.service.ts index f2bce1f7..19040899 100644 --- a/src/api/services/auth.service.ts +++ b/src/api/services/auth.service.ts @@ -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; - } } diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index dd598034..e138cd1f 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -369,6 +369,15 @@ export class BaileysStartupService extends ChannelStartupService { status: 'closed', }); + if (this.configService.get('DATABASE').ENABLED) { + await this.prismaRepository.instance.update({ + where: { id: this.instanceId }, + data: { + connectionStatus: 'close', + }, + }); + } + if (this.configService.get('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').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').ENABLED && this.localChatwoot.enabled) { this.chatwootService.eventWhatsapp( Events.CONNECTION_UPDATE, diff --git a/src/validate/validate.schema.ts b/src/validate/validate.schema.ts index 40f8a7f4..b7021ba0 100644 --- a/src/validate/validate.schema.ts +++ b/src/validate/validate.schema.ts @@ -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',