diff --git a/.DS_Store b/.DS_Store index 6f99bef..be0f4a7 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/WhatsAppWeb.Query.js b/WhatsAppWeb.Query.js index 21b27a6..438b892 100644 --- a/WhatsAppWeb.Query.js +++ b/WhatsAppWeb.Query.js @@ -23,7 +23,7 @@ module.exports = { * @return {Promise<[object, object]>} */ getStatus: function (jid) { - jid = jid ?? this.userMetaData.id + jid = jid || this.userMetaData.id return this.query(["query","Status",jid]) }, /** @@ -32,7 +32,7 @@ module.exports = { * @return {Promise<[object, object]>} */ getProfilePicture: function (jid) { - jid = jid ?? this.userMetaData.id + jid = jid || this.userMetaData.id return this.query(["query","ProfilePicThumb",jid]) }, /** diff --git a/WhatsAppWeb.Recv.js b/WhatsAppWeb.Recv.js index e490a9b..7957fe9 100644 --- a/WhatsAppWeb.Recv.js +++ b/WhatsAppWeb.Recv.js @@ -73,12 +73,12 @@ module.exports = { let callbacks = this.callbacks["function:" + json[0]] var callbacks2 var callback - for (var key in json[1] ?? {}) { + for (var key in json[1] || {}) { callbacks2 = callbacks[key + ":" + json[1][key]] if (callbacks2) { break } } if (!callbacks2) { - for (var key in json[1] ?? {}) { + for (var key in json[1] || {}) { callbacks2 = callbacks[key] if (callbacks2) { break } } @@ -110,10 +110,15 @@ module.exports = { * @return {[string, string]} [type of notification, specific type of message] */ getNotificationType: function (message) { + const MessageStubTypes = { + 20: "addedToGroup", + 32: "leftGroup", + 39: "createdGroup" + } if (message.message) { return ["message", Object.keys(message.message)[0]] } else if (message.messageStubType) { - return [WhatsAppWeb.MessageStubTypes[message.messageStubType] , null] + return [MessageStubTypes[message.messageStubType] , null] } else { return ["unknown", null] } @@ -143,8 +148,8 @@ module.exports = { throw "parameters (" + parameters + ") must be a string or array" } const func = "function:" + parameters[0] - const key = parameters[1] ?? "" - const key2 = parameters[2] ?? "" + const key = parameters[1] || "" + const key2 = parameters[2] || "" if (!this.callbacks[func]) { this.callbacks[func] = {} } @@ -165,8 +170,8 @@ module.exports = { throw "parameters (" + parameters + ") must be a string or array" } const func = "function:" + parameters[0] - const key = parameters[1] ?? "" - const key2 = parameters[2] ?? "" + const key = parameters[1] || "" + const key2 = parameters[2] || "" if (this.callbacks[func] && this.callbacks[func][key] && this.callbacks[func][key][key2]) { delete this.callbacks[func][key][key2] return @@ -211,7 +216,7 @@ module.exports = { if (!type) { return Promise.reject("unknown message type") } - if (type === WhatsAppWeb.MessageType.extendedText || type === WhatsAppWeb.MessageType.text) { + if (type === "extendedTextMessage" || type === "conversation") { return Promise.reject("cannot decode text message") } diff --git a/WhatsAppWeb.Send.js b/WhatsAppWeb.Send.js index 15af6b9..43431ef 100644 --- a/WhatsAppWeb.Send.js +++ b/WhatsAppWeb.Send.js @@ -252,7 +252,7 @@ module.exports = { var buff = Utils.aesEncrypt(binary, this.authInfo.encKey) // encrypt it using AES and our encKey const sign = Utils.hmacSign(buff, this.authInfo.macKey) // sign the message using HMAC and our macKey - tag = tag ?? Utils.generateMessageTag() + tag = tag || Utils.generateMessageTag() buff = Buffer.concat([ Buffer.from(tag + ","), // generate & prefix the message tag Buffer.from(tags), // prefix some bytes that tell whatsapp what the message is about @@ -271,7 +271,7 @@ module.exports = { */ sendJSON: function (json, tag) { const str = JSON.stringify(json) - tag = tag ?? Utils.generateMessageTag() + tag = tag || Utils.generateMessageTag() this.send(tag + "," + str) return tag }, diff --git a/WhatsAppWeb.Session.js b/WhatsAppWeb.Session.js index fea856b..26e9b50 100644 --- a/WhatsAppWeb.Session.js +++ b/WhatsAppWeb.Session.js @@ -73,17 +73,21 @@ module.exports = { } else { return this.generateKeysForAuth(json.ref) } - case 401: // if the phone was unpaired - throw [json.status, "unpaired from phone", message] - case 429: // request to login was denied, don't know why it happens - throw [json.status, "request denied, try reconnecting", message] - case 304: // request to generate a new key for a QR code was denied - throw [json.status, "request for new key denied", message] default: - throw [json.status, "unknown error", message] + throw [json.status, "unknown error", json] } }) .then (([json, q]) => { + switch (json.status) { + case 401: // if the phone was unpaired + throw [json.status, "unpaired from phone", json] + case 429: // request to login was denied, don't know why it happens + throw [json.status, "request denied, try reconnecting", json] + case 304: // request to generate a new key for a QR code was denied + throw [json.status, "request for new key denied", json] + default: + break + } if (json[1] && json[1].challenge) { // if its a challenge request (we get it when logging in) return this.respondToChallenge(json[1].challenge) .then (([json, _]) => { diff --git a/example/example.js b/example/example.js index 7e10a94..7730b93 100644 --- a/example/example.js +++ b/example/example.js @@ -50,7 +50,7 @@ client.connect (authInfo, 30*1000) // connect or timeout in 30 seconds // decode, decrypt & save the media. // The extension to the is applied automatically based on the media type client.decodeMediaMessage(m.message, "media_in_" + m.key.id) - .then (meta => console.log(sender + " sent media, saved at: " + meta.fileName)) + .then (meta => console.log(sender + " sent media, saved at: " + meta.filename)) .catch (err => console.log("error in decoding message: " + err)) } // send a reply after 3 seconds diff --git a/media_in_3A09C94FDF36E9498BF5.jpeg b/media_in_3A09C94FDF36E9498BF5.jpeg new file mode 100644 index 0000000..2553db1 Binary files /dev/null and b/media_in_3A09C94FDF36E9498BF5.jpeg differ