From 3c102f3258f44ecd465a00b7e9419c39084f8a2b Mon Sep 17 00:00:00 2001 From: rawee Date: Sat, 17 Dec 2022 15:04:34 +0530 Subject: [PATCH] Group Node Added --- package.json | 9 ++++---- whatsapp-Gout.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ whatsapp-out.js | 8 +++---- 3 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 whatsapp-Gout.js diff --git a/package.json b/package.json index f6b2ba3..6e6df6b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "node-red-contrib-whatsapp-link", - "version": "0.1.19", + "version": "0.1.21", "description": "Whatsapp connection with Node-Red | No third party APIs", - "scripts": { + "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -25,7 +25,8 @@ "whatsapp admin": "whatsappAdmin.js", "whatsapp in": "whatsapp-in.js", "whatsapp Out": "whatsapp-out.js", - "whatsapp Link": "whatsappLink.js" + "whatsapp Link": "whatsappLink.js", + "Group Out": "whatsapp-Gout.js" } }, "dependencies": { @@ -33,6 +34,6 @@ "whatsapp-web.js": "^1.18.4" }, "engines": { - "node" : ">=8.0.0" + "node": ">=8.0.0" } } diff --git a/whatsapp-Gout.js b/whatsapp-Gout.js new file mode 100644 index 0000000..6df2f7a --- /dev/null +++ b/whatsapp-Gout.js @@ -0,0 +1,55 @@ +module.exports = function(RED) { + function WhatsappGroupOut(config) { + RED.nodes.createNode(this,config); + var node = this; + node.gID = config.gID; + node.gID = node.gID.replace(/\D/g, ''); + //node.number = this.number.includes('@c.us') ? this.number : `${this.number}@c.us`; + node.gID = `${node.gID}@g.us`; + var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink); + node.waClient = whatsappLinkNode.client; + + node.on('input', (message)=> { + try { + node.waClient.sendMessage(node.gID, message.payload); + } + catch(e) { + node.log(`Error Sending Msg: ${e}`); + }; + }); + + + + + function SetStatus(WAStatus, color){ + node.status({fill:color,shape:"dot",text:WAStatus}); + }; + + //whatsapp Status Parameters---- + node.waClient.on('qr', (qr) => { + SetStatus("QR Code Generated", "yellow"); + // QRCode.toDataURL(qr, function(err, url){ + // msg = {payload : url}; + // node.send(msg); + // }); + }); + + 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("whatsapp-Gout", WhatsappGroupOut); +} diff --git a/whatsapp-out.js b/whatsapp-out.js index a83e0d3..fc44a0d 100644 --- a/whatsapp-out.js +++ b/whatsapp-out.js @@ -26,10 +26,10 @@ module.exports = function(RED) { //whatsapp Status Parameters---- node.waClient.on('qr', (qr) => { SetStatus("QR Code Generated", "yellow"); - QRCode.toDataURL(qr, function(err, url){ - msg = {payload : url}; - node.send(msg); - }); + // QRCode.toDataURL(qr, function(err, url){ + // msg = {payload : url}; + // node.send(msg); + // }); }); node.waClient.on('auth_failure', () => {