diff --git a/.gitignore b/.gitignore index b512c09..859cfb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +removed.rm \ No newline at end of file diff --git a/.npmignore b/.npmignore index b512c09..859cfb8 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +removed.rm \ No newline at end of file diff --git a/README.md b/README.md index 3e614d6..3e4aae8 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Admin Node generate QR Code just below the node for easy connection with whatsap MultiMedia Message: Requirments- | Input | Description | |--------|-------------| - | `msg.image` | Base64 (encoded image), [`image-tool`](https://flows.nodered.org/node/node-red-contrib-image-tools) node work fine| + | `msg.image` | Base64 (encoded image), [`image-tool`](https://flows.nodered.org/node/node-red-contrib-image-tools) node work fine for incoding base64| | `msg.payload` | Image Caption | | `msg.toNumber` | Reciver number (if number not provided in node) | @@ -86,65 +86,6 @@ 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. -## Button, List and TemplateButton -Supported in Whatsapp-Lite only, `TODO for Whatsapp-Web`. -A Complete Button-Bot example is avilable in Node examples. - -* Simple Button 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} - ] -} -``` -* TemplateButton combination of link button, Call button 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'}} - ] -} -``` -* List Message combination of link button, List button 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 buttons from the Node Examples. - `A-reply-to-All.json` example is avilable in examples to import. 5. **Reply Node** : In Beta mode. (Chats-out Node can be used instead of reply node) diff --git a/admin.js b/admin.js index 7a19a15..47d30be 100644 --- a/admin.js +++ b/admin.js @@ -126,16 +126,21 @@ module.exports = function(RED) { if(node.client.clientType === "waSocketClient"){ var client = null + + async function clientFromWhatsappLite(){ client = await node.client; client.ev.on('connection.update', (updates)=>{ - + function printQrCode(urlQr) { + var qrImageWithID = {}; + qrImageWithID.id = node.id; + qrImageWithID.image = urlQr; + RED.comms.publish("whatsappLinkQrCode", qrImageWithID); + } + if(updates.qr){ QRCode.toDataURL(updates.qr, function(err, url){ - var qrImageWithID = {}; - qrImageWithID.id = node.id; - qrImageWithID.image = url; - RED.comms.publish("whatsappLinkQrCode", qrImageWithID); + printQrCode(url); }); QRCode.toString(updates.qr, {type : 'terminal', small:true }, function(err, QRTerminal){ @@ -144,20 +149,16 @@ module.exports = function(RED) { 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 + //Setting conncetion status indication + var {connection} = updates if(connection === 'open'){ + printQrCode(null); SetStatus("Connected", "green"); } else if(updates.isOnline){ + printQrCode(null); SetStatus("Connected", "green"); } else if(connection === 'close'){ diff --git a/chats-out.js b/chats-out.js index f25c168..2092c1a 100644 --- a/chats-out.js +++ b/chats-out.js @@ -76,7 +76,6 @@ module.exports = function(RED) { async function whatsappMultiMediaMessage(numb, whatsappImage, whatsappCaption){ whatsappCaption = whatsappCaption || "Image from Node-Red"; var whatsappImageBase64 = whatsappImage.split(',')[1] || whatsappImage; - console.log(whatsappImageBase64) try { if (node.waClient.clientType === "waWebClient"){ numb = await webNubmerSeteing(numb) diff --git a/package.json b/package.json index 2871a29..2fd759f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-whatsapp-link", - "version": "0.1.39B", + "version": "0.1.39C", "description": "Node to send and receive whatsapp messages in groups and chats. | No third party APIs", "repository": { "type": "git", diff --git a/whatsappLink.js b/whatsappLink.js index 31571d0..305cb48 100644 --- a/whatsappLink.js +++ b/whatsappLink.js @@ -105,9 +105,6 @@ module.exports = function(RED) { pressenceUpdate(onlineStatus); }); - - - client.WAConnect = WAConnect; client.WARestart = WARestart; client.WAClose = WAClose; @@ -156,7 +153,14 @@ module.exports = function(RED) { const { connection, lastDisconnect } = update if (connection === 'close') { // reconnect if not logged out - + + // console.log(lastDisconnect, lastDisconnect?.error?.data?.content) + // if (lastDisconnect.error.output.statusCode === 401 || + // lastDisconnect.error.output.statusCode === 440){ + // console.log(`logged Out by User. StatusCode : ${lastDisconnect?.error?.output.statusCode}`) + // FS.rmSync(whatsappLinkDirSocket, {recursive : true, force: true}) + // } + // connectSocketClient(); if ( lastDisconnect && lastDisconnect.error && @@ -171,12 +175,13 @@ module.exports = function(RED) { lastDisconnect && lastDisconnect.error && lastDisconnect.error.output && - lastDisconnect.error.output.statusCode === 401 + lastDisconnect.error.output.statusCode === 401 && + lastDisconnect.error.output.statusCode === 440 ) { FS.rmSync(whatsappLinkDirSocket, {recursive : true, force: true}) connectSocketClient() } else { - WAnode.log("Error : " + lastDisconnect?.error) + WAnode.log(`ErrorCode: ${lastDisconnect?.error?.output.statusCode} | ${lastDisconnect?.error}`) } } }