mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
support for custom queries + presence update handler
This commit is contained in:
@@ -27,6 +27,9 @@ Baileys is super easy to use:
|
||||
``` javascript
|
||||
client.handlers.onError = (error) => { /* called when there was an error */ }
|
||||
```
|
||||
``` javascript
|
||||
client.handlers.presenceUpdated = (id, presence) => { /* called when you recieve an update on someone's presence */ }
|
||||
```
|
||||
``` javascript
|
||||
client.handlers.onDisconnect = () => { /* called when internet gets disconnected */ }
|
||||
```
|
||||
@@ -133,7 +136,7 @@ Baileys is super easy to use:
|
||||
}
|
||||
})
|
||||
```
|
||||
Of course, replace ``` [countrycode][some10digitnumber] ``` with an actual country code & number. ``` isOnWhatsApp ``` returns a promise.
|
||||
Of course, replace ``` [countrycode][some10digitnumber] ``` with an actual country code & number.
|
||||
|
||||
|
||||
Do check out & run [example.js](example/example.js) to see example usage of all these functions.
|
||||
|
||||
@@ -140,6 +140,11 @@ module.exports = function(WhatsAppWeb) {
|
||||
|
||||
}
|
||||
return
|
||||
case "Presence":
|
||||
if (this.handlers.presenceUpdated) {
|
||||
this.handlers.presenceUpdated(json[1].id, json[1].type)
|
||||
}
|
||||
return
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -155,6 +160,8 @@ module.exports = function(WhatsAppWeb) {
|
||||
q.callback(json.status == 200, q.queryJSON[2])
|
||||
} else if (q.queryJSON[1] === "mediaConn") {
|
||||
q.callback(json.media_conn)
|
||||
} else {
|
||||
q.callback(json)
|
||||
}
|
||||
delete this.queryCallbacks[messageTag]
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ module.exports = function(WhatsAppWeb) {
|
||||
]
|
||||
this.sendBinary(json, [10, 128])
|
||||
}
|
||||
// check the presence status of a given jid
|
||||
WhatsAppWeb.prototype.requestPresenceUpdate = function (jid) {
|
||||
this.query(["action","presence","subscribe",jid])
|
||||
}
|
||||
// send a text message to someone, optionally you can provide a quoted message & the timestamp for the message
|
||||
WhatsAppWeb.prototype.sendTextMessage = function (id, txt, quoted=null, timestamp=null) {
|
||||
let message
|
||||
|
||||
BIN
example/.DS_Store
vendored
BIN
example/.DS_Store
vendored
Binary file not shown.
@@ -19,6 +19,10 @@ client.handlers.onConnected = () => {
|
||||
Despite the convenience, be careful with this file
|
||||
*/
|
||||
}
|
||||
// called when someone's presence is updated
|
||||
client.handlers.presenceUpdated = (id, type) => {
|
||||
console.log("presence of " + id + " is " + type)
|
||||
}
|
||||
// called when you have a pending unread message or recieve a new message
|
||||
client.handlers.onUnreadMessage = (m) => {
|
||||
// console.log("recieved message: " + JSON.stringify(m)) // uncomment to see what the raw message looks like
|
||||
@@ -58,6 +62,7 @@ client.handlers.onUnreadMessage = (m) => {
|
||||
}
|
||||
}, 4*1000) // send after 4 seconds
|
||||
}
|
||||
|
||||
// called if an error occurs
|
||||
client.handlers.onError = (err) => console.log(err)
|
||||
client.handlers.onDisconnect = () => { /* internet got disconnected, save chats here or whatever; will reconnect automatically */ }
|
||||
|
||||
Reference in New Issue
Block a user