From b3b4ee7a288dc9d64b9d61f62620f3eb72366dc4 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Wed, 2 Aug 2023 14:48:02 -0300 Subject: [PATCH] fix: If you pass empty events in create instance and set webhook it is understood as all --- CHANGELOG.md | 1 + .../controllers/instance.controller.ts | 30 ++++++++++++++++++- .../controllers/webhook.controller.ts | 27 +++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb4f5e7..b5d9ac9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Encoded spaces in chatwoot webhook * Adjustment in the saving of contacts, saving the information of the number and Jid * Update Dockerfile +* If you pass empty events in create instance and set webhook it is understood as all ### Integrations diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index e2b81695..8acb2a80 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -86,10 +86,38 @@ export class InstanceController { this.logger.verbose('creating webhook'); try { + let newEvents: string[] = []; + if (events.length === 0) { + newEvents = [ + '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', + 'CALL', + 'NEW_JWT_TOKEN', + ]; + } else { + newEvents = events; + } this.webhookService.create(instance, { enabled: true, url: webhook, - events, + events: newEvents, webhook_by_events, }); diff --git a/src/whatsapp/controllers/webhook.controller.ts b/src/whatsapp/controllers/webhook.controller.ts index 281147db..b1d9b415 100644 --- a/src/whatsapp/controllers/webhook.controller.ts +++ b/src/whatsapp/controllers/webhook.controller.ts @@ -24,6 +24,33 @@ export class WebhookController { data.events = []; } + if (data.events.length === 0) { + logger.verbose('webhook events empty'); + data.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', + 'CALL', + 'NEW_JWT_TOKEN', + ]; + } + return this.webhookService.create(instance, data); }