Chats-In Events Added

This commit is contained in:
rawee 2023-02-12 17:48:02 +05:30
parent 2823eb349d
commit d76ffd696a
7 changed files with 306 additions and 49 deletions

BIN
.github/messageScreenShot.jpeg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -61,6 +61,54 @@ Admin Node generate QR Code just below the node for easy connection with whatsap
| `msg.chatID` | Chat ID of Group chat / Personal chat |
| `msg.message` | Complete message object. <br />*Some extra details for advance users* |
Other Events options --
| waWebClient | Description |
|-------------|-------------|
| `message`
| `message_create`
| `auth_failure`
| `authenticated`
| `change_battery`
| `change_state`
| `disconnected`
| `group_join`
| `group_leave`
| `group_update`
| `incoming_call`
| `media_uploaded`
| `message_ack`
| `message_reaction`
| `message_revoke_everyone`
| `message_revoke_me`
| `qr`
| `ready`
| waSocketClient | Description |
|-------------|----------------|
| `messages.upsert`
| `connection.update`
| `creds.update`
| `messaging-history.set`
| `chats.upsert`
| `chats.update`
| `chats.delete`
| `presence.update`
| `contacts.upsert`
| `contacts.update`
| `messages.delete`
| `messages.update`
| `messages.media-update`
| `messages.reaction`
| `message-receipt.update`
| `groups.upsert`
| `groups.update`
| `group-participants.update`
| `blocklist.set`
| `blocklist.update`
| `call`
3. **Chats Out** : As simple as mention on name, node will send `msg.payload` recived at input to the number mentioned in node.
@ -138,7 +186,7 @@ msg.payload = {
```
Yes its lot require for buttons, A node will come soon to minimize these effors.
You may direct import these test button with bellow code.
You may direct import these test button with bellow code.
```json
[
@ -263,6 +311,9 @@ You may direct import these test button with bellow code.
}
]
```
### Screen Shots of Buttons and Image Messages.
![](.github/messageScreenShot.jpeg)
5. **Reply Node** : In Beta mode.
@ -280,6 +331,7 @@ Issues and Suggestions are welcome [here.](https://github.com/raweee/node-red-co
* `Ver-0.1.30` : Message can be send to an Array of contacts provided at `msg.toNumber`.
* `Ver-0.1.32` : Socket based `Whatsapp Lite` config node added in beta mode. Image message sending support added in chats-out node.
* `Ver-0.1.33` : Button and list support added, Minnor bugs fixed.
* `Ver-0.1.34` : Multiple Events reading options are added in Chats-In Node.
## Future Nodes
Currently working on more Whatsapp Node and will be avilable soon -

View File

@ -6,7 +6,6 @@ module.exports = function(RED) {
var node = this;
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
node.client = whatsappLinkNode.client;
// RED.comms.publish("whatsappLinkNodeID", node.id)
function SetStatus(WAStatus, color){
node.status({fill:color,shape:"dot",text:WAStatus});

View File

@ -1,17 +1,89 @@
<script type="text/javascript">
RED.nodes.registerType('chats-in',{
category: 'whatsapp',
color: '#25D366',
defaults: {
name: {value:"Chats In"},
whatsappLink: {value:"whatsapp-web", type:'whatsappLink'}
},
outputs:1,
icon: 'whatsappLink.svg',
label: function() {
return this.name||"Chats In";
(function () {
let socketEventOptions = [
{ value : 'messages.upsert', lable : 'messages.upsert'},
{ value : 'connection.update', lable : 'connection.update'},
{ value : 'creds.update', lable : 'creds.update'},
{ value : 'messaging-history.set', lable : 'messaging-history.set'},
{ value : 'chats.upsert', lable : 'chats.upsert'},
{ value : 'chats.update', lable : 'chats.update'},
{ value : 'chats.delete', lable : 'chats.delete'},
{ value : 'presence.update', lable : 'presence.update'},
{ value : 'contacts.upsert', lable : 'contacts.upsert'},
{ value : 'contacts.update', lable : 'contacts.update'},
{ value : 'messages.delete', lable : 'messages.delete'},
{ value : 'messages.update', lable : 'messages.update'},
{ value : 'messages.media-update', lable : 'messages.media-update'},
{ value : 'messages.reaction', lable : 'messages.reaction'},
{ value : 'message-receipt.update', lable : 'message-receipt.update',},
{ value : 'groups.upsert', lable : 'groups.upsert'},
{ value : 'groups.update', lable : 'groups.update'},
{ value : 'group-participants.update', lable : 'group-participants.update'},
{ value : 'blocklist.set', lable : 'blocklist.set'},
{ value : 'blocklist.update', lable : 'blocklist.update'},
{ value : 'call', lable : 'call'}
];
let webEventOpstions = [
{ value : 'message', label : 'message'},
{ value : 'message_create', label : 'message_create'},
{ value : 'auth_failure', label : 'auth_failure'},
{ value : 'authenticated', label : 'authenticated'},
{ value : 'change_battery', label : 'change_battery'},
{ value : 'change_state', label : 'change_state'},
{ value : 'disconnected', label : 'disconnected'},
{ value : 'group_join', label : 'group_join'},
{ value : 'group_leave', label : 'group_leave'},
{ value : 'group_update', label : 'group_update'},
{ value : 'incoming_call', label : 'incoming_call'},
{ value : 'media_uploaded', label : 'media_uploaded'},
{ value : 'message_ack', label : 'message_ack'},
{ value : 'message_reaction', label : 'message_reaction'},
{ value : 'message_revoke_everyone', label : 'message_revoke_everyone'},
{ value : 'message_revoke_me', label : 'message_revoke_me'},
{ value : 'qr', label : 'qr'},
{ value : 'ready', label : 'ready'}
];
function setMyInputLable(myLable) {
return { "value": myLable, "label": myLable }
}
});
RED.nodes.registerType('chats-in',{
category: 'whatsapp',
color: '#25D366',
defaults: {
name: {value:"Chats In"},
whatsappLink: {value:"whatsapp-web", type:'whatsappLink'},
whatsappLiteevent : {},
whatsappWebevent : {}
},
outputs:1,
icon: 'whatsappLink.svg',
label: function() {
return this.name||"Chats In";
},
oneditprepare: function(){
$("#node-input-whatsappWebevent").typedInput({
types: [
{
value: "Select Client Type",
multiple: "true",
options: webEventOpstions
}
]
});
$("#node-input-whatsappLiteevent").typedInput({
types: [
{
value: "Select Client Type",
multiple: "true",
options: socketEventOptions
}
]
})
}
});
})();
</script>
<script type="text/html" data-template-name="chats-in">
@ -23,8 +95,21 @@
<label for="node-input-whatsappLink"><i class="fa fa-gear"></i> Client</label>
<input type="text" id="node-input-whatsappLink" placeholder="Name">
</div>
<hr>
<div>
<label for="node-input-whatsappLiteevent" ><i class="fa fa-envelope"></i> Socket Event : <input type="text" id="node-input-whatsappLiteevent"></label>
</div>
<div class="form-tips">
<p>Node will recive all whatsapp (personal and group) messages.</p>
<p>waSocketClient only. Select <b>message.upsert</b> to recive all chats messages.
Multiple options are also avilable</p>
</div>
<hr>
<div>
<label for="node-input-whatsappWebevent" ><i class="fa fa-envelope"></i> Web Event : <input type="text" id="node-input-whatsappWebevent"></label>
</div>
<div class="form-tips">
<p>waWebClient only. Select <b>message</b> to recive all chats messages.
Multiple options are also avilable</p>
</div>
</script>
@ -41,4 +126,51 @@ Node to recive all messages send to connected number.
| `msg.chatID` | Chat ID of Group chat / Personal chat |
| `msg.message` | Complete message object. <br />*Some extra details for advance users* |
Other Events options --
| waWebClient | Description |
|-------------|-------------|
| `message`
| `message_create`
| `auth_failure`
| `authenticated`
| `change_battery`
| `change_state`
| `disconnected`
| `group_join`
| `group_leave`
| `group_update`
| `incoming_call`
| `media_uploaded`
| `message_ack`
| `message_reaction`
| `message_revoke_everyone`
| `message_revoke_me`
| `qr`
| `ready`
| waSocketClient | Description |
|-------------|----------------|
| `messages.upsert`
| `connection.update`
| `creds.update`
| `messaging-history.set`
| `chats.upsert`
| `chats.update`
| `chats.delete`
| `presence.update`
| `contacts.upsert`
| `contacts.update`
| `messages.delete`
| `messages.update`
| `messages.media-update`
| `messages.reaction`
| `message-receipt.update`
| `groups.upsert`
| `groups.update`
| `group-participants.update`
| `blocklist.set`
| `blocklist.update`
| `call`
</script>

View File

@ -4,21 +4,33 @@ module.exports = function(RED) {
var node = this;
var whatsappLinkNode = RED.nodes.getNode(config.whatsappLink);
node.waClient = whatsappLinkNode.client;
var whatsappLiteEvents = config.whatsappLiteevent;
var whatsappWebEvents = config.whatsappWebevent;
function SetStatus(WAStatus, color){
node.status({fill:color,shape:"dot",text:WAStatus});
};
if(node.waClient.clientType === "waWebClient"){
node.waClient.on('message', async message => {
let msg = {};
msg.payload = message.body;
msg.from = message.author || message.from ;
msg.chatID = message.from.replace(/\D/g, '');
msg.from = msg.from.replace(/\D/g, '');
msg.message = message ;
node.send(msg);
});
if(node.waClient.clientType === "waWebClient"){
whatsappWebEvents = whatsappWebEvents?.split(",") || whatsappWebEvents ;
whatsappWebEvents?.forEach((waEvent)=>{
if (waEvent ==='message'){
node.waClient.on(waEvent, async message => {
let msg = {};
msg.payload = message.body|| null;
msg.from = message.author || message.from ;
msg.chatID = message.from.replace(/\D/g, '');
msg.from = msg.from.replace(/\D/g, '');
msg.message = message ;
node.send(msg);
});
} else {
node.waClient.on(waEvent, async message => {
node.send(message);
});
};
})
//whatsapp Status Parameters----
node.waClient.on('qr', (qr) => {
@ -46,18 +58,28 @@ module.exports = function(RED) {
var client = null
async function clientFromWhatsappLite(){
client = await node.waClient;
client.ev.on('messages.upsert', msgs =>{
msgs.messages.forEach(async msg =>{
msg.payload = msg.message?.conversation;
msg.from = msg.key.participant || msg.key.remoteJid;
msg.from = msg.from.replace(/\D/g, '') || msg.from;
msg.chatID = msg.key.remoteJid.replace(/\D/g, '') || msg.key.remoteJid ;
node.send(msg)
})
});
whatsappLiteEvents = whatsappLiteEvents?.split(",") || whatsappLiteEvents;
whatsappLiteEvents?.forEach((waEvent)=>{
if (waEvent ==='messages.upsert'){
client.ev.on('messages.upsert', msgs =>{
msgs.messages.forEach(async msg =>{
msg.payload = msg.message?.conversation;
msg.from = msg.key.participant || msg.key.remoteJid;
msg.from = msg.from.replace(/\D/g, '') || msg.from;
msg.chatID = msg.key.remoteJid.replace(/\D/g, '') || msg.key.remoteJid ;
node.send(msg)
})
});
}
else {
client.ev.on(waEvent, msgs =>{
node.send(msgs)
});
};
})
//Setting conncetion status indication
client.ev.on('connection.update', (updates)=>{
var {connection} = updates
@ -80,14 +102,7 @@ module.exports = function(RED) {
}
clientFromWhatsappLite();
}
};
}
RED.nodes.registerType("chats-in", WhatsappIn);
}

View File

@ -54,5 +54,64 @@ MultiMedia Message Out: Requirments-
| `msg.payload` | Image Caption |
| `msg.toNumber` | Reciver number (if number not provided in node) |
## Button, List and TemplateButton
Supported in Whatsapp-Lite only, `TODO for Whatsapp-Web`.
* <b>Simple Button </b>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}
]
}
```
* <b>TemplateButton</b> combination of <b>link button</b>, <b>Call button</b> 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'}}
]
}
```
* <b>List Message</b> combination of <b>link button</b>, <b>List button</b> 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 button with bellow code.
-*Don't forget to mention international dialing code befor your number. Number must be in format like `+11 99999 99999` without any space.*
</script>

View File

@ -1,6 +1,6 @@
{
"name": "node-red-contrib-whatsapp-link",
"version": "0.1.32-B",
"version": "0.1.34",
"description": "Node to send and receive whatsapp messages in groups and chats. | No third party APIs",
"repository": {
"type": "git",
@ -31,8 +31,8 @@
},
"dependencies": {
"@adiwajshing/baileys": "latest",
"qrcode": "^1.5.1",
"whatsapp-web.js": "latest"
"whatsapp-web.js": "latest",
"qrcode": "^1.5.1"
},
"engines": {
"node": ">=8.0.0"