First take on recipient node
This commit is contained in:
parent
9a7b19f938
commit
642c2b5841
@ -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 @@
|
||||
<input type="text" id="node-input-whatsappLink" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-number"><i class="fa fa-address-card-o"></i> Number</label>
|
||||
<input type="text" id="node-input-number" placeholder="Mobile or Group Number..">
|
||||
<label for="node-input-recipient"><i class="fa fa-user"></i> Recipient</label>
|
||||
<input type="text" id="node-input-recipient" placeholder="Select or add recipient">
|
||||
</div>
|
||||
<div class="form-tips">
|
||||
<p>Don't forget to mention international dialing code befor your number.
|
||||
Number must be in format like <b>+11 99999 99999</b> without any space.</p>
|
||||
<P><b>OR</b></P>
|
||||
<P>Leave the Number blank here and provide the number along with msg.paylod
|
||||
at `msg.toNumber` with international code.</P>
|
||||
<p>To send message on multiple contacts an Arrar of number can be passed
|
||||
on `msg.toNumber` like `msg.toNumber = ["+1199999999", "+12990000099", "+1311111111"].</p>
|
||||
<p><b>Recipient:</b> Select a reusable Number Recipient configuration (optional).</p>
|
||||
<p><b>Override at runtime:</b> Provide <code>msg.toNumber</code> to override the configured recipient.</p>
|
||||
<p>Number format: <b>+11 99999 99999</b> (international dialing code, no spaces).</p>
|
||||
<p>For multiple contacts, pass an array: <code>msg.toNumber = ["+1199999999", "+12990000099"]</code></p>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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 @@
|
||||
<input type="text" id="node-input-whatsappLink" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-gID"><i class="fa fa-address-card-o"></i> Group ID </label>
|
||||
<input type="text" id="node-input-gID" placeholder="Group Chat ID..">
|
||||
<label for="node-input-recipient"><i class="fa fa-users"></i> Group Recipient</label>
|
||||
<input type="text" id="node-input-recipient" placeholder="Select or add group recipient">
|
||||
</div>
|
||||
<div class="form-tips">
|
||||
<p>Group chat IDs are numbers given to each chats in whatsapp. <br>
|
||||
- For every message recived from whatsapp-chats-in Node,
|
||||
Chat ID may be read at <b>msg.chatID</b>.<br>
|
||||
<b>Or</b><br>
|
||||
- Chat ID of group can also be recive from whatsapp-admin Node,
|
||||
whenever the new group joined, Admin Node will notifiy the same.
|
||||
</p>
|
||||
<p><b>Recipient:</b> Select a reusable Group Recipient configuration (optional).</p>
|
||||
<p><b>Override at runtime:</b> Provide <code>msg.toNumber</code> to override the configured recipient.</p>
|
||||
<p>Group IDs are in format NUMBER-TIMESTAMP (e.g., 1234567890-1234567890).</p>
|
||||
<p>Find group IDs from <code>msg.chatID</code> in chats-in node or from the admin node when joining groups.</p>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
41
groupRecipient.html
Normal file
41
groupRecipient.html
Normal file
@ -0,0 +1,41 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('group-recipient', {
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: {value: ""},
|
||||
groupId: {value: "", required: true}
|
||||
},
|
||||
label: function() {
|
||||
return this.name || this.groupId || "Group Recipient";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="group-recipient">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-config-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-groupId"><i class="fa fa-users"></i> Group ID</label>
|
||||
<input type="text" id="node-config-input-groupId" placeholder="1234567890-1234567890">
|
||||
</div>
|
||||
<div class="form-tips">
|
||||
<strong>Tip:</strong> Enter the WhatsApp group ID in the format NUMBER-TIMESTAMP (e.g., 1234567890-1234567890).
|
||||
<br>You can find the group ID by sending a message to the group and checking the message metadata.
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="group-recipient">
|
||||
<p>Configuration node for a WhatsApp group recipient.</p>
|
||||
<h3>Details</h3>
|
||||
<p>This configuration node stores a group ID that can be reused across multiple group output nodes.</p>
|
||||
<p>The group ID can be overridden at runtime by setting <code>msg.toNumber</code> in the flow.</p>
|
||||
<h3>Configuration</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>Name <span class="property-type">string</span></dt>
|
||||
<dd>A friendly name to identify this group (optional).</dd>
|
||||
<dt>Group ID <span class="property-type">string</span></dt>
|
||||
<dd>The WhatsApp group ID in the format NUMBER-TIMESTAMP (contains a hyphen).</dd>
|
||||
</dl>
|
||||
</script>
|
||||
8
groupRecipient.js
Normal file
8
groupRecipient.js
Normal file
@ -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);
|
||||
}
|
||||
40
numberRecipient.html
Normal file
40
numberRecipient.html
Normal file
@ -0,0 +1,40 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('number-recipient', {
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: {value: ""},
|
||||
number: {value: "", required: true}
|
||||
},
|
||||
label: function() {
|
||||
return this.name || this.number || "Number Recipient";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="number-recipient">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-config-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-number"><i class="fa fa-phone"></i> Phone Number</label>
|
||||
<input type="text" id="node-config-input-number" placeholder="+1234567890">
|
||||
</div>
|
||||
<div class="form-tips">
|
||||
<strong>Tip:</strong> Enter the phone number with or without country code (e.g., +1234567890 or 1234567890).
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="number-recipient">
|
||||
<p>Configuration node for a WhatsApp chat recipient.</p>
|
||||
<h3>Details</h3>
|
||||
<p>This configuration node stores a phone number that can be reused across multiple chat output nodes.</p>
|
||||
<p>The phone number can be overridden at runtime by setting <code>msg.toNumber</code> in the flow.</p>
|
||||
<h3>Configuration</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>Name <span class="property-type">string</span></dt>
|
||||
<dd>A friendly name to identify this recipient (optional).</dd>
|
||||
<dt>Phone Number <span class="property-type">string</span></dt>
|
||||
<dd>The WhatsApp phone number. Can include country code with or without + prefix.</dd>
|
||||
</dl>
|
||||
</script>
|
||||
8
numberRecipient.js
Normal file
8
numberRecipient.js
Normal file
@ -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);
|
||||
}
|
||||
@ -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": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user