diff --git a/README.md b/README.md index b28b057..a024c71 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/WhatsAppWeb.Query.js b/WhatsAppWeb.Query.js index 438b892..850f5ff 100644 --- a/WhatsAppWeb.Query.js +++ b/WhatsAppWeb.Query.js @@ -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 diff --git a/WhatsAppWeb.Session.js b/WhatsAppWeb.Session.js index 26e9b50..02de394 100644 --- a/WhatsAppWeb.Session.js +++ b/WhatsAppWeb.Session.js @@ -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", []) }, /** diff --git a/WhatsAppWeb.js b/WhatsAppWeb.js index 91d6e94..d24bafa 100644 --- a/WhatsAppWeb.js +++ b/WhatsAppWeb.js @@ -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 \ No newline at end of file diff --git a/media_in_3A09C94FDF36E9498BF5.jpeg b/media_in_3A09C94FDF36E9498BF5.jpeg deleted file mode 100644 index 2553db1..0000000 Binary files a/media_in_3A09C94FDF36E9498BF5.jpeg and /dev/null differ diff --git a/package.json b/package.json index b5c2a1b..a8753ac 100644 --- a/package.json +++ b/package.json @@ -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" },