Buttons Added
This commit is contained in:
parent
f0221c4c70
commit
2823eb349d
188
README.md
188
README.md
@ -64,7 +64,7 @@ Admin Node generate QR Code just below the node for easy connection with whatsap
|
|||||||
|
|
||||||
3. **Chats Out** : As simple as mention on name, node will send `msg.payload` recived at input to the number mentioned in node.
|
3. **Chats Out** : As simple as mention on name, node will send `msg.payload` recived at input to the number mentioned in node.
|
||||||
|
|
||||||
MultiMedia Message Out: Requirments-
|
MultiMedia Message: Requirments-
|
||||||
| Input | Description |
|
| Input | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| `msg.image` | Base64 (encoded image) |
|
| `msg.image` | Base64 (encoded image) |
|
||||||
@ -82,9 +82,192 @@ Admin Node generate QR Code just below the node for easy connection with whatsap
|
|||||||
|
|
||||||
The node will send recived `msg.payload` to a group chat.
|
The node will send recived `msg.payload` to a group chat.
|
||||||
|
|
||||||
|
## Button, List and TemplateButton
|
||||||
|
Supported in Whatsapp-Lite only, `TODO for Whatsapp-Web`.
|
||||||
|
|
||||||
|
* <b>Simple Button </b>For simple 3 Bottons your `msg.paylod` should be...
|
||||||
|
|
||||||
|
```js
|
||||||
|
msg.payload = {
|
||||||
|
text: "Hi it's button message", //String
|
||||||
|
footer: 'Hello World', //String
|
||||||
|
headerType: 1, //keep it "1" only.
|
||||||
|
buttons: [ // Array of buttons.
|
||||||
|
{buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1},
|
||||||
|
{buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1},
|
||||||
|
{buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* <b>TemplateButton</b> combination of <b>link button</b>, <b>Call button</b> and Normal buttons. Your `msg.paylod` should look similar to--
|
||||||
|
|
||||||
|
```js
|
||||||
|
msg.payload = {
|
||||||
|
text: "Hi it's a template message by Node-RED 👍 to Test",
|
||||||
|
footer: 'Hello I am footer of message.',
|
||||||
|
templateButtons: [
|
||||||
|
{index: 1, urlButton: {displayText: '⭐ Vist Node-RED', url: 'https://nodered.org/'}},
|
||||||
|
{index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}},
|
||||||
|
{index: 3, quickReplyButton: {displayText: 'Click me I am Button', id: 'I-am-button-id-without-space'}},
|
||||||
|
{index: 4, quickReplyButton: {displayText: '🖱️ Sample Button 2', id: 'button-2-was-clicked'}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* <b>List Message</b> combination of <b>link button</b>, <b>List button</b> and Selectors. Your `msg.paylod` should look similar to--
|
||||||
|
|
||||||
|
```js
|
||||||
|
msg.payload = {
|
||||||
|
text: "This is a list",
|
||||||
|
footer: "nice footer, link: https://google.com",
|
||||||
|
title: "Amazing boldfaced list title",
|
||||||
|
buttonText: "Required, Tap to see List",
|
||||||
|
sections : [{
|
||||||
|
title: "Section 1",
|
||||||
|
rows: [
|
||||||
|
{title: "Option 1", rowId: "option1"},
|
||||||
|
{title: "Option 2", rowId: "option2", description: "This is a description"}
|
||||||
|
]},
|
||||||
|
{
|
||||||
|
title: "Section 2",
|
||||||
|
rows: [
|
||||||
|
{title: "Option 3", rowId: "option3"},
|
||||||
|
{title: "Option 4", rowId: "option4", description: "This is a description V2"}
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
Yes its lot require for buttons, A node will come soon to minimize these effors.
|
||||||
|
You may direct import these test button with bellow code.
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "6fe81f4418014185",
|
||||||
|
"type": "inject",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "Sample button Text",
|
||||||
|
"props": [
|
||||||
|
{
|
||||||
|
"p": "payload"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repeat": "",
|
||||||
|
"crontab": "",
|
||||||
|
"once": false,
|
||||||
|
"onceDelay": 0.1,
|
||||||
|
"topic": "",
|
||||||
|
"payload": "",
|
||||||
|
"payloadType": "date",
|
||||||
|
"x": 130,
|
||||||
|
"y": 180,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"ad52615eb46ed55b"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "cf275a62edbc347f",
|
||||||
|
"type": "inject",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "Smart Button Test",
|
||||||
|
"props": [
|
||||||
|
{
|
||||||
|
"p": "topic",
|
||||||
|
"v": "",
|
||||||
|
"vt": "date"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repeat": "",
|
||||||
|
"crontab": "",
|
||||||
|
"once": false,
|
||||||
|
"onceDelay": 0.1,
|
||||||
|
"topic": "",
|
||||||
|
"x": 130,
|
||||||
|
"y": 140,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"f5fbed87687de5b7"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "f5fbed87687de5b7",
|
||||||
|
"type": "function",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "TempButton",
|
||||||
|
"func": "msg.payload = {\n text: \"Hi it's a template message by Node-RED 👍 to Test\",\n footer: 'Hello I am footer of message.',\n templateButtons: [\n {\n index: 1,\n urlButton: {\n displayText: '⭐ Vist Node-RED',\n url: 'https://nodered.org/'\n }\n },\n {\n index: 2,\n callButton: {\n displayText: 'Call me!',\n phoneNumber: '+1 (234) 5678-901'\n }\n },\n {\n index: 3,\n quickReplyButton: {\n displayText: 'Click me I am Button',\n id: 'id-like-buttons-message'\n }\n },\n {\n index: 4,\n quickReplyButton: {\n displayText: '🖱️ Sample Button',\n id: 'button-id-no-space'\n }\n }] \n}\nreturn msg;",
|
||||||
|
"outputs": 1,
|
||||||
|
"noerr": 0,
|
||||||
|
"initialize": "",
|
||||||
|
"finalize": "",
|
||||||
|
"libs": [],
|
||||||
|
"x": 370,
|
||||||
|
"y": 140,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"9caf4dd912ca82f6"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ad52615eb46ed55b",
|
||||||
|
"type": "function",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "Button",
|
||||||
|
"func": "msg.payload = {\n text: \"Hi it's button message\",\n footer: 'Hello World',\n headerType: 1,\n buttons: [\n {buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1},\n {buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1},\n {buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1}\n ]\n }\nreturn msg;",
|
||||||
|
"outputs": 1,
|
||||||
|
"noerr": 0,
|
||||||
|
"initialize": "",
|
||||||
|
"finalize": "",
|
||||||
|
"libs": [],
|
||||||
|
"x": 350,
|
||||||
|
"y": 180,
|
||||||
|
"wires": [
|
||||||
|
[
|
||||||
|
"9caf4dd912ca82f6"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "670571eb76e4d237",
|
||||||
|
"type": "comment",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "Connect them to Chats-Out Node. ",
|
||||||
|
"info": "Dont foget mobile no.",
|
||||||
|
"x": 160,
|
||||||
|
"y": 100,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "9caf4dd912ca82f6",
|
||||||
|
"type": "chats-out",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "Chats Out",
|
||||||
|
"whatsappLink": "whatsapp-web",
|
||||||
|
"number": "",
|
||||||
|
"x": 620,
|
||||||
|
"y": 160,
|
||||||
|
"wires": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3e0550933ed06e84",
|
||||||
|
"type": "comment",
|
||||||
|
"z": "a133618d7af8d486",
|
||||||
|
"name": "Mention Your Phone No. in node.",
|
||||||
|
"info": "",
|
||||||
|
"x": 610,
|
||||||
|
"y": 120,
|
||||||
|
"wires": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
5. **Reply Node** : In Beta mode.
|
5. **Reply Node** : In Beta mode.
|
||||||
|
|
||||||
Node will reply(the `payload`) on each message starting with string mentioned in instruction coloum or defaults `!red`.
|
Node will reply(the `payload`) on each message starting with string mentioned in instruction coloum or defaults `!red`. Avoid using it please.
|
||||||
|
|
||||||
|
|
||||||
## Issues & Updates
|
## Issues & Updates
|
||||||
@ -96,6 +279,7 @@ Issues and Suggestions are welcome [here.](https://github.com/raweee/node-red-co
|
|||||||
* `Ver-0.1.28` : Now QR Codes are directlly avilable in run time on Whatsapp-Admin-Node.
|
* `Ver-0.1.28` : Now QR Codes are directlly avilable in run time on Whatsapp-Admin-Node.
|
||||||
* `Ver-0.1.30` : Message can be send to an Array of contacts provided at `msg.toNumber`.
|
* `Ver-0.1.30` : Message can be send to an Array of contacts provided at `msg.toNumber`.
|
||||||
* `Ver-0.1.32` : Socket based `Whatsapp Lite` config node added in beta mode. Image message sending support added in chats-out node.
|
* `Ver-0.1.32` : Socket based `Whatsapp Lite` config node added in beta mode. Image message sending support added in chats-out node.
|
||||||
|
* `Ver-0.1.33` : Button and list support added, Minnor bugs fixed.
|
||||||
|
|
||||||
## Future Nodes
|
## Future Nodes
|
||||||
Currently working on more Whatsapp Node and will be avilable soon -
|
Currently working on more Whatsapp Node and will be avilable soon -
|
||||||
|
|||||||
10
admin.html
10
admin.html
@ -24,15 +24,10 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var adminNodeId = null;
|
|
||||||
RED.comms.subscribe("whatsappLinkNodeID", function (e, currentID) {
|
|
||||||
adminNodeId = currentID;
|
|
||||||
})
|
|
||||||
|
|
||||||
var creatImageContainer = function(NodeID) {
|
var creatImageContainer = function(NodeID) {
|
||||||
let img = document.getElementById("whatsappLink-QRcode-" + NodeID)
|
let img = document.getElementById("whatsappLink-QRcode-" + NodeID)
|
||||||
if (!img) {
|
if (!img) {
|
||||||
const container = document.getElementById(adminNodeId)
|
const container = document.getElementById(NodeID)
|
||||||
if (!container) { return }
|
if (!container) { return }
|
||||||
const img = document.createElementNS("http://www.w3.org/2000/svg", 'image')
|
const img = document.createElementNS("http://www.w3.org/2000/svg", 'image')
|
||||||
img.setAttribute('id', "whatsappLink-QRcode-" + NodeID)
|
img.setAttribute('id', "whatsappLink-QRcode-" + NodeID)
|
||||||
@ -50,9 +45,10 @@
|
|||||||
qrImage.addEventListener("click", ()=> removeQrCode(id), {once:true})
|
qrImage.addEventListener("click", ()=> removeQrCode(id), {once:true})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
RED.comms.subscribe("whatsappLinkQrCode", function (e, msg) {
|
RED.comms.subscribe("whatsappLinkQrCode", function (e, msg) {
|
||||||
if (msg.image === null){
|
if (msg.image === null){
|
||||||
removeQrCode(msg.id);
|
removeQrCode(adminNodeId);
|
||||||
}
|
}
|
||||||
renderQrCode(msg.id, msg.image);
|
renderQrCode(msg.id, msg.image);
|
||||||
});
|
});
|
||||||
|
|||||||
95
admin.js
95
admin.js
@ -6,7 +6,7 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
||||||
node.client = whatsappLinkNode.client;
|
node.client = whatsappLinkNode.client;
|
||||||
RED.comms.publish("whatsappLinkNodeID", node.id)
|
// RED.comms.publish("whatsappLinkNodeID", node.id)
|
||||||
|
|
||||||
function SetStatus(WAStatus, color){
|
function SetStatus(WAStatus, color){
|
||||||
node.status({fill:color,shape:"dot",text:WAStatus});
|
node.status({fill:color,shape:"dot",text:WAStatus});
|
||||||
@ -15,33 +15,53 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Commands recived for Whatsapp Admin.
|
// Commands recived for Whatsapp Admin.
|
||||||
this.on('input', async function(msg, send){
|
this.on('input', async function(msg, send){
|
||||||
if (msg.payload === "destroy") {
|
if (msg.payload === "destroy") {
|
||||||
if(node.client.clientType === "waWebClient"){
|
if(node.client.clientType === "waWebClient"){
|
||||||
node.clinet.WAClose();
|
node.clinet.WAClose();
|
||||||
SetStatus("Disconnected","red");
|
SetStatus("Disconnected","red");
|
||||||
}
|
} else {
|
||||||
|
var client = await node.client;
|
||||||
|
client.end();
|
||||||
|
SetStatus("Disconnected","red");
|
||||||
}
|
}
|
||||||
else if (msg.payload==="logout") {
|
}
|
||||||
if(node.client.clientType === "waWebClient"){
|
else if (msg.payload==="logout") {
|
||||||
node.client.logout();
|
if(node.client.clientType === "waWebClient"){
|
||||||
SetStatus("Logged Out","red");
|
node.client.logout();
|
||||||
}
|
SetStatus("Logged Out","red");
|
||||||
|
} else{
|
||||||
|
var client = await node.client;
|
||||||
|
client.logout();
|
||||||
|
SetStatus("Disconnected","red");
|
||||||
}
|
}
|
||||||
else if (msg.payload === "test"){
|
}
|
||||||
if(node.client.clientType === "waWebClient"){
|
else if (msg.payload === "test"){
|
||||||
msg.payload = await node.client.getState();
|
if(node.client.clientType === "waWebClient"){
|
||||||
node.send(msg);
|
msg.payload = await node.client.getState();
|
||||||
}
|
node.send(msg);
|
||||||
|
} else {
|
||||||
|
var client = await node.client;
|
||||||
|
await client.sendPresenceUpdate('available')
|
||||||
|
SetStatus("Presence Avilable","green");
|
||||||
}
|
}
|
||||||
else if (msg.payload === "restart"){
|
}
|
||||||
if(node.client.clientType === "waWebClient"){
|
else if (msg.payload === "restart"){
|
||||||
node.client.WARestart();
|
if(node.client.clientType === "waWebClient"){
|
||||||
SetStatus("Connecting...", "yellow");
|
node.client.WARestart();
|
||||||
}
|
SetStatus("Connecting...", "yellow");
|
||||||
};
|
} else {
|
||||||
});
|
var client = await node.client;
|
||||||
|
client.end();
|
||||||
|
SetStatus("Restarting...", "yellow");
|
||||||
|
setTimeout(() => {
|
||||||
|
SetStatus("Please Deploy all nodes to subscribe for messgaes", "yellow");
|
||||||
|
node.client.clientStartFunction();
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
if(node.client.clientType === "waWebClient"){
|
if(node.client.clientType === "waWebClient"){
|
||||||
@ -110,6 +130,29 @@ module.exports = function(RED) {
|
|||||||
async function clientFromWhatsappLite(){
|
async function clientFromWhatsappLite(){
|
||||||
client = await node.client;
|
client = await node.client;
|
||||||
client.ev.on('connection.update', (updates)=>{
|
client.ev.on('connection.update', (updates)=>{
|
||||||
|
|
||||||
|
if(updates.qr){
|
||||||
|
QRCode.toDataURL(updates.qr, function(err, url){
|
||||||
|
var qrImageWithID = {};
|
||||||
|
qrImageWithID.id = node.id;
|
||||||
|
qrImageWithID.image = url;
|
||||||
|
RED.comms.publish("whatsappLinkQrCode", qrImageWithID);
|
||||||
|
});
|
||||||
|
|
||||||
|
QRCode.toString(updates.qr, {type : 'terminal', small:true }, function(err, QRTerminal){
|
||||||
|
node.log(`To Connect, Scan the QR Code through your Whatsapp Mobile App.`)
|
||||||
|
console.log("");
|
||||||
|
console.log(QRTerminal);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (connection === 'open') {
|
||||||
|
var qrImageWithID = {};
|
||||||
|
qrImageWithID.id = node.id;
|
||||||
|
qrImageWithID.image = null;
|
||||||
|
RED.comms.publish("whatsappLinkQrCode", qrImageWithID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log(updates);
|
||||||
var {connection} = updates
|
var {connection} = updates
|
||||||
//Setting conncetion status indication
|
//Setting conncetion status indication
|
||||||
if(connection === 'open'){
|
if(connection === 'open'){
|
||||||
@ -124,7 +167,7 @@ module.exports = function(RED) {
|
|||||||
else if(connection === 'connecting'){
|
else if(connection === 'connecting'){
|
||||||
SetStatus("Connecting...", "yellow");
|
SetStatus("Connecting...", "yellow");
|
||||||
}
|
}
|
||||||
else if(updates.is){
|
else if(updates.qr){
|
||||||
SetStatus("Scan QR Code to Connect.", "yellow");
|
SetStatus("Scan QR Code to Connect.", "yellow");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -49,7 +49,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
client.ev.on('messages.upsert', msgs =>{
|
client.ev.on('messages.upsert', msgs =>{
|
||||||
msgs.messages.forEach(async msg =>{
|
msgs.messages.forEach(async msg =>{
|
||||||
msg.payload = msg.message.conversation;
|
msg.payload = msg.message?.conversation;
|
||||||
msg.from = msg.key.participant || msg.key.remoteJid;
|
msg.from = msg.key.participant || msg.key.remoteJid;
|
||||||
msg.from = msg.from.replace(/\D/g, '') || msg.from;
|
msg.from = msg.from.replace(/\D/g, '') || msg.from;
|
||||||
msg.chatID = msg.key.remoteJid.replace(/\D/g, '') || msg.key.remoteJid ;
|
msg.chatID = msg.key.remoteJid.replace(/\D/g, '') || msg.key.remoteJid ;
|
||||||
@ -73,7 +73,7 @@ module.exports = function(RED) {
|
|||||||
else if(connection === 'connecting'){
|
else if(connection === 'connecting'){
|
||||||
SetStatus("Connecting...", "yellow");
|
SetStatus("Connecting...", "yellow");
|
||||||
}
|
}
|
||||||
else if(updates.is){
|
else if(updates.qr){
|
||||||
SetStatus("Scan QR Code to Connect.", "yellow");
|
SetStatus("Scan QR Code to Connect.", "yellow");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
68
chats-out.js
68
chats-out.js
@ -5,36 +5,57 @@ module.exports = function(RED) {
|
|||||||
node.number = config.number;
|
node.number = config.number;
|
||||||
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
||||||
node.waClient = whatsappLinkNode.client;
|
node.waClient = whatsappLinkNode.client;
|
||||||
const { MessageMedia } = require('whatsapp-web.js')
|
const { MessageMedia, Buttons } = require('whatsapp-web.js')
|
||||||
|
|
||||||
let SetStatus = function(WAStatus, color){
|
let SetStatus = function(WAStatus, color){
|
||||||
node.status({fill:color,shape:"dot",text:WAStatus});
|
node.status({fill:color,shape:"dot",text:WAStatus});
|
||||||
};
|
};
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
async function whatsappMessage(numb , inputMessage){
|
function webNubmerSeteing(numb){
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||||
|
numb = `${numb}@c.us`;
|
||||||
|
return numb
|
||||||
|
}
|
||||||
|
|
||||||
|
function socNubmerSeteing(numb){
|
||||||
|
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||||
|
numb = `${numb}@s.whatsapp.net`
|
||||||
|
return numb
|
||||||
|
}
|
||||||
|
|
||||||
|
async function whatsappMessage(numb , inputMessage){
|
||||||
if (node.waClient.clientType === "waWebClient"){
|
if (node.waClient.clientType === "waWebClient"){
|
||||||
try {
|
try {
|
||||||
numb = `${numb}@c.us`;
|
numb = webNubmerSeteing(numb);
|
||||||
|
if(typeof inputMessage === "object"){
|
||||||
|
// inputMessage = new Buttons(inputMessage.text, inputMessage.buttons, "text" ,inputMessage.footer)
|
||||||
|
let myBtn = new Buttons('Button body',[{body:'bt1'},{body:'bt2'},{body:'bt3'}],'title','footer');
|
||||||
|
console.log(myBtn)
|
||||||
|
node.waClient.sendMessage(numb, inputMessage);
|
||||||
|
inputMessage = myBtn
|
||||||
|
}
|
||||||
node.waClient.sendMessage(numb, inputMessage);
|
node.waClient.sendMessage(numb, inputMessage);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e){
|
||||||
node.log(`Error Sending Msg: ${e}`);
|
node.error(`Error Sending Msg: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.waClient.clientType === "waSocketClient"){
|
else if (node.waClient.clientType === "waSocketClient"){
|
||||||
try {
|
try {
|
||||||
let client = await node.waClient;
|
let client = await node.waClient;
|
||||||
numb = `${numb}@s.whatsapp.net`;
|
numb = socNubmerSeteing(numb)
|
||||||
const msgStatus = await client.sendMessage(numb, {text : inputMessage});
|
if (typeof inputMessage ==="string"){
|
||||||
|
inputMessage = {text : inputMessage};
|
||||||
|
}
|
||||||
|
const msgStatus = await client.sendMessage(numb, inputMessage);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
node.log(`Error Sending Msg: ${e}`);
|
node.error(`Error Sending Msg: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.log(`Error Sending Msg: ${e}`)
|
node.error(`Error Sending Msg: ${e}`)
|
||||||
}
|
}
|
||||||
SetStatus("Message Send.", "green");
|
SetStatus("Message Send.", "green");
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
@ -42,20 +63,31 @@ module.exports = function(RED) {
|
|||||||
}, 2000)
|
}, 2000)
|
||||||
};
|
};
|
||||||
|
|
||||||
function whatsappMultiMediaMessage(numb, whatsappImage, whatsappCaption){
|
async function whatsappMultiMediaMessage(numb, whatsappImage, whatsappCaption){
|
||||||
|
var whatsappImageBase64 = whatsappImage.split(',')[1] || whatsappImage;
|
||||||
try {
|
try {
|
||||||
numb = node.number;
|
if (node.waClient.clientType === "waWebClient"){
|
||||||
whatsappImage = whatsappImage.split(',')[1] || whatsappImage;
|
numb = webNubmerSeteing(node.number)
|
||||||
var myMessage = new MessageMedia('image/png', whatsappImage, null, null);
|
var myMessage = new MessageMedia('image/png', whatsappImageBase64, null, null);
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
node.waClient.sendMessage(numb, myMessage, {caption : whatsappCaption || "Image from Node-Red"});
|
||||||
numb = `${numb}@c.us`;
|
}
|
||||||
node.waClient.sendMessage(numb, myMessage, {caption : whatsappCaption || "Image from Node-Red"});
|
else {
|
||||||
|
numb = socNubmerSeteing(node.number)
|
||||||
|
const imageMessage = {
|
||||||
|
text: whatsappCaption,
|
||||||
|
footer: null,
|
||||||
|
templateButtons: null,
|
||||||
|
image: {url : whatsappImage }
|
||||||
|
};
|
||||||
|
let client = await node.waClient;
|
||||||
|
const msgStatus = await client.sendMessage(numb, imageMessage);
|
||||||
|
}
|
||||||
SetStatus("Message Send.", "green");
|
SetStatus("Message Send.", "green");
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
SetStatus('Connected','green');
|
SetStatus('Connected','green');
|
||||||
}, 2000)
|
}, 2000)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
node.log(`Error sending MultiMedia Message : ${e}`)
|
node.error(`Error sending MultiMedia Message : ${e}`)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,7 +159,7 @@ module.exports = function(RED) {
|
|||||||
else if(connection === 'connecting'){
|
else if(connection === 'connecting'){
|
||||||
SetStatus("Connecting...", "yellow");
|
SetStatus("Connecting...", "yellow");
|
||||||
}
|
}
|
||||||
else if(updates.is){
|
else if(updates.qr){
|
||||||
SetStatus("Scan QR Code to Connect.", "yellow");
|
SetStatus("Scan QR Code to Connect.", "yellow");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
121
group-out.js
121
group-out.js
@ -5,36 +5,58 @@ module.exports = function(RED) {
|
|||||||
node.number = config.gID;
|
node.number = config.gID;
|
||||||
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
||||||
node.waClient = whatsappLinkNode.client;
|
node.waClient = whatsappLinkNode.client;
|
||||||
const { MessageMedia } = require('whatsapp-web.js')
|
|
||||||
|
const { MessageMedia, Buttons } = require('whatsapp-web.js')
|
||||||
|
|
||||||
let SetStatus = function(WAStatus, color){
|
let SetStatus = function(WAStatus, color){
|
||||||
node.status({fill:color,shape:"dot",text:WAStatus});
|
node.status({fill:color,shape:"dot",text:WAStatus});
|
||||||
};
|
};
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
async function whatsappMessage(numb , inputMessage){
|
function webNubmerSeteing(numb){
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||||
|
numb = `${numb}@g.us`;
|
||||||
|
return numb
|
||||||
|
}
|
||||||
|
|
||||||
|
function socNubmerSeteing(numb){
|
||||||
|
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
||||||
|
numb = `${numb}@g.us`
|
||||||
|
return numb
|
||||||
|
}
|
||||||
|
|
||||||
|
async function whatsappMessage(numb , inputMessage){
|
||||||
if (node.waClient.clientType === "waWebClient"){
|
if (node.waClient.clientType === "waWebClient"){
|
||||||
try {
|
try {
|
||||||
numb = `${numb}@g.us`;
|
numb = webNubmerSeteing(numb);
|
||||||
|
if(typeof inputMessage === "object"){
|
||||||
|
// inputMessage = new Buttons(inputMessage.text, inputMessage.buttons, "text" ,inputMessage.footer)
|
||||||
|
let myBtn = new Buttons('Button body',[{body:'bt1'},{body:'bt2'},{body:'bt3'}],'title','footer');
|
||||||
|
console.log(myBtn)
|
||||||
|
node.waClient.sendMessage(numb, inputMessage);
|
||||||
|
inputMessage = myBtn
|
||||||
|
}
|
||||||
node.waClient.sendMessage(numb, inputMessage);
|
node.waClient.sendMessage(numb, inputMessage);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e){
|
||||||
node.log(`Error Sending Msg: ${e}`);
|
node.error(`Error Sending Msg: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.waClient.clientType === "waSocketClient"){
|
else if (node.waClient.clientType === "waSocketClient"){
|
||||||
try {
|
try {
|
||||||
let client = await node.waClient;
|
let client = await node.waClient;
|
||||||
numb = `${numb}@g.us`;
|
numb = socNubmerSeteing(numb)
|
||||||
const msgStatus = await client.sendMessage(numb, {text : inputMessage});
|
if (typeof inputMessage ==="string"){
|
||||||
|
inputMessage = {text : inputMessage};
|
||||||
|
}
|
||||||
|
const msgStatus = await client.sendMessage(numb, inputMessage);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
node.log(`Error Sending Msg: ${e}`);
|
node.error(`Error Sending Msg: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.log(`Error Sending Msg: ${e}`)
|
node.error(`Error Sending Msg: ${e}`)
|
||||||
}
|
}
|
||||||
SetStatus("Message Send.", "green");
|
SetStatus("Message Send.", "green");
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
@ -42,20 +64,31 @@ module.exports = function(RED) {
|
|||||||
}, 2000)
|
}, 2000)
|
||||||
};
|
};
|
||||||
|
|
||||||
function whatsappMultiMediaMessage(numb, whatsappImage, whatsappCaption){
|
async function whatsappMultiMediaMessage(numb, whatsappImage, whatsappCaption){
|
||||||
|
var whatsappImageBase64 = whatsappImage.split(',')[1] || whatsappImage;
|
||||||
try {
|
try {
|
||||||
numb = node.number;
|
if (node.waClient.clientType === "waWebClient"){
|
||||||
whatsappImage = whatsappImage.split(',')[1] || whatsappImage;
|
numb = webNubmerSeteing(node.number)
|
||||||
var myMessage = new MessageMedia('image/png', whatsappImage, null, null);
|
var myMessage = new MessageMedia('image/png', whatsappImageBase64, null, null);
|
||||||
numb = typeof numb ==='number' ? numb : numb.replace(/\D/g, '');
|
node.waClient.sendMessage(numb, myMessage, {caption : whatsappCaption || "Image from Node-Red"});
|
||||||
numb = `${numb}@g.us`;
|
}
|
||||||
node.waClient.sendMessage(numb, myMessage, {caption : whatsappCaption || "Image from Node-Red"});
|
else {
|
||||||
|
numb = socNubmerSeteing(node.number)
|
||||||
|
const imageMessage = {
|
||||||
|
text: whatsappCaption,
|
||||||
|
footer: null,
|
||||||
|
templateButtons: null,
|
||||||
|
image: {url : whatsappImage }
|
||||||
|
};
|
||||||
|
let client = await node.waClient;
|
||||||
|
const msgStatus = await client.sendMessage(numb, imageMessage);
|
||||||
|
}
|
||||||
SetStatus("Message Send.", "green");
|
SetStatus("Message Send.", "green");
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
SetStatus('Connected','green');
|
SetStatus('Connected','green');
|
||||||
}, 2000)
|
}, 2000)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
node.log(`Error sending MultiMedia Message : ${e}`)
|
node.error(`Error sending MultiMedia Message : ${e}`)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,6 +121,8 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//whatsapp Status Parameters----
|
//whatsapp Status Parameters----
|
||||||
if (node.waClient.clientType === "waWebClient"){
|
if (node.waClient.clientType === "waWebClient"){
|
||||||
node.waClient.on('qr', (qr) => {
|
node.waClient.on('qr', (qr) => {
|
||||||
@ -127,7 +162,7 @@ module.exports = function(RED) {
|
|||||||
else if(connection === 'connecting'){
|
else if(connection === 'connecting'){
|
||||||
SetStatus("Connecting...", "yellow");
|
SetStatus("Connecting...", "yellow");
|
||||||
}
|
}
|
||||||
else if(updates.is){
|
else if(updates.qr){
|
||||||
SetStatus("Scan QR Code to Connect.", "yellow");
|
SetStatus("Scan QR Code to Connect.", "yellow");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -136,56 +171,6 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// node.on('input', (message)=> {
|
|
||||||
// if(node.gID){
|
|
||||||
// try {
|
|
||||||
// node.gID = node.gID.replace(/\D/g, '');
|
|
||||||
// node.gID = `${node.gID}@g.us`;
|
|
||||||
// node.waClient.sendMessage(node.gID, message.payload);
|
|
||||||
// SetStatus("Message Send.", "green");
|
|
||||||
// setTimeout(()=>{
|
|
||||||
// SetStatus('Connected','green');
|
|
||||||
// }, 3000)
|
|
||||||
// }
|
|
||||||
// catch(e) {
|
|
||||||
// node.log(`Error Sending Msg: ${e}`);
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// SetStatus("No Chat-ID","red");
|
|
||||||
// setTimeout(()=>{
|
|
||||||
// SetStatus('Connected','green');
|
|
||||||
// }, 5000)
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
|
|
||||||
//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("group-out", WhatsappGroupOut);
|
RED.nodes.registerType("group-out", WhatsappGroupOut);
|
||||||
}
|
}
|
||||||
|
|||||||
120
package-lock.json
generated
120
package-lock.json
generated
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-whatsapp-link",
|
"name": "node-red-contrib-whatsapp-link",
|
||||||
"version": "0.1.31",
|
"version": "0.1.32-A",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "node-red-contrib-whatsapp-link",
|
"name": "node-red-contrib-whatsapp-link",
|
||||||
"version": "0.1.31",
|
"version": "0.1.32-A",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adiwajshing/baileys": "^5.0.0",
|
"@adiwajshing/baileys": "latest",
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"whatsapp-web.js": "latest"
|
"whatsapp-web.js": "latest"
|
||||||
},
|
},
|
||||||
@ -140,9 +140,9 @@
|
|||||||
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA=="
|
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA=="
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "18.11.18",
|
"version": "18.13.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz",
|
||||||
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA=="
|
"integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg=="
|
||||||
},
|
},
|
||||||
"node_modules/@types/yauzl": {
|
"node_modules/@types/yauzl": {
|
||||||
"version": "2.10.0",
|
"version": "2.10.0",
|
||||||
@ -476,9 +476,9 @@
|
|||||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
||||||
},
|
},
|
||||||
"node_modules/content-type": {
|
"node_modules/content-type": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
||||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
|
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
@ -1093,9 +1093,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/minimist": {
|
"node_modules/minimist": {
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||||
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
@ -1156,9 +1156,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/node-fetch": {
|
"node_modules/node-fetch": {
|
||||||
"version": "2.6.8",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.8.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz",
|
||||||
"integrity": "sha512-RZ6dBYuj8dRSfxpUSu+NsdF1dpPpluJxwOp+6IoDp/sH2QNDSvurYsAa+F1WxY2RjA1iP93xhcsUoYbF2XBqVg==",
|
"integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
},
|
},
|
||||||
@ -1403,6 +1403,26 @@
|
|||||||
"node": ">=10.18.1"
|
"node": ">=10.18.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/puppeteer/node_modules/ws": {
|
||||||
|
"version": "8.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
||||||
|
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"bufferutil": "^4.0.1",
|
||||||
|
"utf-8-validate": "^5.0.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"bufferutil": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"utf-8-validate": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/qrcode": {
|
"node_modules/qrcode": {
|
||||||
"version": "1.5.1",
|
"version": "1.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.1.tgz",
|
||||||
@ -1472,9 +1492,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/readdir-glob/node_modules/minimatch": {
|
"node_modules/readdir-glob/node_modules/minimatch": {
|
||||||
"version": "5.1.4",
|
"version": "5.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
|
||||||
"integrity": "sha512-U0iNYXt9wALljzfnGkhFSy5sAC6/SCR3JrHrlsdJz4kF8MvhTRQNiC59iUi1iqsitV7abrNAJWElVL9pdnoUgw==",
|
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"brace-expansion": "^2.0.1"
|
"brace-expansion": "^2.0.1"
|
||||||
@ -1771,9 +1791,9 @@
|
|||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
||||||
},
|
},
|
||||||
"node_modules/whatsapp-web.js": {
|
"node_modules/whatsapp-web.js": {
|
||||||
"version": "1.19.2",
|
"version": "1.19.3",
|
||||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.19.2.tgz",
|
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.19.3.tgz",
|
||||||
"integrity": "sha512-ibEKy0KJsmH1rH9DKXfWk9vCnP/Dw/nZF9Ax3M7LCYtumSC+fiXMRF3BMVu7E75NRdv1pzjw4v05/Oq9aYY6aA==",
|
"integrity": "sha512-+qPLVpSjyGMHS68znIXHAX6XhaAEh3MYmsrzzT8d+XDGy/Bw2g4z1VqiLBJbceiGT4zvKwJD7XKKFokV+ozh+Q==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pedroslopez/moduleraid": "^5.0.2",
|
"@pedroslopez/moduleraid": "^5.0.2",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
@ -1836,15 +1856,15 @@
|
|||||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
||||||
},
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.5.0",
|
"version": "8.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.12.0.tgz",
|
||||||
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
"integrity": "sha512-kU62emKIdKVeEIOIKVegvqpXMSTAMLJozpHZaJNDYqBjzlSYXQGviYwN1osDLJ9av68qHd4a2oSjd7yD4pacig==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"bufferutil": "^4.0.1",
|
"bufferutil": "^4.0.1",
|
||||||
"utf-8-validate": "^5.0.2"
|
"utf-8-validate": ">=5.0.2"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"bufferutil": {
|
"bufferutil": {
|
||||||
@ -2017,9 +2037,9 @@
|
|||||||
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA=="
|
"integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA=="
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "18.11.18",
|
"version": "18.13.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz",
|
||||||
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA=="
|
"integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg=="
|
||||||
},
|
},
|
||||||
"@types/yauzl": {
|
"@types/yauzl": {
|
||||||
"version": "2.10.0",
|
"version": "2.10.0",
|
||||||
@ -2276,9 +2296,9 @@
|
|||||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
||||||
},
|
},
|
||||||
"content-type": {
|
"content-type": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
||||||
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
|
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA=="
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
@ -2759,9 +2779,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||||
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"mkdirp": {
|
"mkdirp": {
|
||||||
@ -2806,9 +2826,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node-fetch": {
|
"node-fetch": {
|
||||||
"version": "2.6.8",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.8.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz",
|
||||||
"integrity": "sha512-RZ6dBYuj8dRSfxpUSu+NsdF1dpPpluJxwOp+6IoDp/sH2QNDSvurYsAa+F1WxY2RjA1iP93xhcsUoYbF2XBqVg==",
|
"integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
}
|
}
|
||||||
@ -2990,6 +3010,14 @@
|
|||||||
"tar-fs": "2.1.1",
|
"tar-fs": "2.1.1",
|
||||||
"unbzip2-stream": "1.4.3",
|
"unbzip2-stream": "1.4.3",
|
||||||
"ws": "8.5.0"
|
"ws": "8.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ws": {
|
||||||
|
"version": "8.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
||||||
|
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
||||||
|
"requires": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"qrcode": {
|
"qrcode": {
|
||||||
@ -3045,9 +3073,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimatch": {
|
"minimatch": {
|
||||||
"version": "5.1.4",
|
"version": "5.1.6",
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
|
||||||
"integrity": "sha512-U0iNYXt9wALljzfnGkhFSy5sAC6/SCR3JrHrlsdJz4kF8MvhTRQNiC59iUi1iqsitV7abrNAJWElVL9pdnoUgw==",
|
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^2.0.1"
|
"brace-expansion": "^2.0.1"
|
||||||
@ -3284,9 +3312,9 @@
|
|||||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
|
||||||
},
|
},
|
||||||
"whatsapp-web.js": {
|
"whatsapp-web.js": {
|
||||||
"version": "1.19.2",
|
"version": "1.19.3",
|
||||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.19.2.tgz",
|
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.19.3.tgz",
|
||||||
"integrity": "sha512-ibEKy0KJsmH1rH9DKXfWk9vCnP/Dw/nZF9Ax3M7LCYtumSC+fiXMRF3BMVu7E75NRdv1pzjw4v05/Oq9aYY6aA==",
|
"integrity": "sha512-+qPLVpSjyGMHS68znIXHAX6XhaAEh3MYmsrzzT8d+XDGy/Bw2g4z1VqiLBJbceiGT4zvKwJD7XKKFokV+ozh+Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pedroslopez/moduleraid": "^5.0.2",
|
"@pedroslopez/moduleraid": "^5.0.2",
|
||||||
"archiver": "^5.3.1",
|
"archiver": "^5.3.1",
|
||||||
@ -3338,9 +3366,9 @@
|
|||||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
||||||
},
|
},
|
||||||
"ws": {
|
"ws": {
|
||||||
"version": "8.5.0",
|
"version": "8.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.12.0.tgz",
|
||||||
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==",
|
"integrity": "sha512-kU62emKIdKVeEIOIKVegvqpXMSTAMLJozpHZaJNDYqBjzlSYXQGviYwN1osDLJ9av68qHd4a2oSjd7yD4pacig==",
|
||||||
"requires": {}
|
"requires": {}
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-whatsapp-link",
|
"name": "node-red-contrib-whatsapp-link",
|
||||||
"version": "0.1.32",
|
"version": "0.1.32-B",
|
||||||
"description": "Node to send and receive whatsapp messages in groups and chats. | No third party APIs",
|
"description": "Node to send and receive whatsapp messages in groups and chats. | No third party APIs",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -30,9 +30,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@adiwajshing/baileys": "latest",
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"whatsapp-web.js": "latest",
|
"whatsapp-web.js": "latest"
|
||||||
"@adiwajshing/baileys": "^5.0.0"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.0.0"
|
"node": ">=8.0.0"
|
||||||
|
|||||||
319
whatsappLink.js
319
whatsappLink.js
@ -1,21 +1,22 @@
|
|||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
const { Client, LocalAuth } = require('whatsapp-web.js');
|
|
||||||
const makeWASocket = require('@adiwajshing/baileys');
|
|
||||||
const { useMultiFileAuthState } = makeWASocket
|
|
||||||
const QRCode = require('qrcode');
|
const QRCode = require('qrcode');
|
||||||
const FS = require('node:fs')
|
const FS = require('node:fs')
|
||||||
const OS = require('os');
|
const OS = require('os');
|
||||||
const Path = require('path');
|
const Path = require('path');
|
||||||
|
let userDir = OS.homedir();
|
||||||
|
let whatsappLinkDir = Path.join(userDir, '.node-red', 'Whatsapp-Link');
|
||||||
|
let whatsappLinkDirSocket = Path.join(whatsappLinkDir, 'WA-Sockets');
|
||||||
|
// let whatsappLinkDirSocketLogs = Path.join(whatsappLinkDir, 'WA-Sockets-logs');
|
||||||
|
|
||||||
let userDir = OS.homedir();
|
function RemoteClientNode(n) {
|
||||||
let whatsappLinkDir = Path.join(userDir, '.node-red', 'Whatsapp-Link');
|
RED.nodes.createNode(this,n);
|
||||||
let whatsappLinkDirSocket = Path.join(whatsappLinkDir, 'WA-Sockets')
|
var WAnode = this;
|
||||||
function RemoteClientNode(n) {
|
var clientType = n.clientType;
|
||||||
RED.nodes.createNode(this,n);
|
var whatsappConnectionStatus;
|
||||||
var WAnode = this;
|
var client
|
||||||
var clientType = n.clientType;
|
|
||||||
var whatsappConnectionStatus;
|
if (clientType ==="waWebClient"){
|
||||||
var client
|
const { Client, LocalAuth } = require('whatsapp-web.js');
|
||||||
|
|
||||||
var WAConnect = function(){
|
var WAConnect = function(){
|
||||||
const webClient = new Client({
|
const webClient = new Client({
|
||||||
@ -37,171 +38,179 @@ module.exports = function(RED) {
|
|||||||
};
|
};
|
||||||
return webClient ;
|
return webClient ;
|
||||||
};
|
};
|
||||||
|
client = WAConnect();
|
||||||
|
WAnode.connectionSetupID = setInterval(connectionSetup, 10000);
|
||||||
|
|
||||||
if (clientType ==="waWebClient"){
|
function WAClose(){
|
||||||
client = WAConnect();
|
try {
|
||||||
WAnode.connectionSetupID = setInterval(connectionSetup, 10000);
|
client.destroy();
|
||||||
|
}
|
||||||
function WAClose(){
|
catch(e){
|
||||||
try {
|
WAnode.err(`Error : Too many instructions! Try again.`)
|
||||||
client.destroy();
|
|
||||||
}
|
|
||||||
catch(e){
|
|
||||||
WAnode.err(`Error : Too many instructions! Try again.`)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var WARestart = function(){
|
|
||||||
WAClose();
|
|
||||||
WAConnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connectionSetup(){
|
|
||||||
try {
|
|
||||||
whatsappConnectionStatus = await client.getState();
|
|
||||||
if(whatsappConnectionStatus === "CONNECTED"){
|
|
||||||
clearInterval(WAnode.connectionSetupID);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WAnode.log(`Status : Connecting to Whatsapp...`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(e){
|
|
||||||
WAnode.log(`Error : Waiting for Initializion...`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//QR-Code on Terminal and Ready Status.
|
|
||||||
client.on("qr", (qr)=>{
|
|
||||||
clearInterval(WAnode.connectionSetupID);
|
|
||||||
QRCode.toString(qr, {type : 'terminal', small:true }, function(err, QRTerminal){
|
|
||||||
WAnode.log(`To Connect, Scan the QR Code through your Whatsapp Mobile App.`)
|
|
||||||
console.log("");
|
|
||||||
console.log(QRTerminal);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
client.on("ready", ()=>{
|
|
||||||
WAnode.log(`Status : Whatsapp Connected`);
|
|
||||||
});
|
|
||||||
|
|
||||||
//Whatsapp-Link Test Features (For Status and Testing Only.)
|
|
||||||
client.on('message_create', async (msg)=> {
|
|
||||||
if (msg.body.startsWith('!nodered')){
|
|
||||||
let chat = await msg.getChat();
|
|
||||||
let contact = await msg.getContact();
|
|
||||||
if (chat.isGroup){
|
|
||||||
let msgReply =
|
|
||||||
`Hi From Node-Red.
|
|
||||||
------------------
|
|
||||||
Group Name : ${chat.name},
|
|
||||||
Group Id : ${chat.id.user},
|
|
||||||
Group Admin : ${chat.groupMetadata.owner.user},
|
|
||||||
Participants : ${chat.groupMetadata.size}`
|
|
||||||
msg.reply(msgReply);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let msgReply = `Hi @${contact.number} From Node-Red.`
|
|
||||||
chat.sendMessage(msgReply, {
|
|
||||||
mentions : [contact]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
client.WAConnect = WAConnect;
|
|
||||||
client.WARestart = WARestart;
|
|
||||||
client.WAClose = WAClose;
|
|
||||||
client.clientType = clientType;
|
|
||||||
WAnode.client = client;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (clientType === "waSocketClient"){
|
var WARestart = function(){
|
||||||
|
WAClose();
|
||||||
|
WAConnect();
|
||||||
|
}
|
||||||
|
|
||||||
async function connectSocketClient() {
|
async function connectionSetup(){
|
||||||
const { state, saveCreds } = await useMultiFileAuthState(whatsappLinkDirSocket);
|
try {
|
||||||
const socketClient = makeWASocket.default({
|
whatsappConnectionStatus = await client.getState();
|
||||||
printQRInTerminal: false,
|
if(whatsappConnectionStatus === "CONNECTED"){
|
||||||
auth : state
|
clearInterval(WAnode.connectionSetupID);
|
||||||
})
|
}
|
||||||
|
else {
|
||||||
|
WAnode.log(`Status : Connecting to Whatsapp...`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
WAnode.log(`Error : Waiting for Initializion...`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
socketClient.ev.on('creds.update', saveCreds)
|
//QR-Code on Terminal and Ready Status.
|
||||||
|
client.on("qr", (qr)=>{
|
||||||
|
clearInterval(WAnode.connectionSetupID);
|
||||||
|
QRCode.toString(qr, {type : 'terminal', small:true }, function(err, QRTerminal){
|
||||||
|
WAnode.log(`To Connect, Scan the QR Code through your Whatsapp Mobile App.`)
|
||||||
|
console.log("");
|
||||||
|
console.log(QRTerminal);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
client.on("ready", ()=>{
|
||||||
|
WAnode.log(`Status : Whatsapp Connected`);
|
||||||
|
});
|
||||||
|
|
||||||
socketClient.ev.on('connection.update', (update) => {
|
//Whatsapp-Link Test Features (For Status and Testing Only.)
|
||||||
const { connection, lastDisconnect } = update
|
client.on('message_create', async (msg)=> {
|
||||||
if (connection === 'close') {
|
msg.body = `${msg.body}`;
|
||||||
// reconnect if not logged out
|
if (msg.body.startsWith('!nodered')){
|
||||||
|
let chat = await msg.getChat();
|
||||||
|
let contact = await msg.getContact();
|
||||||
|
if (chat.isGroup){
|
||||||
|
let msgReply =
|
||||||
|
`Hi From Node-Red.
|
||||||
|
------------------
|
||||||
|
Group Name : ${chat.name},
|
||||||
|
Group Id : ${chat.id.user},
|
||||||
|
Group Admin : ${chat.groupMetadata.owner.user},
|
||||||
|
Participants : ${chat.groupMetadata.size}`
|
||||||
|
msg.reply(msgReply);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let msgReply = `Hi @${contact.number} From Node-Red.`
|
||||||
|
chat.sendMessage(msgReply, {
|
||||||
|
mentions : [contact]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
client.WAConnect = WAConnect;
|
||||||
|
client.WARestart = WARestart;
|
||||||
|
client.WAClose = WAClose;
|
||||||
|
client.clientType = clientType;
|
||||||
|
WAnode.client = client;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (clientType === "waSocketClient"){
|
||||||
|
const makeWASocket = require('@adiwajshing/baileys');
|
||||||
|
const { useMultiFileAuthState } = makeWASocket;
|
||||||
|
const pino = require('pino');
|
||||||
|
|
||||||
|
async function connectSocketClient() {
|
||||||
|
const { state, saveCreds } = await useMultiFileAuthState(whatsappLinkDirSocket);
|
||||||
|
// const loggerFile = pino.destination(whatsappLinkDirSocketLogs);
|
||||||
|
const socketClient = makeWASocket.default({
|
||||||
|
printQRInTerminal: false,
|
||||||
|
logger:pino({level: "fatal"}),
|
||||||
|
auth : state,
|
||||||
|
browser: ["Node-RED", "Chrome", "4.0.0"],
|
||||||
|
markOnlineOnConnect: true,
|
||||||
|
patchMessageBeforeSending: (message) => {
|
||||||
|
const requiresPatch = !!(
|
||||||
|
message.buttonsMessage || message.templateMessage || message.listMessage
|
||||||
|
);
|
||||||
|
if (requiresPatch) {
|
||||||
|
message = {
|
||||||
|
viewOnceMessage: {
|
||||||
|
message: {
|
||||||
|
messageContextInfo: {
|
||||||
|
deviceListMetadataVersion: 2,
|
||||||
|
deviceListMetadata: {},
|
||||||
|
},
|
||||||
|
...message,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
socketClient.ev.on('creds.update', saveCreds)
|
||||||
|
|
||||||
|
socketClient.ev.on('connection.update', (update) => {
|
||||||
|
const { connection, lastDisconnect } = update
|
||||||
|
if (connection === 'close') {
|
||||||
|
// reconnect if not logged out
|
||||||
|
|
||||||
|
if (
|
||||||
|
lastDisconnect &&
|
||||||
|
lastDisconnect.error &&
|
||||||
|
lastDisconnect.error.output &&
|
||||||
|
(lastDisconnect.error.output.statusCode === 410 ||
|
||||||
|
lastDisconnect.error.output.statusCode === 428 ||
|
||||||
|
lastDisconnect.error.output.statusCode === 515)
|
||||||
|
) {
|
||||||
|
connectSocketClient()
|
||||||
|
} else {
|
||||||
if (
|
if (
|
||||||
lastDisconnect &&
|
lastDisconnect &&
|
||||||
lastDisconnect.error &&
|
lastDisconnect.error &&
|
||||||
lastDisconnect.error.output &&
|
lastDisconnect.error.output &&
|
||||||
(lastDisconnect.error.output.statusCode === 410 ||
|
lastDisconnect.error.output.statusCode === 401
|
||||||
lastDisconnect.error.output.statusCode === 428 ||
|
|
||||||
lastDisconnect.error.output.statusCode === 515)
|
|
||||||
) {
|
) {
|
||||||
connectSocketClient()
|
connectSocketClient()
|
||||||
|
FS.rmSync(whatsappLinkDirSocket, {recursive : true, force: true})
|
||||||
} else {
|
} else {
|
||||||
if (
|
WAnode.log('Node Refressed')
|
||||||
lastDisconnect &&
|
|
||||||
lastDisconnect.error &&
|
|
||||||
lastDisconnect.error.output &&
|
|
||||||
lastDisconnect.error.output.statusCode === 401
|
|
||||||
) {
|
|
||||||
FS.rmSync(whatsappLinkDirSocket, {recursive : true, force: true})
|
|
||||||
connectSocketClient()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log('Error unexpected', update)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(update.qr){
|
}
|
||||||
QRCode.toDataURL(update.qr, function(err, url){
|
})
|
||||||
var qrImageWithID = {};
|
return socketClient
|
||||||
qrImageWithID.id = WAnode.id;
|
|
||||||
qrImageWithID.image = url;
|
|
||||||
RED.comms.publish("whatsappLinkQrCode", qrImageWithID);
|
|
||||||
});
|
|
||||||
|
|
||||||
QRCode.toString(update.qr, {type : 'terminal', small:true }, function(err, QRTerminal){
|
|
||||||
WAnode.log(`To Connect, Scan the QR Code through your Whatsapp Mobile App.`)
|
|
||||||
console.log("");
|
|
||||||
console.log(QRTerminal);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (connection === 'open') {
|
|
||||||
var qrImageWithID = {};
|
|
||||||
qrImageWithID.id = WAnode.id;
|
|
||||||
qrImageWithID.image = null;
|
|
||||||
RED.comms.publish("whatsappLinkQrCode", qrImageWithID);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return socketClient
|
|
||||||
};
|
|
||||||
client = connectSocketClient();
|
|
||||||
client.clientType = clientType;
|
|
||||||
WAnode.client = client
|
|
||||||
};
|
};
|
||||||
|
client = connectSocketClient();
|
||||||
|
client.clientType = clientType;
|
||||||
|
client.clientStartFunction = connectSocketClient;
|
||||||
|
WAnode.client = client
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.on('close', (removed, done)=>{
|
this.on('close', (removed, done)=>{
|
||||||
if(removed){
|
if(removed){
|
||||||
if(clientType === "waWebClient"){
|
if(clientType === "waWebClient"){
|
||||||
clearInterval(WAnode.connectionSetupID);
|
clearInterval(WAnode.connectionSetupID);
|
||||||
WAnode.client.WAClose();
|
WAnode.client.WAClose();
|
||||||
}
|
} else {
|
||||||
|
WAnode.client.end()
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if(clientType === "waWebClient"){
|
|
||||||
clearInterval(WAnode.connectionSetupID);
|
|
||||||
WAnode.client.WAClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
|
|
||||||
});
|
}
|
||||||
|
else {
|
||||||
|
if(clientType === "waWebClient"){
|
||||||
|
clearInterval(WAnode.connectionSetupID);
|
||||||
|
WAnode.client.WAClose();
|
||||||
|
} else { WAnode.client.end() }
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("whatsappLink",RemoteClientNode);
|
RED.nodes.registerType("whatsappLink",RemoteClientNode);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user