Bug fixes

This commit is contained in:
Adhiraj
2020-05-20 11:42:21 +05:30
parent ea5ca61e49
commit 42a3d12236
6 changed files with 46 additions and 19 deletions

View File

@@ -159,15 +159,15 @@
client.loadEntireConversation ("xyz@c.us", (message) => console.log("Loaded message with ID: " + message.key.id)) client.loadEntireConversation ("xyz@c.us", (message) => console.log("Loaded message with ID: " + message.key.id))
.then (() => console.log("queried all messages")) // promise resolves once all messages are retreived .then (() => console.log("queried all messages")) // promise resolves once all messages are retreived
``` ```
- To get the status of some person/group - To get the status of some person
``` javascript ``` javascript
client.getStatus ("xyz@c.us") // leave empty to get your own client.getStatus ("xyz@c.us") // leave empty to get your own
.then (json => console.log("status: " + json.status)) .then ((json, q) => console.log("status: " + json.status))
``` ```
- To get the display picture of some person/group - To get the display picture of some person/group
``` javascript ``` javascript
client.getStatus ("xyz@g.us") // leave empty to get your own client.getProfilePicture ("xyz@g.us") // leave empty to get your own
.then (json => console.log("download profile picture from: " + json.eurl)) .then (([json, q]) => console.log("download profile picture from: " + json.eurl))
``` ```
- To get someone's presence (if they're typing, online) - To get someone's presence (if they're typing, online)
``` javascript ``` javascript
@@ -178,6 +178,11 @@
Of course, replace ``` xyz ``` with an actual ID. Also, append ``` @c.us ``` for individuals & ``` @g.us ``` for groups. Of course, replace ``` xyz ``` with an actual ID. Also, append ``` @c.us ``` for individuals & ``` @g.us ``` for groups.
* __Groups__ * __Groups__
- To query the metadata of a group
``` javascript
client.groupMetadata ("abcd-xyz@g.us")
.then (([json, _]) => console.log(json.id + ", title: " + json.subject + ", description: " + json.desc))
```
- To create a group - To create a group
``` javascript ``` javascript
client.groupCreate ("My Fab Group", ["abcd@s.whatsapp.net", "efgh@s.whatsapp.net"]) // title & participants client.groupCreate ("My Fab Group", ["abcd@s.whatsapp.net", "efgh@s.whatsapp.net"]) // title & participants

View File

