salman0ansari / whatsapp-api-nodejs

RESTful WhatsApp API with Multiple Device Support
GNU General Public License v3.0
1.27k stars 605 forks source link

one bug fixed about group message #793

Open xinkyo opened 11 months ago

xinkyo commented 11 months ago

when send group message, it takes 30 seconds to send, when I trace the code, the bug happend at mongoAuthState.js const writeData = (data, id) => {
this fucntion when data is array, it is not writen, need to change to object.

const writeData = (data, id) => { // console.log('write data array') // console.log(data) if (Array.isArray(data)) { const obj = {}; data.forEach((value, index) => { obj[index] = value; }); data = obj; }

    return collection.replaceOne(
        { _id: id },
        JSON.parse(JSON.stringify(data, BufferJSON.replacer)),
        { upsert: true }
    )
}

2nd part is : const BufferJSON = { replacer: (k, value) => {

here add type:buffer is not working, because it is changed to string before add type:buffer. don' know how to fix. in stead, in reviver ,I add the code to change base64 code to buffer.

else if ((k === 'seed' || k === 'public' || k === 'private') && typeof value === 'string') { // Convert the base64 string back to a Buffer return Buffer.from(value, 'base64'); }

@whiskeysockets/baileys/lib/Signal/libsignal.js here when loadSenderKey, the key should be array, but mongoAuthState send the object, temporaly I change to array here to array.

loadSenderKey: async (keyId) => {

        const { [keyId]: key } = await keys.get('sender-key', [keyId]);

        if (key) {
            if(typeof key==='object'){

            let testkey4 = convertObjectToArray(key)
           let    record=new WASignalGroup_1.SenderKeyRecord(testkey4)
           return record;
                }else{
                    let    record=new WASignalGroup_1.SenderKeyRecord(key)
                      return record;
                }

        }
    },

this is the full code i change in 2 file, it is just temporly work around, hope somebody could rewrite the mongoAuthState to save the key and read the key correctly in array and handle the buffer data correctly Downloads.zip

luanhduarte commented 11 months ago

Is it working? I added these two files in my code and it's not working!

Take a look in the API's answer:

{ "error": true, "code": 500, "message": "Error: NoSessionException" }