Reply Node Updated

This commit is contained in:
rawee 2023-01-13 01:46:52 +05:30
parent 33e40fd3ef
commit 02e63b7497
6 changed files with 69 additions and 54 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -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",

View File

@ -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 @@
<label for="node-input-instruction"><i class="fa fa-tag"></i> Instruction</label>
<input type="text" id="node-input-instruction" placeholder="instruction">
</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">
<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>
</script>
<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>

View File

@ -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('👍');
};
}
});

View File

@ -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);