Group join and leave notification added
This commit is contained in:
parent
79331bbedc
commit
b0bb79845f
@ -33,6 +33,7 @@ Currently in developing mode, Continous updated may encounter. :sweat_smile:
|
||||
| Connecting..| When whatsapp attempting to connect.
|
||||
| QR Code (image) | when QR code is generated. *This method can also be used to get QR Code (image) generated by whatsapp.*
|
||||
| Connected | When whatapp is sucessfully connected.|
|
||||
| Group Joined or Removed | `msg.paylod` : Group Name. </br> `msg.type` : joined / Removed from group.</br> `msg.notification` : Complete notification. </br> `msg.chat` : Complete Group Details.
|
||||
|
||||
|
||||
2. **Whatsapp In** : Node to recive all messages send to connected number.
|
||||
@ -43,7 +44,7 @@ Currently in developing mode, Continous updated may encounter. :sweat_smile:
|
||||
- Please look complete `{msg}` to get all details about recived message.
|
||||
|
||||
|
||||
*Try to send `!nodered` to connected whatsapp number and get a `Hi` in reply from Node-Red.*
|
||||
*Try to send a message `!nodered` to connected whatsapp number and get a `Hi` in reply from Node-Red.*
|
||||
|
||||
3. **Whatsapp Out** : As simple as mention on name, node will send `msg.payload` recived at input to the number mentioned in node.
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "node-red-contrib-whatsapp-link",
|
||||
"version": "0.1.16",
|
||||
"version": "0.1.18",
|
||||
"description": "Whatsapp connection with Node-Red | No third party APIs",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
||||
@ -3,14 +3,19 @@ module.exports = function(RED) {
|
||||
RED.nodes.createNode(this,config);
|
||||
var node = this;
|
||||
node.number = config.number;
|
||||
node.number = node.number.match(/\d+/);
|
||||
node.number = node.number.replace(/\D/g, '');
|
||||
//node.number = this.number.includes('@c.us') ? this.number : `${this.number}@c.us`;
|
||||
node.number = `${node.number}@c.us`;
|
||||
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
|
||||
node.waClient = whatsappLinkNode.client;
|
||||
|
||||
node.on('input', (message)=> {
|
||||
node.waClient.sendMessage(this.number, message.payload);
|
||||
try {
|
||||
node.waClient.sendMessage(node.number, message.payload);
|
||||
}
|
||||
catch(e) {
|
||||
node.log(`Error Sending Msg: ${e}`);
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -36,15 +36,21 @@ module.exports = function(RED) {
|
||||
});
|
||||
|
||||
//Group Add/leave status-----
|
||||
node.waClient.on('group_join', (msg)=>{
|
||||
node.waClient.on('group_join', async (notification)=>{
|
||||
msg.chat = await notification.getChat();
|
||||
msg.payload = msg.chat.name;
|
||||
msg.type = notification.type;
|
||||
msg.notification = notification;
|
||||
node.send(msg);
|
||||
console.log(msg);
|
||||
msg.reply('!Node-Red joined');
|
||||
notification.reply('!Node-Red joined');
|
||||
});
|
||||
|
||||
node.waClient.on('group_leave', (msg)=>{
|
||||
node.waClient.on('group_leave', async (notification)=>{
|
||||
msg.chat = await notification.getChat();
|
||||
msg.payload = msg.chat.name;
|
||||
msg.type = notification.type;
|
||||
msg.notification = notification;
|
||||
node.send(msg);
|
||||
msg.reply('!Node-Red leave');
|
||||
});
|
||||
|
||||
node.waClient.on('group_update', (msg)=>{
|
||||
|
||||
@ -20,7 +20,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
catch(e) {
|
||||
WAnode.log(`Error : ${e}`);
|
||||
WARestart();
|
||||
WAnode.log(`Error : Unable to start Whatsapp. Try Again..`);
|
||||
};
|
||||
|
||||
client.on("qr", (qr)=>{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user