Baileys
Baileys copied to clipboard
[BUG] contacts.upsert only happens on WhatsApp Business
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?
Show your code for more context
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
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"}
maybe related to: #268
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.
I also have the same error, and I need to reconnect WhatsApp Business until Baileys can synchronize, about 11x to 15x