WhiskeySockets / Baileys

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

Messages are not coming in upserts #115

Closed SamPandey001 closed 1 year ago

SamPandey001 commented 1 year ago

Hey there,it's been a long time,i didn't touch baileys in a long tho :P and now when i update baileys ^4.4.0 to WhiskeySockets/Baileys Userbot and i don't get messages in upserts but bot sends messages just after a successfull connection. Here is log.

Secktor Server listening on port http://localhost:8000!
0|secktor | ℹ️ Connecting to WhatsApp... Please Wait.
0|secktor | ✅ Login Successful!
0|secktor | ⬇️ Installing External Plugins...
0|secktor | ✅ External Plugins Installed!
0|secktor | Closing open session in favor of incoming prekey bundle
0|secktor | Closing session: SessionEntry {
0|secktor | _chains: {
0|secktor | 'BXgUxIWilzuTCZpb+vyiJgf7PDsLywmBoGv2rBjSchIn': { chainKey: [Object], chainType: 2, messageKeys: {} },
0|secktor | 'BTkrJoCwE7GRgDFpJ7fjqkfbYp+2f75enVXqU+EIfn1P': { chainKey: [Object], chainType: 1, messageKeys: {} }
0|secktor | },
0|secktor | registrationId: 230,
0|secktor | currentRatchet: {
0|secktor | ephemeralKeyPair: {
0|secktor | pubKey: <Buffer 05 39 2b 26 80 b0 13 b1 91 80 31 69 27 b7 e3 aa 47 db 62 9f b6 7f be 5e 9d 55 ea 53 e1 08 7e 7d 4f>,
0|secktor | privKey: <Buffer d0 c2 40 d0 62 42 b0 36 ba 67 7c bf 6a e9 00 cc 86 f1 b4 c6 58 03 be 02 1c f3 d9 98 bf 82 f0 58>
0|secktor | },
0|secktor | lastRemoteEphemeralKey: <Buffer 05 78 14 c4 85 a2 97 3b 93 09 9a 5b fa fc a2 26 07 fb 3c 3b 0b cb 09 81 a0 6b f6 ac 18 d2 72 12 27>,
0|secktor | previousCounter: 0,
0|secktor | rootKey: <Buffer bc 37 f8 8e 63 68 86 d9 64 c2 f5 c2 ef d6 f5 45 14 a5 7e 3f 5d 64 50 fa 89 3e 0d f1 14 35 36 87>
0|secktor | },
0|secktor | indexInfo: {
0|secktor | baseKey: <Buffer 05 0f bb fd bf c0 0b 53 3e c1 51 bd 5e 7a 10 32 0e 7c bb 8c e1 49 08 51 6c 7f 96 2c 6e f8 6d fd 66>,
0|secktor | baseKeyType: 2,
0|secktor | closed: -1,
0|secktor | used: 1686279748810,
0|secktor | created: 1686279748810,
0|secktor | remoteIdentityKey: <Buffer 05 b1 16 fb e6 cb 0c 67 16 55 80 a6 dd be 28 25 ce f8 15 70 6a b0 78 f5 21 dc 09 c6 d1 52 8b 87 23>
0|secktor | }
0|secktor | }

What can be a possible reason it? thanks btw

canove commented 1 year ago

try with npm i @whiskeysockets/baileys@6.1.0

AshishKumar9532 commented 1 year ago

try with npm i @whiskeysockets/baileys@6.1.0

huh,still same.

Miku21750 commented 1 year ago

yes, i also got this problem when migrating my previous baileys, adiwajshing to this baileys.

this is my function when receive message.upsert :

