WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.1k stars 1.07k forks source link

[BUG] contacts.upsert only happens on WhatsApp Business #522

Open renatoiub opened 7 months ago

renatoiub commented 7 months ago

I'm having trouble getting the contacts. When I scan the code with the event it happens but when I scan the code with normal WhatsApp it works. Could it be a bug?

kyraex commented 7 months ago

Show your code for more context

renatoiub commented 7 months ago

const { default: makeWASocket, DisconnectReason, isJidUser, isJidGroup, makeInMemoryStore, WAPresence, proto, delay, WAMessageUpdate, MessageOptions, useMultiFileAuthStat, WAMessage, BufferJSON, Contact, Chat, Chats, GroupMetadata, ConnectionState, UserFacingSocketConfig, useMultiFileAuthState, fetchLatestBaileysVersion

} = require('@whiskeysockets/baileys')

class WhatsAppInstance { socketConfig = {
defaultQueryTimeoutMs: undefined, printQRInTerminal: false, logger: pino({ level: config.log.level, })

     //markOnlineOnConnect:false
                    }

     async init(key) 
     {

         const ver = await fetchLatestBaileysVersion()

         let b = {
browser: {
platform: 'Chrome (Linux)',
browser: 'chrome',
version: '22.5.0',
        }
                } 

          const { state, saveCreds} = await useMultiFileAuthState('db/'+key)
          this.authState = { state, saveCreds}

    this.socketConfig.auth = this.authState.state        
    this.socketConfig.version = ver.version
    this.socketConfig.browser = Object.values(b.browser)
    this.instance.sock = makeWASocket(this.socketConfig)

    this.setHandler()
    return this

}

setHandler() {

    const sock = this.instance.sock

    sock?.ev.on('contacts.upsert', async (contacts) => {
    console.log(contacts)

     }

} When I use it the business works normally. When I use normal Whatsapp the event doesn't work

renatoiub commented 7 months ago

Every time I change a contact, in Business I receive the event and in the normal WhatsApp log I come across this:

{"level":30,"time":1701399588789,"pid":7056,"hostname":"PUBLICIDADE-01","name":"critical_unblock_low","error":"Error: error:1C800064:Provider routines::bad decrypt\n at Decipheriv.final (node:internal/crypto/cipher:193:29)\n at aesDecryptWithIV (C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Utils\crypto.js:114:51)\n at aesDecrypt (C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Utils\crypto.js:108:12)\n at decodeSyncdMutations (C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Utils\chat-utils.js:171:48)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async decodeSyncdSnapshot (C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Utils\chat-utils.js:274:37)\n at async C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Socket\chats.js:390:70\n at async Object.transaction (C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Utils\auth-utils.js:136:26)\n at async C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Socket\chats.js:334:9\n at async C:\WHATSAPP\whatsapp-api-nodejs\node_modules\@whiskeysockets\baileys\lib\Utils\event-buffer.js:105:36","msg":"failed to sync state from version"}

onurguven commented 7 months ago

maybe related to: #268

renatoiub commented 7 months ago

It appears to be a Whatsapp sync error with Baileys. When the device is syncing in the background, the bug happens. After the synchronization was complete, the new contacts arrived, but all the contacts that should appear at the event when scanning the qr_code did not appear. The ideal would be to have a function at Baileys to call contacts, just like there is for groups.

endriodev commented 5 months ago

I also have the same error, and I need to reconnect WhatsApp Business until Baileys can synchronize, about 11x to 15x