@@ -18,7 +18,7 @@ module.exports = {
return this.query(["action","presence","subscribe",jid]) return this.query(["action","presence","subscribe",jid])
}, },
/** /**
* Query the status of the person * Query the status of the person (see groupMetadata() for groups)
* @param {string} [jid] the whatsapp ID of the person * @param {string} [jid] the whatsapp ID of the person
* @return {Promise<[object, object]>} * @return {Promise<[object, object]>}
*/ */
@@ -131,6 +131,14 @@ module.exports = {
return loadMessage() return loadMessage()
}, },
/**
* Get the metadata of the group
* @param {string} jid the ID of the group
* @return {Promise<[object, object]>}
*/
groupMetadata: function (jid) {
return this.query (["query", "GroupMetadata", jid])
},
/** /**
* Create a group * Create a group
* @param {string} title like, the title of the group * @param {string} title like, the title of the group

View File

@@ -1,7 +1,6 @@
const WebSocket = require('ws') const WebSocket = require('ws')
const Curve = require ('curve25519-js') const Curve = require ('curve25519-js')
const Utils = require('./WhatsAppWeb.Utils') const Utils = require('./WhatsAppWeb.Utils')
const QR = require('qrcode-terminal')
/* /*
Contains the code for connecting to WhatsApp Web, establishing a new session & logging back in Contains the code for connecting to WhatsApp Web, establishing a new session & logging back in
*/ */
@@ -221,13 +220,9 @@ module.exports = {
* @private * @private
*/ */
generateKeysForAuth: function (ref) { generateKeysForAuth: function (ref) {
this.curveKeys = Curve.generateKeyPair( Utils.randomBytes(32) ) this.curveKeys = Curve.generateKeyPair(Utils.randomBytes(32))
const publicKeyStr = Buffer.from(this.curveKeys.public).toString('base64') const phoneAuthInfo = [ref, Buffer.from(this.curveKeys.public).toString('base64'), this.authInfo.clientID]
let str = ref + "," + publicKeyStr + "," + this.authInfo.clientID this.onReadyForPhoneAuthentication (phoneAuthInfo)
this.log("authenticating... Converting to QR: " + str)
QR.generate(str, {small: true})
return this.waitForMessage ("s1", []) return this.waitForMessage ("s1", [])
}, },
/** /**

View File

@@ -1,4 +1,5 @@
const BinaryCoding = require('./binary_coding/binary_encoder.js') const BinaryCoding = require('./binary_coding/binary_encoder.js')
const QR = require('qrcode-terminal')
class WhatsAppWeb { class WhatsAppWeb {
/** /**
@@ -27,7 +28,8 @@ class WhatsAppWeb {
image: "imageMessage", image: "imageMessage",
video: "videoMessage", video: "videoMessage",
sticker: "stickerMessage", sticker: "stickerMessage",
document: "documentMessage", document: "documentMessage",
audio: "audioMessage",
extendedText: "extendedTextMessage" extendedText: "extendedTextMessage"
} }
/** /**
@@ -66,8 +68,14 @@ class WhatsAppWeb {
/** Log messages that are not handled, so you can debug & see what custom stuff you can implement */ /** Log messages that are not handled, so you can debug & see what custom stuff you can implement */
this.logUnhandledMessages = false this.logUnhandledMessages = false
/** @private */ /** @private */
this.callbacks = {} this.callbacks = {}
/**
* What to do when you need the phone to authenticate the connection (generate QR code by default)
*/
this.onReadyForPhoneAuthentication = this.generateQRCode
this.onRe
this.encoder = new BinaryCoding.Encoder() this.encoder = new BinaryCoding.Encoder()
this.decoder = new BinaryCoding.Decoder() this.decoder = new BinaryCoding.Decoder()
@@ -144,7 +152,13 @@ class WhatsAppWeb {
encKey: this.authInfo.encKey.toString('base64'), encKey: this.authInfo.encKey.toString('base64'),
macKey: this.authInfo.macKey.toString('base64') macKey: this.authInfo.macKey.toString('base64')
} }
} }
/** Generate a QR code from the ref & the curve public key. This is scanned by the phone */
generateQRCode ([ref, publicKey, clientID]) {
const str = ref + "," + publicKey + "," + clientID
QR.generate(str, {small: true})
}
log (text) { log (text) {
console.log ("[Baileys] " + text) console.log ("[Baileys] " + text)
} }
@@ -226,7 +240,7 @@ const query = require("./WhatsAppWeb.Query")
WhatsAppWeb.prototype.isOnWhatsApp = query.isOnWhatsApp WhatsAppWeb.prototype.isOnWhatsApp = query.isOnWhatsApp
/** Check the presence of a given person (online, offline) */ /** Check the presence of a given person (online, offline) */
WhatsAppWeb.prototype.requestPresenceUpdate = query.requestPresenceUpdate WhatsAppWeb.prototype.requestPresenceUpdate = query.requestPresenceUpdate
/** Query the status of the person */ /** Query the status of the person (see groupMetadata() for groups) */
WhatsAppWeb.prototype.getStatus = query.getStatus WhatsAppWeb.prototype.getStatus = query.getStatus
/** Get the URL to download the profile picture of a person/group */ /** Get the URL to download the profile picture of a person/group */
WhatsAppWeb.prototype.getProfilePicture = query.getProfilePicture WhatsAppWeb.prototype.getProfilePicture = query.getProfilePicture
@@ -240,6 +254,8 @@ WhatsAppWeb.prototype.isPhoneConnected = query.isPhoneConnected
WhatsAppWeb.prototype.loadConversation = query.loadConversation WhatsAppWeb.prototype.loadConversation = query.loadConversation
/** Load the entire friggin conversation with a group or person */ /** Load the entire friggin conversation with a group or person */
WhatsAppWeb.prototype.loadEntireConversation = query.loadEntireConversation WhatsAppWeb.prototype.loadEntireConversation = query.loadEntireConversation
/** Get the metadata of the group */
WhatsAppWeb.prototype.groupMetadata = query.groupMetadata
/** Create a group */ /** Create a group */
WhatsAppWeb.prototype.groupCreate = query.groupCreate WhatsAppWeb.prototype.groupCreate = query.groupCreate
/** Leave a group */ /** Leave a group */
@@ -253,4 +269,5 @@ WhatsAppWeb.prototype.groupMakeAdmin = query.groupMakeAdmin
/** Get the invite code of the group */ /** Get the invite code of the group */
WhatsAppWeb.prototype.groupInviteCode = query.groupInviteCode WhatsAppWeb.prototype.groupInviteCode = query.groupInviteCode
module.exports = WhatsAppWeb module.exports = WhatsAppWeb

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

View File

@@ -1,8 +1,10 @@
{ {
"name": "baileys", "name": "baileys",
"version": "1.0.0", "version": "1.0.2",
"description": "Whatsapp Web API", "description": "WhatsApp Web API",
"main": "WhatsAppWeb.js", "main": "WhatsAppWeb.js",
"homepage": "https://github.com/adiwajshing/Baileys",
"keywords": ["whatsapp", "js-whatsapp", "reverse engineer", "whatsapp api"],
"scripts": { "scripts": {
"test": "node test.js" "test": "node test.js"
}, },