From 8732af0f430542ab66d06af2fdaff5309b7a2cd5 Mon Sep 17 00:00:00 2001 From: allburov Date: Thu, 13 Oct 2022 10:14:43 +0700 Subject: [PATCH] Add onAnyMessage hook --- README.md | 1 + src/whatsapp.service.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 99cd5b3f..d859b811 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ The description of [webhooks you can in Venom README.md, section Events](https:/ All webhooks are disabled by default: +- `WHATSAPP_HOOK_ONANYMESSAGE=http://localhost/uri` - `WHATSAPP_HOOK_ONMESSAGE=http://localhost/uri` - `WHATSAPP_HOOK_ONSTATECHANGE=http://localhost/uri` - `WHATSAPP_HOOK_ONACK=http://localhost/uri` diff --git a/src/whatsapp.service.ts b/src/whatsapp.service.ts index 08cbc8ff..411243c2 100644 --- a/src/whatsapp.service.ts +++ b/src/whatsapp.service.ts @@ -15,9 +15,11 @@ const writeFileAsync = promisify(fs.writeFile) const SECOND = 1000; -const ONMESSAGE_HOOK = "onMessage" +const ON_ANY_MESSAGE_HOOK = "onAnyMessage" +const ON_MESSAGE_HOOK = "onMessage" const HOOKS = [ - ONMESSAGE_HOOK, + ON_ANY_MESSAGE_HOOK, + ON_MESSAGE_HOOK, "onStateChange", "onAck", // TODO: IMPLEMENTED THESE TOO @@ -191,7 +193,7 @@ export class WhatsappService { continue } - if (hook === ONMESSAGE_HOOK) { + if (hook === ON_MESSAGE_HOOK || hook == ON_ANY_MESSAGE_HOOK) { this.whatsapp[hook](data => this.onMessageHook(data, url)) } else { this.whatsapp[hook](data => this.callWebhook(data, url))