diff --git a/README.md b/README.md
index 8b2e979..737be51 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,10 @@ Admin Node generate QR Code just below the node for easy connection with whatsap
4. **Group Message** : Whatsapp Group Node to send message in a Group.
The node will send recived `msg.payload` to a group chat.
+
+5. **Reply Node** : In Beta mode.
+
+Node will reply on each message starting with string mentioned in instruction or defaults `!red`.
## Issues & Updates
@@ -69,14 +73,12 @@ Issues and Suggestions are welcome [here.](https://github.com/raweee/node-red-co
* `Ver-0.1.21` : Group Message Node added.
* `Ver-0.1.23` : Nodes are formatted correctly and names are updated.
* `Ver-0.1.28` : Now QR Codes are directlly avilable in run time on Whatsapp-Admin-Node.
-* Working on Whatsapp Reply Node.
+* Working on Reply Node.
## Future Nodes
Currently working on more Whatsapp Node and will be avilable soon -
-
-1. Group Message Node.
-2. Chat Reply node.
-3. Instruction (smart) Reply Node.
+1. Chat Reply node. (working)
+2. Instruction (smart) Reply Node.
Complete detail for Nodes will also be updated as soon as possible.
diff --git a/admin.js b/admin.js
index dd25e42..c3e41c1 100644
--- a/admin.js
+++ b/admin.js
@@ -8,6 +8,7 @@ module.exports = function(RED) {
node.waClient = whatsappLinkNode.client;
node.WARestart = whatsappLinkNode.WARestart;
node.WAConnect = whatsappLinkNode.WAConnect;
+ node.destroy = whatsappLinkNode.WAClose;
function SetStatus(WAStatus, color){
node.status({fill:color,shape:"dot",text:WAStatus});
@@ -18,14 +19,14 @@ module.exports = function(RED) {
// Commands recived for Whatsapp Admin.
this.on('input', async function(msg, send){
if (msg.payload === "destroy") {
- await node.waClient.destroy();
+ node.destroy();
SetStatus("Disconnected","red");
}
else if (msg.payload==="logout") {
- await node.waClient.logout();
+ node.waClient.logout();
SetStatus("Logged Out","red");
}
- else if (msg.payload === "state"){
+ else if (msg.payload === "test"){
msg.payload = await node.waClient.getState();
node.send(msg);
}
diff --git a/package.json b/package.json
index 44a0ffc..4024b03 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-whatsapp-link",
- "version": "0.1.28A",
+ "version": "0.1.29",
"description": "Node to send and receive whatsapp chats and group messages. | No third party APIs",
"repository": {
"type": "git",
diff --git a/reply.html b/reply.html
index b1b0851..09a6f7c 100644
--- a/reply.html
+++ b/reply.html
@@ -4,8 +4,9 @@
color: '#25D366',
defaults: {
name: {value:"Reply"},
- instruction : {value : ""},
- whatsappLink: {value:"whatsapp-web", type:'whatsappLink'}
+ instruction : {value : "!red"},
+ whatsappLink: {value:"whatsapp-web", type:'whatsappLink'},
+ react : {value: `👍`}
},
inputs:1,
icon: 'whatsappLink.svg',
@@ -28,12 +29,20 @@
+
+
+
+
+
diff --git a/reply.js b/reply.js
index 0a7b27c..2ed6a5b 100644
--- a/reply.js
+++ b/reply.js
@@ -2,7 +2,8 @@ module.exports = function(RED) {
function WhatsappReply(config) {
RED.nodes.createNode(this,config);
var node = this;
- node.instruction = config.instruction ;
+ node.instruction = config.instruction;
+ node.react = config.react;
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
node.waClient = whatsappLinkNode.client;
let instructionPayload = null ;
@@ -20,9 +21,9 @@ module.exports = function(RED) {
if(instructionPayload) {
message.reply(instructionPayload)
}
- else {
- message.react('😅');
- message.reply('👍');
+ else if (node.react){
+ message.react(node.react);
+ // message.reply('👍');
};
}
});
diff --git a/whatsappLink.js b/whatsappLink.js
index 23d0c6e..dcdafaf 100644
--- a/whatsappLink.js
+++ b/whatsappLink.js
@@ -7,43 +7,43 @@ module.exports = function(RED) {
let userDir = OS.homedir();
let whatsappLinkDir = Path.join(userDir, '.node-red', 'Whatsapp-Link');
function RemoteClientNode(n) {
- RED.nodes.createNode(this,n);
- let WAnode = this;
- let whatsappConnectionStatus;
+ RED.nodes.createNode(this,n);
+ let WAnode = this;
+ let whatsappConnectionStatus;
- const client = new Client({
- authStrategy : new LocalAuth({
- dataPath : whatsappLinkDir
- }),
- puppeteer : {
- headless : true,
- args : ['--no-sandbox', '--disable-setuid-sandbox']
- }
- });
+ const client = new Client({
+ authStrategy : new LocalAuth({
+ dataPath : whatsappLinkDir
+ }),
+ puppeteer : {
+ headless : true,
+ args : ['--no-sandbox', '--disable-setuid-sandbox']
+ }
+ });
- let WAConnect = function(){
- try {
- client.initialize();
- WAnode.log("Status : Initializing Whatsapp..");
- }
- catch(e) {
- WAnode.log(`Error : Unable to start Whatsapp. Try Again..`);
- };
+ let WAConnect = function(){
+ try {
+ client.initialize();
+ WAnode.log("Status : Initializing Whatsapp..");
+ }
+ catch(e) {
+ WAnode.log(`Error : Unable to start Whatsapp. Try Again..`);
+ };
- //QR-Code on Terminal and Ready Status.
- client.on("qr", (qr)=>{
- clearInterval(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);
+ //QR-Code on Terminal and Ready Status.
+ client.on("qr", (qr)=>{
+ clearInterval(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`);
- });
- };
- WAConnect();
+ client.on("ready", ()=>{
+ WAnode.log(`Status : Whatsapp Connected`);
+ });
+ };
+ WAConnect();
//Whatsapp-Link Test Features (For Status and Testing Only.)
client.on('message_create', async (msg)=> {
@@ -74,6 +74,7 @@ Participants : ${chat.groupMetadata.size}`
function WAClose(){
try {
client.destroy();
+ WAnode.client.destroy();
}
catch(e){
WAnode.err(`Error : Too many instructions! Try again.`)
@@ -91,14 +92,14 @@ Participants : ${chat.groupMetadata.size}`
}
}
catch(e){
- WAnode.log(`Error : Connection is slow...`);
+ WAnode.log(`Error : Waiting for Initializion...`);
}
};
let connectionSetupID = setInterval(connectionSetup, 10000);
- let WARestart = async function(){
- await client.destroy();
- await client.initialize();
+ let WARestart = function(){
+ WAClose();
+ WAConnect();
}
this.on('close', (removed, done)=>{
@@ -118,6 +119,7 @@ Participants : ${chat.groupMetadata.size}`
this.WAConnect = WAConnect;
this.client = client;
this.WARestart = WARestart;
+ this.WAClose = WAClose;
this.whatsappConnectionStatus = whatsappConnectionStatus;
}
RED.nodes.registerType("whatsappLink",RemoteClientNode);