waha icon indicating copy to clipboard operation
waha copied to clipboard

[BUG][WEBJS] - Messages not getting delivered occasionally

Open KKshitiz opened this issue 11 months ago • 2 comments

Describe the bug

Sometimes it happens the message request is sent and success response is received. I've also setup the webhooks so that my system marks the message as delivered. But, very rarely, the messages don't get actually delivered. It's a problem with multiple sessions. All the sessions are running on separate servers.

Has anyone faced similar issue? Can you help to debug it? @allburov

Since, it occurs rarely, I'm unable to reproduce this. Any help would be appreciated.

Version

{
  "version": "2025.2.1",
  "engine": "WEBJS",
  "tier": "PLUS"
}

patron:ADVANCED

KKshitiz avatar Feb 08 '25 05:02 KKshitiz

Hi! Yes, it could happen with some WEBJS (and other) engine. I believe only logout/scan qr will help in that case

What we're doing to handle such cases when using WAHA in our projects:

  1. Send message via API, save message id in database
  2. Listen message.ack - if the message doesn't send us SERVER or DEVICE|READ|PLAYED ack in N seconds (usually 60) - try resending it one more time
  3. Listen message.ack for 60 seconds for 2nd message (keep listening for the 1st message ack too)
  4. IF retry doesn't help - notify the client about probably failed session and ask to logout/scan qr code

You also can check message status by https://waha.devlike.pro/docs/how-to/receive-messages/#get-message-by-id as fallback, if no message.ack event send.

That approach prevent us from being blocked (we only send 2 messages, not like retry it until success) because sometimes even if we don't get message.ack - message got delivered.

We thought about building such queue in WAHA itself, but it'll require a bit more infrastructure (like redis or something to save the queue/background tasks) so it's not implemented yet, but we'll check that one more time a bit later!

patron:PRO

devlikepro avatar Feb 10 '25 03:02 devlikepro

Since, it occurs rarely

Yeah, the same, when it happens - no way to look inside the browser to debug why it happened and usually no useful logs :(

Make sure also to send the message one by one with some lock in your system - we don't have locks in WAHA for sending messages, so it's application responsibility to handle maintain "get a message - send seen - send typing - wait - send response - wait before starting processing new message" flow - if 2 messages come at the same time you MUST NOT "send response" and "typing" in to chats simultaneously. Usually it never happens, but it could be the issue (also thought about the solution built-in in WAHA, will get back to it a bit later too)

patron:PRO

devlikepro avatar Feb 10 '25 03:02 devlikepro