mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Compatibility with older versions of Node + decodeMedia bug fix
This commit is contained in:
@@ -23,7 +23,7 @@ module.exports = {
|
|||||||
* @return {Promise<[object, object]>}
|
* @return {Promise<[object, object]>}
|
||||||
*/
|
*/
|
||||||
getStatus: function (jid) {
|
getStatus: function (jid) {
|
||||||
jid = jid ?? this.userMetaData.id
|
jid = jid || this.userMetaData.id
|
||||||
return this.query(["query","Status",jid])
|
return this.query(["query","Status",jid])
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +32,7 @@ module.exports = {
|
|||||||
* @return {Promise<[object, object]>}
|
* @return {Promise<[object, object]>}
|
||||||
*/
|
*/
|
||||||
getProfilePicture: function (jid) {
|
getProfilePicture: function (jid) {
|
||||||
jid = jid ?? this.userMetaData.id
|
jid = jid || this.userMetaData.id
|
||||||
return this.query(["query","ProfilePicThumb",jid])
|
return this.query(["query","ProfilePicThumb",jid])
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ module.exports = {
|
|||||||
let callbacks = this.callbacks["function:" + json[0]]
|
let callbacks = this.callbacks["function:" + json[0]]
|
||||||
var callbacks2
|
var callbacks2
|
||||||
var callback
|
var callback
|
||||||
for (var key in json[1] ?? {}) {
|
for (var key in json[1] || {}) {
|
||||||
callbacks2 = callbacks[key + ":" + json[1][key]]
|
callbacks2 = callbacks[key + ":" + json[1][key]]
|
||||||
if (callbacks2) { break }
|
if (callbacks2) { break }
|
||||||
}
|
}
|
||||||
if (!callbacks2) {
|
if (!callbacks2) {
|
||||||
for (var key in json[1] ?? {}) {
|
for (var key in json[1] || {}) {
|
||||||
callbacks2 = callbacks[key]
|
callbacks2 = callbacks[key]
|
||||||
if (callbacks2) { break }
|
if (callbacks2) { break }
|
||||||
}
|
}
|
||||||
@@ -110,10 +110,15 @@ module.exports = {
|
|||||||
* @return {[string, string]} [type of notification, specific type of message]
|
* @return {[string, string]} [type of notification, specific type of message]
|
||||||
*/
|
*/
|
||||||
getNotificationType: function (message) {
|
getNotificationType: function (message) {
|
||||||
|
const MessageStubTypes = {
|
||||||
|
20: "addedToGroup",
|
||||||
|
32: "leftGroup",
|
||||||
|
39: "createdGroup"
|
||||||
|
}
|
||||||
if (message.message) {
|
if (message.message) {
|
||||||
return ["message", Object.keys(message.message)[0]]
|
return ["message", Object.keys(message.message)[0]]
|
||||||
} else if (message.messageStubType) {
|
} else if (message.messageStubType) {
|
||||||
return [WhatsAppWeb.MessageStubTypes[message.messageStubType] , null]
|
return [MessageStubTypes[message.messageStubType] , null]
|
||||||
} else {
|
} else {
|
||||||
return ["unknown", null]
|
return ["unknown", null]
|
||||||
}
|
}
|
||||||
@@ -143,8 +148,8 @@ module.exports = {
|
|||||||
throw "parameters (" + parameters + ") must be a string or array"
|
throw "parameters (" + parameters + ") must be a string or array"
|
||||||
}
|
}
|
||||||
const func = "function:" + parameters[0]
|
const func = "function:" + parameters[0]
|
||||||
const key = parameters[1] ?? ""
|
const key = parameters[1] || ""
|
||||||
const key2 = parameters[2] ?? ""
|
const key2 = parameters[2] || ""
|
||||||
if (!this.callbacks[func]) {
|
if (!this.callbacks[func]) {
|
||||||
this.callbacks[func] = {}
|
this.callbacks[func] = {}
|
||||||
}
|
}
|
||||||
@@ -165,8 +170,8 @@ module.exports = {
|
|||||||
throw "parameters (" + parameters + ") must be a string or array"
|
throw "parameters (" + parameters + ") must be a string or array"
|
||||||
}
|
}
|
||||||
const func = "function:" + parameters[0]
|
const func = "function:" + parameters[0]
|
||||||
const key = parameters[1] ?? ""
|
const key = parameters[1] || ""
|
||||||
const key2 = parameters[2] ?? ""
|
const key2 = parameters[2] || ""
|
||||||
if (this.callbacks[func] && this.callbacks[func][key] && this.callbacks[func][key][key2]) {
|
if (this.callbacks[func] && this.callbacks[func][key] && this.callbacks[func][key][key2]) {
|
||||||
delete this.callbacks[func][key][key2]
|
delete this.callbacks[func][key][key2]
|
||||||
return
|
return
|
||||||
@@ -211,7 +216,7 @@ module.exports = {
|
|||||||
if (!type) {
|
if (!type) {
|
||||||
return Promise.reject("unknown message 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")
|
return Promise.reject("cannot decode text message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ module.exports = {
|
|||||||
|
|
||||||
var buff = Utils.aesEncrypt(binary, this.authInfo.encKey) // encrypt it using AES and our encKey
|
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
|
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([
|
buff = Buffer.concat([
|
||||||
Buffer.from(tag + ","), // generate & prefix the message tag
|
Buffer.from(tag + ","), // generate & prefix the message tag
|
||||||
Buffer.from(tags), // prefix some bytes that tell whatsapp what the message is about
|
Buffer.from(tags), // prefix some bytes that tell whatsapp what the message is about
|
||||||
@@ -271,7 +271,7 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
sendJSON: function (json, tag) {
|
sendJSON: function (json, tag) {
|
||||||
const str = JSON.stringify(json)
|
const str = JSON.stringify(json)
|
||||||
tag = tag ?? Utils.generateMessageTag()
|
tag = tag || Utils.generateMessageTag()
|
||||||
this.send(tag + "," + str)
|
this.send(tag + "," + str)
|
||||||
return tag
|
return tag
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -73,17 +73,21 @@ module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
return this.generateKeysForAuth(json.ref)
|
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:
|
default:
|
||||||
throw [json.status, "unknown error", message]
|
throw [json.status, "unknown error", json]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then (([json, q]) => {
|
.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)
|
if (json[1] && json[1].challenge) { // if its a challenge request (we get it when logging in)
|
||||||
return this.respondToChallenge(json[1].challenge)
|
return this.respondToChallenge(json[1].challenge)
|
||||||
.then (([json, _]) => {
|
.then (([json, _]) => {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ client.connect (authInfo, 30*1000) // connect or timeout in 30 seconds
|
|||||||
// decode, decrypt & save the media.
|
// decode, decrypt & save the media.
|
||||||
// The extension to the is applied automatically based on the media type
|
// The extension to the is applied automatically based on the media type
|
||||||
client.decodeMediaMessage(m.message, "media_in_" + m.key.id)
|
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))
|
.catch (err => console.log("error in decoding message: " + err))
|
||||||
}
|
}
|
||||||
// send a reply after 3 seconds
|
// send a reply after 3 seconds
|
||||||
|
|||||||
BIN
media_in_3A09C94FDF36E9498BF5.jpeg
Normal file
BIN
media_in_3A09C94FDF36E9498BF5.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
Reference in New Issue
Block a user