oex2003/evolution-api
0
1import { Integration } from '@api/types/wa.types';2import { JSONSchema7 } from 'json-schema';3import { v4 } from 'uuid';4 5const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {6 const properties = {};7 propertyNames.forEach(8 (property) =>9 (properties[property] = {10 minLength: 1,11 description: `The "${property}" cannot be empty`,12 }),13 );14 return {15 if: {16 propertyNames: {17 enum: [...propertyNames],18 },19 },20 then: { properties },21 };22};23 24export const instanceSchema: JSONSchema7 = {25 $id: v4(),26 type: 'object',27 properties: {28 // Instance29 instanceName: { type: 'string' },30 token: { type: 'string' },31 number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },32 businessId: { type: 'string' },33 qrcode: { type: 'boolean' },34 Integration: {35 type: 'string',36 enum: Object.values(Integration),37 },38 // Settings39 rejectCall: { type: 'boolean' },40 msgCall: { type: 'string' },41 groupsIgnore: { type: 'boolean' },42 alwaysOnline: { type: 'boolean' },43 readMessages: { type: 'boolean' },44 readStatus: { type: 'boolean' },45 syncFullHistory: { type: 'boolean' },46 wavoipToken: { type: 'string' },47 // Proxy48 proxyHost: { type: 'string' },49 proxyPort: { type: 'string' },50 proxyProtocol: { type: 'string' },51 proxyUsername: { type: 'string' },52 proxyPassword: { type: 'string' },53 // Webhook54 webhookUrl: { type: 'string' },55 webhookByEvents: { type: 'boolean' },56 webhookBase64: { type: 'boolean' },57 webhookEvents: {58 type: 'array',59 minItems: 0,60 items: {61 type: 'string',62 enum: [63 'APPLICATION_STARTUP',64 'QRCODE_UPDATED',65 'MESSAGES_SET',66 'MESSAGES_UPSERT',67 'MESSAGES_EDITED',68 'MESSAGES_UPDATE',69 'MESSAGES_DELETE',70 'SEND_MESSAGE',71 'SEND_MESSAGE_UPDATE',72 'CONTACTS_SET',73 'CONTACTS_UPSERT',74 'CONTACTS_UPDATE',75 'PRESENCE_UPDATE',76 'CHATS_SET',77 'CHATS_UPSERT',78 'CHATS_UPDATE',79 'CHATS_DELETE',80 'GROUPS_UPSERT',81 'GROUP_UPDATE',82 'GROUP_PARTICIPANTS_UPDATE',83 'CONNECTION_UPDATE',84 'LABELS_EDIT',85 'LABELS_ASSOCIATION',86 'CALL',87 'TYPEBOT_START',88 'TYPEBOT_CHANGE_STATUS',89 ],90 },91 },92 // RabbitMQ93 rabbitmqEnabled: { type: 'boolean' },94 rabbitmqEvents: {95 type: 'array',96 minItems: 0,97 items: {98 type: 'string',99 enum: [100 'APPLICATION_STARTUP',101 'QRCODE_UPDATED',102 'MESSAGES_SET',103 'MESSAGES_UPSERT',104 'MESSAGES_EDITED',105 'MESSAGES_UPDATE',106 'MESSAGES_DELETE',107 'SEND_MESSAGE',108 'SEND_MESSAGE_UPDATE',109 'CONTACTS_SET',110 'CONTACTS_UPSERT',111 'CONTACTS_UPDATE',112 'PRESENCE_UPDATE',113 'CHATS_SET',114 'CHATS_UPSERT',115 'CHATS_UPDATE',116 'CHATS_DELETE',117 'GROUPS_UPSERT',118 'GROUP_UPDATE',119 'GROUP_PARTICIPANTS_UPDATE',120 'CONNECTION_UPDATE',121 'LABELS_EDIT',122 'LABELS_ASSOCIATION',123 'CALL',124 'TYPEBOT_START',125 'TYPEBOT_CHANGE_STATUS',126 ],127 },128 },129 // NATS130 natsEnabled: { type: 'boolean' },131 natsEvents: {132 type: 'array',133 minItems: 0,134 items: {135 type: 'string',136 enum: [137 'APPLICATION_STARTUP',138 'QRCODE_UPDATED',139 'MESSAGES_SET',140 'MESSAGES_UPSERT',141 'MESSAGES_EDITED',142 'MESSAGES_UPDATE',143 'MESSAGES_DELETE',144 'SEND_MESSAGE',145 'SEND_MESSAGE_UPDATE',146 'CONTACTS_SET',147 'CONTACTS_UPSERT',148 'CONTACTS_UPDATE',149 'PRESENCE_UPDATE',150 'CHATS_SET',151 'CHATS_UPSERT',152 'CHATS_UPDATE',153 'CHATS_DELETE',154 'GROUPS_UPSERT',155 'GROUP_UPDATE',156 'GROUP_PARTICIPANTS_UPDATE',157 'CONNECTION_UPDATE',158 'LABELS_EDIT',159 'LABELS_ASSOCIATION',160 'CALL',161 'TYPEBOT_START',162 'TYPEBOT_CHANGE_STATUS',163 ],164 },165 },166 // SQS167 sqsEnabled: { type: 'boolean' },168 sqsEvents: {169 type: 'array',170 minItems: 0,171 items: {172 type: 'string',173 enum: [174 'APPLICATION_STARTUP',175 'QRCODE_UPDATED',176 'MESSAGES_SET',177 'MESSAGES_UPSERT',178 'MESSAGES_EDITED',179 'MESSAGES_UPDATE',180 'MESSAGES_DELETE',181 'SEND_MESSAGE',182 'SEND_MESSAGE_UPDATE',183 'CONTACTS_SET',184 'CONTACTS_UPSERT',185 'CONTACTS_UPDATE',186 'PRESENCE_UPDATE',187 'CHATS_SET',188 'CHATS_UPSERT',189 'CHATS_UPDATE',190 'CHATS_DELETE',191 'GROUPS_UPSERT',192 'GROUP_UPDATE',193 'GROUP_PARTICIPANTS_UPDATE',194 'CONNECTION_UPDATE',195 'LABELS_EDIT',196 'LABELS_ASSOCIATION',197 'CALL',198 'TYPEBOT_START',199 'TYPEBOT_CHANGE_STATUS',200 ],201 },202 },203 // Chatwoot204 chatwootAccountId: { type: 'string' },205 chatwootToken: { type: 'string' },206 chatwootUrl: { type: 'string' },207 chatwootSignMsg: { type: 'boolean' },208 chatwootReopenConversation: { type: 'boolean' },209 chatwootConversationPending: { type: 'boolean' },210 chatwootImportContacts: { type: 'boolean' },211 chatwootNameInbox: { type: 'string' },212 chatwootMergeBrazilContacts: { type: 'boolean' },213 chatwootImportMessages: { type: 'boolean' },214 chatwootDaysLimitImportMessages: { type: 'number' },215 },216 ...isNotEmpty('instanceName'),217};218 219export const presenceOnlySchema: JSONSchema7 = {220 $id: v4(),221 type: 'object',222 properties: {223 presence: {224 type: 'string',225 enum: ['unavailable', 'available', 'composing', 'recording', 'paused'],226 },227 },228 required: ['presence'],229};230 