From 5e9f1805d97d4ee8b4147acb3223dbe1363a27c6 Mon Sep 17 00:00:00 2001 From: jrcleber Date: Tue, 2 Jan 2024 19:01:40 +0000 Subject: [PATCH] reference of the instance in the webhook --- apiary.apib | 4 ---- src/whatsapp/services/whatsapp.service.ts | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 apiary.apib diff --git a/apiary.apib b/apiary.apib deleted file mode 100644 index 3bc43e3a..00000000 --- a/apiary.apib +++ /dev/null @@ -1,4 +0,0 @@ -FORMAT: 1A -HOST: https://polls.apiblueprint.org/ - -# Cleber Wilson \ No newline at end of file diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 4e07fb79..db745bc1 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -250,19 +250,27 @@ export class WAStartupService { private async sendDataWebhook(event: WebhookEventsType, data: T) { const eventDesc = WebhookEventsEnum[event]; - console.log(1, eventDesc); + try { if (this.webhook?.enabled && isURL(this.webhook?.url)) { if (this.webhook?.events && this.webhook?.events[event]) { await axios.post( this.webhook.url, - { event: eventDesc, data }, + { + event: eventDesc, + instance: this.instance, + data, + }, { headers: { 'Resource-Owner': this.instance.ownerJid } }, ); } else { await axios.post( this.webhook.url, - { event: eventDesc, data }, + { + event: eventDesc, + instance: this.instance, + data, + }, { headers: { 'Resource-Owner': this.instance.ownerJid } }, ); } @@ -294,7 +302,7 @@ export class WAStartupService { globalWebhook.URL, { event: eventDesc, - instance: this.instance.name, + instance: this.instance, data, }, { headers: { 'Resource-owner': this.instance.ownerJid } }, @@ -413,6 +421,7 @@ export class WAStartupService { this.instance.profilePicUrl = ( await this.profilePicture(this.instance.ownerJid) ).profilePictureUrl; + this.instance.connectionStatus = 'ONLINE'; this.repository.instance .update({ @@ -420,7 +429,7 @@ export class WAStartupService { data: { ownerJid: this.instance.ownerJid, profilePicUrl: this.instance.profilePicUrl, - connectionStatus: 'ONLINE', + connectionStatus: this.instance.connectionStatus, }, }) .catch((err) => this.logger.error(err)); @@ -1322,8 +1331,6 @@ export class WAStartupService { public async mediaMessage(data: SendMediaDto) { const generate = await this.prepareMediaMessage(data.mediaMessage); - console.log(generate); - return await this.sendMessageWithTyping( data.number, { ...generate.message },