Reply Node(Beta) Added

This commit is contained in:
rawee 2023-01-01 20:13:55 +05:30
parent 2fc45ac0ed
commit 33e40fd3ef
3 changed files with 94 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "node-red-contrib-whatsapp-link",
"version": "0.1.28",
"version": "0.1.28A",
"description": "Node to send and receive whatsapp chats and group messages. | No third party APIs",
"repository": {
"type": "git",
@ -25,6 +25,7 @@
"whatsapp chats-in": "chats-in.js",
"whatsapp chats-out": "chats-out.js",
"whatsapp group-out": "group-out.js",
"whatsapp reply": "reply.js",
"whatsapp Link": "whatsappLink.js"
}
},

39
reply.html Normal file
View File

@ -0,0 +1,39 @@
<script type="text/javascript">
RED.nodes.registerType('reply',{
category: 'whatsapp',
color: '#25D366',
defaults: {
name: {value:"Reply"},
instruction : {value : ""},
whatsappLink: {value:"whatsapp-web", type:'whatsappLink'}
},
inputs:1,
icon: 'whatsappLink.svg',
label: function() {
return this.name||"Reply";
}
});
</script>
<script type="text/html" data-template-name="reply">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-whatsappLink"><i class="fa fa-gear"></i> Client</label>
<input type="text" id="node-input-whatsappLink" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-instruction"><i class="fa fa-tag"></i> Instruction</label>
<input type="text" id="node-input-instruction" placeholder="instruction">
</div>
<div class="form-tips">
<p>Node to reply on message.</p>
</div>
</script>
<script type="text/markdown" data-help-name="reply">
Node to reply on meassage recived.
</script>

53
reply.js Normal file
View File

@ -0,0 +1,53 @@
module.exports = function(RED) {
function WhatsappReply(config) {
RED.nodes.createNode(this,config);
var node = this;
node.instruction = config.instruction ;
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
node.waClient = whatsappLinkNode.client;
let instructionPayload = null ;
function SetStatus(WAStatus, color){
node.status({fill:color,shape:"dot",text:WAStatus});
};
node.on('input', (msg)=>{
instructionPayload = msg.payload ;
});
node.waClient.on('message_create', async (message) => {
if (message.body.startsWith(node.instruction)){
if(instructionPayload) {
message.reply(instructionPayload)
}
else {
message.react('😅');
message.reply('👍');
};
}
});
//whatsapp Status Parameters----
node.waClient.on('qr', (qr) => {
SetStatus("QR Code Generated", "yellow");
});
node.waClient.on('auth_failure', () => {
SetStatus('Not Connected','red');
});
node.waClient.on('loading_screen', () => {
SetStatus('Connecting...','yellow');
});
node.waClient.on('ready', () => {
SetStatus('Connected','green');
});
node.waClient.on('disconnected', () => {
SetStatus("Disconnected","red");
});
}
RED.nodes.registerType("reply", WhatsappReply);
}