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))
.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
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
``` javascript
client.getStatus ("xyz@g.us") // leave empty to get your own
.then (json => console.log("download profile picture from: " + json.eurl))
client.getProfilePicture ("xyz@g.us") // leave empty to get your own
.then (([json, q]) => console.log("download profile picture from: " + json.eurl))
```
- To get someone's presence (if they're typing, online)
``` javascript
@@ -178,6 +178,11 @@
Of course, replace ``` xyz ``` with an actual ID. Also, append ``` @c.us ``` for individuals & ``` @g.us ``` for 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
``` javascript
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])
},
/**
* 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
* @return {Promise<[object, object]>}
*/
@@ -131,6 +131,14 @@ module.exports = {
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
* @param {string} title like, the title of the group

View File

@@ -1,7 +1,6 @@
const WebSocket = require('ws')
const Curve = require ('curve25519-js')
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
*/
@@ -221,13 +220,9 @@ module.exports = {
* @private
*/
generateKeysForAuth: function (ref) {
this.curveKeys = Curve.generateKeyPair( Utils.randomBytes(32) )
const publicKeyStr = Buffer.from(this.curveKeys.public).toString('base64')
let str = ref + "," + publicKeyStr + "," + this.authInfo.clientID
this.log("authenticating... Converting to QR: " + str)
QR.generate(str, {small: true})
this.curveKeys = Curve.generateKeyPair(Utils.randomBytes(32))
const phoneAuthInfo = [ref, Buffer.from(this.curveKeys.public).toString('base64'), this.authInfo.clientID]
this.onReadyForPhoneAuthentication (phoneAuthInfo)
return this.waitForMessage ("s1", [])
},
/**

View File

@@ -1,4 +1,5 @@
const BinaryCoding = require('./binary_coding/binary_encoder.js')
const QR = require('qrcode-terminal')
class WhatsAppWeb {
/**
@@ -27,7 +28,8 @@ class WhatsAppWeb {
image: "imageMessage",
video: "videoMessage",
sticker: "stickerMessage",
document: "documentMessage",
document: "documentMessage",
audio: "audioMessage",
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 */
this.logUnhandledMessages = false
/** @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.decoder = new BinaryCoding.Decoder()
@@ -144,7 +152,13 @@ class WhatsAppWeb {
encKey: this.authInfo.encKey.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) {
console.log ("[Baileys] " + text)
}
@@ -226,7 +240,7 @@ const query = require("./WhatsAppWeb.Query")
WhatsAppWeb.prototype.isOnWhatsApp = query.isOnWhatsApp
/** Check the presence of a given person (online, offline) */
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
/** Get the URL to download the profile picture of a person/group */
WhatsAppWeb.prototype.getProfilePicture = query.getProfilePicture
@@ -240,6 +254,8 @@ WhatsAppWeb.prototype.isPhoneConnected = query.isPhoneConnected
WhatsAppWeb.prototype.loadConversation = query.loadConversation
/** Load the entire friggin conversation with a group or person */
WhatsAppWeb.prototype.loadEntireConversation = query.loadEntireConversation
/** Get the metadata of the group */
WhatsAppWeb.prototype.groupMetadata = query.groupMetadata
/** Create a group */
WhatsAppWeb.prototype.groupCreate = query.groupCreate
/** Leave a group */
@@ -253,4 +269,5 @@ WhatsAppWeb.prototype.groupMakeAdmin = query.groupMakeAdmin
/** Get the invite code of the group */
WhatsAppWeb.prototype.groupInviteCode = query.groupInviteCode
module.exports = WhatsAppWeb

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

View File

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