WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API

Home Page:https://baileys.whiskeysockets.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] `messages.upsert` is not triggering when a new message came? even my bot send

hacxk opened this issue · comments

commented

Title: [BUG] messages.upsert Event Not Triggering for Incoming Messages

I'm facing an issue where the crucial messages.upsert event is not firing consistently when new messages arrive in my WhatsApp bot. This is causing delays or even complete failures in my bot's ability to respond to user interactions.

Steps to Reproduce:

  1. Establish a new connection: The bot successfully connects to WhatsApp.
  2. Receive a message: A user or another contact sends a message to the bot.
  3. Event not triggered: The messages.upsert event handler is not called, or it is triggered with a significant delay.
  4. Consequence: My bot's logic to process and respond to the incoming message is not executed in a timely manner (or at all).

Expected Behavior:

When a new message is received by the bot, the messages.upsert event should fire immediately, providing the bot with the message data to process and respond accordingly.

Environment Details:

  • Server: No, the bot is running on a local computer(mine).
  • connectOptions:
      const sock = await makeWASocket({
              version: version,
              printQRInTerminal: pairingOption === 'QR CODE',
              mobile: false,
              shouldSyncHistoryMessage: false,
              syncFullHistory: false,
              downloadHistory: false,
              msgRetryCounterCache,
              logger: pino({ level: "silent" }),
              browser: ["Ubuntu", "Chrome", "20.0.04"],  // Else Put This   browser: ["Ubuntu", "Chrome", "20.0.04"], Don't Remove this commented
              auth: {
                  creds: state.creds,
                  /** caching makes the store faster to send/recv messages */
                  keys: makeCacheableSignalKeyStore(state.keys, logger),
              },
              linkPreviewImageThumbnailWidth: 1980,
              generateHighQualityLinkPreview: true,
              maxMsgRetryCount: 5,
              retryRequestDelayMs: 100,
              getMessage,
              patchMessageBeforeSending: async (msg, recipientJids) => {
                  for (const jid of recipientJids) {
                      const messageType = Object.keys(msg)[0];
                      // Optimize presence updates based on message type
                      if (messageType === 'audioMessage') {
                          await sock.sendPresenceUpdate('recording', jid);
                          const audioDuration = msg.audio.seconds || 5; // Estimate duration if not provided
                          await delay(audioDuration * 100); // Reduce delay time
                          await sock.sendPresenceUpdate('paused', jid);
                          await delay(100); // Reduce delay time
                      } else {
                          await sock.sendPresenceUpdate('composing', jid);
                          await delay(100); // Reduce delay time
                          await sock.sendPresenceUpdate('paused', jid);
                      }
                  }
                  return msg;
              }
          });
  • Multiple Clients: No, there are no other Baileys clients running on the same IP address.
  • Proxy: No, the bot is not using a proxy.
  • Paired Device & App Android :Whatsapp Business
commented

i fIxed This Issue

i fIxed This Issue

How you fixed it?

commented

by downgrading baileys to @6.7.4 and removing getMessage and Makeing sock to

 const sock = await makeWASocket({
            version: [2, 3000, 1014080102],
            printQRInTerminal: pairingOption === 'QR CODE',
            mobile: false,
            keepAliveIntervalMs: 10000,
            syncFullHistory: false,
            downloadHistory: false,
            markOnlineOnConnect: true,
            defaultQueryTimeoutMs: undefined,
            logger,
            Browsers: ['Hacxk-MD', 'Chrome', '113.0.5672.126'],
            auth: {
                creds: state.creds,
                keys: makeCacheableSignalKeyStore(state.keys, logger),
            },
            linkPreviewImageThumbnailWidth: 1980,
            generateHighQualityLinkPreview: true,
        });```
commented

i fIxed This Issue

How you fixed it?

also delete session and relogin with this sock connection still like that use a vpn and login