pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.17k stars 3.62k forks source link

Delay in receiving incoming message #2381

Open jonylim opened 1 year ago

jonylim commented 1 year ago

Is there an existing issue for this?

Describe the bug

There is a frequent occurrence where the WhatsApp Web was late in receiving incoming messages. The incoming message can be delayed up to more than 1 hour and gradually shorten, but then it can gradually increase again. But outgoing messages were sent just fine. The screenshot of the WhatsApp Web also reflect the incoming delays. I have also compared the deployed instance with actually opening web.whatsapp.com from my browser directly. The messages were up-to-date in browser, but new messages did not immediately appear in the deployed instance. FYI, I use docker for deployment. Does anyone also experience this?

Expected behavior

Incoming messages should be received in real-time.

Steps to Reproduce the Bug or Issue

-

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Docker (node:lts-alpine3.14) whatsapp-web.js version: 1.21.0 WhatsApp Web veresion: 2.2332.15 Node.js Version: v16.15.1

Additional context

No response

shirser121 commented 1 year ago

Same here

thedeaddan commented 1 year ago

Here, too, the problem is not in the library, but in the fact that Whatsapp simply does not issue messages, and if you do not display it, then it is not on the website, and it will pop up as "Waiting for this message. It may take some time."

jonylim commented 1 year ago

Here, too, the problem is not in the library, but in the fact that Whatsapp simply does not issue messages, and if you do not display it, then it is not on the website, and it will pop up as "Waiting for this message. It may take some time."

This is a different case from "Waiting for this message". This is simply the message was delayed and received late, but not happening if scanned directly in WhatsApp Web.

shirser121 commented 9 months ago

Did someone find solution?

Sansekai commented 5 months ago

same problem, any solution?

MoudiZd commented 5 months ago

Try do not awaiting sendMessage, as awaiting sending messages may lead to similar behavior,

I know that stopping from awaiting sending messages may let you loose some feature of detecting delivery status, but actually we can give it a try to check if the current issue is solved using this workaround

Or if you want to keep awaiting you can return a promise that may resolve or reject after sometimes but in same time continue sending messages

Sansekai commented 5 months ago

Try do not awaiting sendMessage, as awaiting sending messages may lead to similar behavior,

I know that stopping from awaiting sending messages may let you loose some feature of detecting delivery status, but actually we can give it a try to check if the current issue is solved using this workaround

Or if you want to keep awaiting you can return a promise that may resolve or reject after sometimes but in same time continue sending messages

await message.reply("Hello"); to message.reply("Hello"); Right?

MoudiZd commented 5 months ago

Try do not awaiting sendMessage, as awaiting sending messages may lead to similar behavior, I know that stopping from awaiting sending messages may let you loose some feature of detecting delivery status, but actually we can give it a try to check if the current issue is solved using this workaround Or if you want to keep awaiting you can return a promise that may resolve or reject after sometimes but in same time continue sending messages

await message.reply("Hello"); to message.reply("Hello"); Right?

Yeah exactly, give it a try, we are in a weird place and we must try everything

Sansekai commented 5 months ago

Thanks, I'll try it

MoudiZd commented 5 months ago

In my case awaiting sending message occure a long delay, but where i remove await and return true instead of awaiting delivery message, i have skipped the delay

Sansekai commented 5 months ago

Screenshot_20240405_203422_WhatsAppBusiness I'm still experiencing delay after removing await

Sansekai commented 5 months ago

This is my code https://pastebin.com/8Bgzirr0

MoudiZd commented 5 months ago

This is my code https://pastebin.com/8Bgzirr0

I have taken a look to the code, and i think that even you are removing await from send message but you are awaiting to clear chats, and actually clearing chats take time specially if chats has too many conversations, so actually i can tell you to log current time between the start of sending messages and the finish of sending them, in this case you can detect if the issue exist in the working flow or it is in the usage of whatsapp functionality

SnzDev commented 5 months ago

Try to install chrome instead of chromium and add bin reference on Client like this:

this.client = new Client({ authStrategy: new LocalAuth(), puppeteer: { executablePath: "/usr/bin/google-chrome-stable", headless: true, args: [ "--no-sandbox", ] }}),