Reply Node Updated
This commit is contained in:
parent
33e40fd3ef
commit
02e63b7497
12
README.md
12
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.
|
4. **Group Message** : Whatsapp Group Node to send message in a Group.
|
||||||
|
|
||||||
The node will send recived `msg.payload` to a group chat.
|
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
|
## 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.21` : Group Message Node added.
|
||||||
* `Ver-0.1.23` : Nodes are formatted correctly and names are updated.
|
* `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.
|
* `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
|
## Future Nodes
|
||||||
Currently working on more Whatsapp Node and will be avilable soon -
|
Currently working on more Whatsapp Node and will be avilable soon -
|
||||||
|
1. Chat Reply node. (working)
|
||||||
1. Group Message Node.
|
2. Instruction (smart) Reply Node.
|
||||||
2. Chat Reply node.
|
|
||||||
3. Instruction (smart) Reply Node.
|
|
||||||
|
|
||||||
Complete detail for Nodes will also be updated as soon as possible.
|
Complete detail for Nodes will also be updated as soon as possible.
|
||||||
|
|
||||||
|
|||||||
7
admin.js
7
admin.js
@ -8,6 +8,7 @@ module.exports = function(RED) {
|
|||||||
node.waClient = whatsappLinkNode.client;
|
node.waClient = whatsappLinkNode.client;
|
||||||
node.WARestart = whatsappLinkNode.WARestart;
|
node.WARestart = whatsappLinkNode.WARestart;
|
||||||
node.WAConnect = whatsappLinkNode.WAConnect;
|
node.WAConnect = whatsappLinkNode.WAConnect;
|
||||||
|
node.destroy = whatsappLinkNode.WAClose;
|
||||||
|
|
||||||
function SetStatus(WAStatus, color){
|
function SetStatus(WAStatus, color){
|
||||||
node.status({fill:color,shape:"dot",text:WAStatus});
|
node.status({fill:color,shape:"dot",text:WAStatus});
|
||||||
@ -18,14 +19,14 @@ 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") {
|
||||||
await node.waClient.destroy();
|
node.destroy();
|
||||||
SetStatus("Disconnected","red");
|
SetStatus("Disconnected","red");
|
||||||
}
|
}
|
||||||
else if (msg.payload==="logout") {
|
else if (msg.payload==="logout") {
|
||||||
await node.waClient.logout();
|
node.waClient.logout();
|
||||||
SetStatus("Logged Out","red");
|
SetStatus("Logged Out","red");
|
||||||
}
|
}
|
||||||
else if (msg.payload === "state"){
|
else if (msg.payload === "test"){
|
||||||
msg.payload = await node.waClient.getState();
|
msg.payload = await node.waClient.getState();
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-whatsapp-link",
|
"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",
|
"description": "Node to send and receive whatsapp chats and group messages. | No third party APIs",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
17
reply.html
17
reply.html
@ -4,8 +4,9 @@
|
|||||||
color: '#25D366',
|
color: '#25D366',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:"Reply"},
|
name: {value:"Reply"},
|
||||||
instruction : {value : ""},
|
instruction : {value : "!red"},
|
||||||
whatsappLink: {value:"whatsapp-web", type:'whatsappLink'}
|
whatsappLink: {value:"whatsapp-web", type:'whatsappLink'},
|
||||||
|
react : {value: `👍`}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
icon: 'whatsappLink.svg',
|
icon: 'whatsappLink.svg',
|
||||||
@ -28,12 +29,20 @@
|
|||||||
<label for="node-input-instruction"><i class="fa fa-tag"></i> Instruction</label>
|
<label for="node-input-instruction"><i class="fa fa-tag"></i> Instruction</label>
|
||||||
<input type="text" id="node-input-instruction" placeholder="instruction">
|
<input type="text" id="node-input-instruction" placeholder="instruction">
|
||||||
</div>
|
</div>
|
||||||
|
<hr>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-react"><i class="fa fa-tag"></i> Reaction</label>
|
||||||
|
<input type="text" id="node-input-react" placeholder="reaction">
|
||||||
|
</div>
|
||||||
<div class="form-tips">
|
<div class="form-tips">
|
||||||
<p>Node to reply on message.</p>
|
<p> <b>In Beta mode</b></p>
|
||||||
|
<p>Node will reply on each message starting with string mentioned in instruction or defaults `!red`.</p>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<script type="text/markdown" data-help-name="reply">
|
<script type="text/markdown" data-help-name="reply">
|
||||||
Node to reply on meassage recived.
|
##In Beta mode
|
||||||
|
|
||||||
|
Node will reply on each message starting with string mentioned in instruction or defaults `!red`.
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
9
reply.js
9
reply.js
@ -2,7 +2,8 @@ module.exports = function(RED) {
|
|||||||
function WhatsappReply(config) {
|
function WhatsappReply(config) {
|
||||||
RED.nodes.createNode(this,config);
|
RED.nodes.createNode(this,config);
|
||||||
var node = this;
|
var node = this;
|
||||||
node.instruction = config.instruction ;
|
node.instruction = config.instruction;
|
||||||
|
node.react = config.react;
|
||||||
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
||||||
node.waClient = whatsappLinkNode.client;
|
node.waClient = whatsappLinkNode.client;
|
||||||
let instructionPayload = null ;
|
let instructionPayload = null ;
|
||||||
@ -20,9 +21,9 @@ module.exports = function(RED) {
|
|||||||
if(instructionPayload) {
|
if(instructionPayload) {
|
||||||
message.reply(instructionPayload)
|
message.reply(instructionPayload)
|
||||||
}
|
}
|
||||||
else {
|
else if (node.react){
|
||||||
message.react('😅');
|
message.react(node.react);
|
||||||
message.reply('👍');
|
// message.reply('👍');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,43 +7,43 @@ module.exports = function(RED) {
|
|||||||
let userDir = OS.homedir();
|
let userDir = OS.homedir();
|
||||||
let whatsappLinkDir = Path.join(userDir, '.node-red', 'Whatsapp-Link');
|
let whatsappLinkDir = Path.join(userDir, '.node-red', 'Whatsapp-Link');
|
||||||
function RemoteClientNode(n) {
|
function RemoteClientNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
let WAnode = this;
|
let WAnode = this;
|
||||||
let whatsappConnectionStatus;
|
let whatsappConnectionStatus;
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
authStrategy : new LocalAuth({
|
authStrategy : new LocalAuth({
|
||||||
dataPath : whatsappLinkDir
|
dataPath : whatsappLinkDir
|
||||||
}),
|
}),
|
||||||
puppeteer : {
|
puppeteer : {
|
||||||
headless : true,
|
headless : true,
|
||||||
args : ['--no-sandbox', '--disable-setuid-sandbox']
|
args : ['--no-sandbox', '--disable-setuid-sandbox']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let WAConnect = function(){
|
let WAConnect = function(){
|
||||||
try {
|
try {
|
||||||
client.initialize();
|
client.initialize();
|
||||||
WAnode.log("Status : Initializing Whatsapp..");
|
WAnode.log("Status : Initializing Whatsapp..");
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
WAnode.log(`Error : Unable to start Whatsapp. Try Again..`);
|
WAnode.log(`Error : Unable to start Whatsapp. Try Again..`);
|
||||||
};
|
};
|
||||||
|
|
||||||
//QR-Code on Terminal and Ready Status.
|
//QR-Code on Terminal and Ready Status.
|
||||||
client.on("qr", (qr)=>{
|
client.on("qr", (qr)=>{
|
||||||
clearInterval(connectionSetupID);
|
clearInterval(connectionSetupID);
|
||||||
QRCode.toString(qr, {type : 'terminal', small:true }, function(err, QRTerminal){
|
QRCode.toString(qr, {type : 'terminal', small:true }, function(err, QRTerminal){
|
||||||
WAnode.log(`To Connect, Scan the QR Code through your Whatsapp Mobile App.`)
|
WAnode.log(`To Connect, Scan the QR Code through your Whatsapp Mobile App.`)
|
||||||
console.log("");
|
console.log("");
|
||||||
console.log(QRTerminal);
|
console.log(QRTerminal);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
client.on("ready", ()=>{
|
||||||
client.on("ready", ()=>{
|
WAnode.log(`Status : Whatsapp Connected`);
|
||||||
WAnode.log(`Status : Whatsapp Connected`);
|
});
|
||||||
});
|
};
|
||||||
};
|
WAConnect();
|
||||||
WAConnect();
|
|
||||||
|
|
||||||
//Whatsapp-Link Test Features (For Status and Testing Only.)
|
//Whatsapp-Link Test Features (For Status and Testing Only.)
|
||||||
client.on('message_create', async (msg)=> {
|
client.on('message_create', async (msg)=> {
|
||||||
@ -74,6 +74,7 @@ Participants : ${chat.groupMetadata.size}`
|
|||||||
function WAClose(){
|
function WAClose(){
|
||||||
try {
|
try {
|
||||||
client.destroy();
|
client.destroy();
|
||||||
|
WAnode.client.destroy();
|
||||||
}
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
WAnode.err(`Error : Too many instructions! Try again.`)
|
WAnode.err(`Error : Too many instructions! Try again.`)
|
||||||
@ -91,14 +92,14 @@ Participants : ${chat.groupMetadata.size}`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
WAnode.log(`Error : Connection is slow...`);
|
WAnode.log(`Error : Waiting for Initializion...`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let connectionSetupID = setInterval(connectionSetup, 10000);
|
let connectionSetupID = setInterval(connectionSetup, 10000);
|
||||||
|
|
||||||
let WARestart = async function(){
|
let WARestart = function(){
|
||||||
await client.destroy();
|
WAClose();
|
||||||
await client.initialize();
|
WAConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on('close', (removed, done)=>{
|
this.on('close', (removed, done)=>{
|
||||||
@ -118,6 +119,7 @@ Participants : ${chat.groupMetadata.size}`
|
|||||||
this.WAConnect = WAConnect;
|
this.WAConnect = WAConnect;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.WARestart = WARestart;
|
this.WARestart = WARestart;
|
||||||
|
this.WAClose = WAClose;
|
||||||
this.whatsappConnectionStatus = whatsappConnectionStatus;
|
this.whatsappConnectionStatus = whatsappConnectionStatus;
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("whatsappLink",RemoteClientNode);
|
RED.nodes.registerType("whatsappLink",RemoteClientNode);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user