From 642c2b58414901af1a8731213cf854907db32991 Mon Sep 17 00:00:00 2001 From: Daniel Gradman-Svendsen Date: Mon, 17 Nov 2025 14:10:07 +0100 Subject: [PATCH] First take on recipient node --- chats-out.html | 17 +++++++---------- chats-out.js | 6 +++++- group-out.html | 17 +++++++---------- group-out.js | 6 +++++- groupRecipient.html | 41 +++++++++++++++++++++++++++++++++++++++++ groupRecipient.js | 8 ++++++++ numberRecipient.html | 40 ++++++++++++++++++++++++++++++++++++++++ numberRecipient.js | 8 ++++++++ package.json | 4 +++- 9 files changed, 124 insertions(+), 23 deletions(-) create mode 100644 groupRecipient.html create mode 100644 groupRecipient.js create mode 100644 numberRecipient.html create mode 100644 numberRecipient.js diff --git a/chats-out.html b/chats-out.html index 652f77a..4763a2f 100644 --- a/chats-out.html +++ b/chats-out.html @@ -5,7 +5,7 @@ defaults: { name: {value:"Chats Out"}, whatsappLink: {value:"whatsapp-web", type:'whatsappLink'}, - number: {value: ""} + recipient: {value:"", type:'number-recipient', required:false} }, outputs:0, inputs:1, @@ -27,17 +27,14 @@
- - + +
-

Don't forget to mention international dialing code befor your number. - Number must be in format like +11 99999 99999 without any space.

-

OR

-

Leave the Number blank here and provide the number along with msg.paylod - at `msg.toNumber` with international code.

-

To send message on multiple contacts an Arrar of number can be passed - on `msg.toNumber` like `msg.toNumber = ["+1199999999", "+12990000099", "+1311111111"].

+

Recipient: Select a reusable Number Recipient configuration (optional).

+

Override at runtime: Provide msg.toNumber to override the configured recipient.

+

Number format: +11 99999 99999 (international dialing code, no spaces).

+

For multiple contacts, pass an array: msg.toNumber = ["+1199999999", "+12990000099"]

diff --git a/chats-out.js b/chats-out.js index 331124f..db82cef 100644 --- a/chats-out.js +++ b/chats-out.js @@ -4,7 +4,11 @@ module.exports = function(RED) { function WhatsappOut(config) { RED.nodes.createNode(this,config); var node = this; - node.number = config.number; + + // Get number from recipient config node if configured + var recipientNode = RED.nodes.getNode(config.recipient); + node.number = recipientNode ? recipientNode.number : null; + var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink); node.waClient = whatsappLinkNode.client; const { MessageMedia, Buttons } = require('whatsapp-web.js'); diff --git a/group-out.html b/group-out.html index dc460c0..d943fb7 100644 --- a/group-out.html +++ b/group-out.html @@ -5,7 +5,7 @@ defaults: { name: {value:"Group Message"}, whatsappLink: {value:"whatsapp-web", type:'whatsappLink'}, - gID: {value: ""} + recipient: {value:"", type:'group-recipient', required:false} }, outputs:0, inputs:1, @@ -27,17 +27,14 @@
- - + +
-

Group chat IDs are numbers given to each chats in whatsapp.
- - For every message recived from whatsapp-chats-in Node, - Chat ID may be read at msg.chatID.
- Or
- - Chat ID of group can also be recive from whatsapp-admin Node, - whenever the new group joined, Admin Node will notifiy the same. -

+

Recipient: Select a reusable Group Recipient configuration (optional).

+

Override at runtime: Provide msg.toNumber to override the configured recipient.

+

Group IDs are in format NUMBER-TIMESTAMP (e.g., 1234567890-1234567890).

+

Find group IDs from msg.chatID in chats-in node or from the admin node when joining groups.

diff --git a/group-out.js b/group-out.js index 0e46117..ab3bf18 100644 --- a/group-out.js +++ b/group-out.js @@ -4,7 +4,11 @@ module.exports = function(RED) { function WhatsappGroupOut(config) { RED.nodes.createNode(this,config); var node = this; - node.number = config.gID; + + // Get group ID from recipient config node if configured + var recipientNode = RED.nodes.getNode(config.recipient); + node.number = recipientNode ? recipientNode.groupId : null; + var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink); node.waClient = whatsappLinkNode.client; diff --git a/groupRecipient.html b/groupRecipient.html new file mode 100644 index 0000000..1e660cc --- /dev/null +++ b/groupRecipient.html @@ -0,0 +1,41 @@ + + + + + diff --git a/groupRecipient.js b/groupRecipient.js new file mode 100644 index 0000000..d404e4e --- /dev/null +++ b/groupRecipient.js @@ -0,0 +1,8 @@ +module.exports = function(RED) { + function GroupRecipientNode(n) { + RED.nodes.createNode(this, n); + this.groupId = n.groupId; + this.name = n.name; + } + RED.nodes.registerType("group-recipient", GroupRecipientNode); +} diff --git a/numberRecipient.html b/numberRecipient.html new file mode 100644 index 0000000..e629cb0 --- /dev/null +++ b/numberRecipient.html @@ -0,0 +1,40 @@ + + + + + diff --git a/numberRecipient.js b/numberRecipient.js new file mode 100644 index 0000000..f45ca28 --- /dev/null +++ b/numberRecipient.js @@ -0,0 +1,8 @@ +module.exports = function(RED) { + function NumberRecipientNode(n) { + RED.nodes.createNode(this, n); + this.number = n.number; + this.name = n.name; + } + RED.nodes.registerType("number-recipient", NumberRecipientNode); +} diff --git a/package.json b/package.json index 590db76..07076e3 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "whatsapp chats-out": "chats-out.js", "whatsapp group-out": "group-out.js", "whatsapp reply": "whatsappReply.js", - "whatsapp Link": "whatsappLink.js" + "whatsapp Link": "whatsappLink.js", + "number-recipient": "numberRecipient.js", + "group-recipient": "groupRecipient.js" } }, "dependencies": {