forked from raweee/node-red-contrib-whatsapp-link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhatsappReply.js
54 lines (45 loc) · 1.66 KB
/
whatsappReply.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module.exports = function(RED) {
function WhatsappReply(config) {
RED.nodes.createNode(this,config);
var node = this;
node.instruction = config.instruction;
node.react = config.react;
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 if (node.react){
message.react(node.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);
}