sock.ev.on('messages.upsert', async chatUpdate => {

    console.log('p')
    console.log(JSON.stringify(chatUpdate, undefined, 2))
    try {
    mek = chatUpdate.messages[0]
    if (!mek.message) return
    mek.message = (Object.keys(mek.message)[0] === 'ephemeralMessage') ? mek.message.ephemeralMessage.message : mek.message
    if (mek.key && mek.key.remoteJid === 'status@broadcast') return
    if (!sock.public && !mek.key.fromMe && chatUpdate.type === 'notify') return
    if (mek.key.id.startsWith('BAE5') && mek.key.id.length === 16) return
    m = smsg(sock, mek, store)
    require("./hisoka")(sock, m, chatUpdate, store)
    } catch (err) {

        console.log(err)
    }
}) `

i tested with console.log, but terminal didn't receive when new message sended to my phone

sorry for bad english

SamPandey001 commented 1 year ago

All other events are working fine,just messages aren't going there.🐥

morganzysman commented 1 year ago

Delete the async

Miku21750 commented 1 year ago

Delete the async

Still same though, i think that's not in async function

kbiits commented 1 year ago

@SamPandey001 use this for temporary workaround https://github.com/kbiits/Whiskey-Baileys

enoksaju commented 12 months ago

same here, not is triggering event messages.upsert, if i return to version 4.4 this is working fine, but this version not have latest functions

thereis commented 8 months ago

Still facing this issue in groups with temp messages aka expiry in 1 day.

fogolin commented 8 months ago

Seems like this is not closed, I face the same issue. As @SamPandey001 has pointed out, seems like quite a simple solution: https://github.com/WhiskeySockets/Baileys/compare/master...kbiits:Whiskey-Baileys:master

if(!authState.creds?.myAppStateKeyId && !config.mobile) {
    ev.buffer()
    needToFlushWithAppStateSync = true
    ev.flush() // <= Added this on the commit
}

Does this look like something that should be added here as well?

thereis commented 8 months ago

@fogolin I've forked the repository with the latest version and added the same code, I still have the same problems.

Closing stale open session for new outgoing prekey bundle
Closing session: SessionEntry

I don't know if this have anything related to the addTransactionCapability. Here's my socket:

const { state, saveCreds } = await createMultiFileAuthState(
        process.env.USER_DATA_DIR ?? '.session-data',
);

this.client = makeWASocket({
      version,
      printQRInTerminal: false,
      logger: this.logger.pino as any,
      auth: {
        creds: state.creds,
        keys: addTransactionCapability(state.keys, this.logger.pino as any, {
          maxCommitRetries: 10,
          delayBetweenTriesMs: 250,
        }),
      },
      syncFullHistory: false,
      generateHighQualityLinkPreview: true,
      defaultQueryTimeoutMs: 0,
      getMessage: this.getMessage,
      browser: ['Chrome (Linux)', '', ''],
      keepAliveIntervalMs: 10_000,
    });
fogolin commented 8 months ago

Ok. this is really a bummer, I'm having to make workarounds whenever dealing with messages and updates, upsert would really be an easier way to handle it, but I'll keep a lookout for this.

thereis commented 8 months ago

@fogolin I've managed to revert some changes here and now the issue is slightly better, I do receive those logs often but it's crashing when I am sending a text message to a group with lots of people.

thereis commented 8 months ago

Ok, I am facing a better performance by caching the group participants and sending them in the cachedGroupMetadata in the sendText method.

fogolin commented 6 months ago

I have an open issue on my repo related to edited messages and we'll look into it sometime next week, I'll keep you posted if I find anything.

kbiits commented 6 months ago

Seems like this is not closed, I face the same issue. As @SamPandey001 has pointed out, seems like quite a simple solution: https://github.com/WhiskeySockets/Baileys/compare/master...kbiits:Whiskey-Baileys:master

if(!authState.creds?.myAppStateKeyId && !config.mobile) {
    ev.buffer()
    needToFlushWithAppStateSync = true
    ev.flush() // <= Added this on the commit
}

Does this look like something that should be added here as well?

no, I think the buffer shouldn't flushed there. Of course, the new messages aren't emitted in the upsert event because of it, but my workaround implementation is just a workaround to make it works.

The buffer was already flushed somewhere (I forgot, will look back into it again), but in fact, it's still not flushed.

luispimenta commented 4 months ago

Ok, I am facing a better performance by caching the group participants and sending them in the cachedGroupMetadata in the sendText method.

@thereis Could you teach how you did this?