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.6k stars 3.72k forks source link

Messages sent but never delivered to the contact #2654

Open stefanfuchs opened 12 months ago

stefanfuchs commented 12 months ago

Is there an existing issue for this?

Describe the bug

I'm having a weird issue: when the whatsapp-web.js client is online for some time, some messages that are sent are never actually delivered to the contact. They stay with one gray "tick" forever.

The most weird thing about this bug is that these messages appear on the mobile app with 1 gray tick as well, but never get delivered.

Sometimes clearing the whatsapp session works, but only for some time. It has to be done again and again.

This issue is happening consistently across multiple numbers, and i've been scratching my head a lot trying to figure out what's happening.

Expected behavior

The messages that are sent should be delivered to the contacts after some time.

Steps to Reproduce the Bug or Issue

  1. Start the whatsapp-web.js client, and use for some time (e.g. 1 or 2 hours).
  2. Send a message via the sendMessage method.
  3. Some contacts don't actually receive these messages, they stay with one gray "tick" forever. No delivered or read events are generated by the whatsapp client.

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Docker + Alpine 3.15 Phone OS: Android whatsapp-web.js version: 1.23.1 WhatsApp Web version [run await client.getWWebVersion()]: 2.2350.52 Node.js Version: 16.20.2-r0

Additional context

Related issues, which might ou might not be the same problem: https://github.com/pedroslopez/whatsapp-web.js/issues/2603 https://github.com/pedroslopez/whatsapp-web.js/issues/2554

daveckw commented 12 months ago

I am facing the same issue. Reconnect sometimes solved the issue but there is no indication when it has the issue

JoseFortunato commented 12 months ago

I am facing the same issue. When i reconnect it works for some time....

alechkos commented 12 months ago

There is no issues with sendMessage method in your context. More likely that the problem is in your code, maybe with handling asynchronous methods. Also you should keep the client active, e.g. by calling some library method approximately every 4 hours.

stefanfuchs commented 12 months ago

I've been using the lib for 3 years now, and only recently these kinds of problems started. I'ts most likely a bug in whatsapp itself, and the annoying part is that it happens randomly after using the lib normally for some time.

And yes, I'm using the lib very frequently to send messages - with multiple numbers - therefore it's not a problem of keeping the client active. In fact, the more messages are sent, the bigger the probability of this problem occuring.

JoseFortunato commented 12 months ago

I've been using the lib for 3 years now, and only recently these kinds of problems started. I'ts most likely a bug in whatsapp itself, and the annoying part is that it happens randomly after using the lib normally for some time.

And yes, I'm using the lib very frequently to send messages - with multiple numbers - therefore it's not a problem of keeping the client active. In fact, the more messages are sent, the bigger the probability of this problem occuring.

Same here...

stefanfuchs commented 12 months ago

And it's very strange because these messages even show up in the whatsapp app in the mobile phone... but they stay forever with one gray tick, never delivered. That's why it seems like a bug in whatsapp itself.

stefanfuchs commented 12 months ago

I am trying to update the chromium / puppeteer versions, because I saw the version used by the lib is more than 1 year old... and that might be the problem. Will have to try and see if it works.

daveckw commented 12 months ago

Yes. It has become more serious lately (more frequent).

JoseFortunato commented 11 months ago

Hi, someone solved the problem?

devluinix commented 11 months ago

Same problem for me, try doing a LOOP to restart the application every 1 hour. Always reconnecting the session like this, because apparently Whatsapp is putting the session in the span list

USING: client.resetState();

stefanfuchs commented 11 months ago

@devluinix when reseting the state like this, the qr code must be read again?

devluinix commented 11 months ago

@stefanfuchs no need read again.

My Client

path = 'mysession';

global.client = new Client({
      authStrategy: new LocalAuth({ clientId: path }),
      puppeteer: { 
         headless: true,
         args: ['--no-sandbox'],
      }
   });

Recomended too:

CODE

let delayVerify = 20000; //20s
   setInterval(() => {
         if (Math.random() < 0.8) {
            try { client.sendPresenceAvailable(); } catch (e) { console.log("Erro: sendPresenceAvailable"); } 
         } else {
            try { client.sendPresenceUnavailable(); } catch (e) { console.log("Erro: sendPresenceUnavailable"); }
         }
   }, delayVerify);

To simulate a human

alechkos commented 11 months ago

@stefanfuchs, @daveckw, @JoseFortunato

Is this helpful?

stefanfuchs commented 11 months ago

@alechkos it seems to be helping, I tested your solution for one day so far.

I'm using resetState() when at least 10 messages aren't delivered, without reseting the client. But when 15 messages are pending, I reset the whole app. resetState seems to be helping with the delivery of the messages.

Also, I'm using your code of sending the presence available/unavailable.

daveckw commented 11 months ago

Dear all, thank you for all the suggestions. I found out what the issue was on my side. My whatsapp web js is running on Google Cloud Server VM. The storage of the disk was utilised up till 90% most of the time and the issues above started happening. I upgraded the storage to 30GB (was 10GB before) and everything is working smoothly now. There are no more disconnection or unsent messages.

stefanfuchs commented 11 months ago

@daveckw interesting... I'm using amazon ECS here. I'll try to increase the disk space in the tasks, see if it helps.

JoseFortunato commented 11 months ago

Dear all, the same here. The storage of the disk was utilised up till 99% on aws EC2, i increased disk size and everything is working smoothly now.

creskopper commented 11 months ago

@daveckw Does this apply when working locally?

MUHESI commented 10 months ago

interestingly, the solution has been found, By the way I am also exploring this interesting library but I want to know: can they make a map of more than 1000 contacts who will receive messages? I've read WhatsApp's policy, which forbids sending mass messages. Can't this kind of use become a problem for WhatsApp?

@daveckw @stefanfuchs

daveckw commented 10 months ago

interestingly, the solution has been found, By the way I am also exploring this interesting library but I want to know: can they make a map of more than 1000 contacts who will receive messages? I've read WhatsApp's policy, which forbids sending mass messages. Can't this kind of use become a problem for WhatsApp?

@daveckw @stefanfuchs

Yes. You can. However bear in mind if large number of people report Spam, your number can be banned by whatsapp.

MUHESI commented 10 months ago

interestingly, the solution has been found, By the way I am also exploring this interesting library but I want to know: can they make a map of more than 1000 contacts who will receive messages? I've read WhatsApp's policy, which forbids sending mass messages. Can't this kind of use become a problem for WhatsApp? @daveckw @stefanfuchs

Yes. You can. However bear in mind if large number of people report Spam, your number can be banned by WhatsApp.

Okay, I see, thanks for your answer. can you share your LinkedIn or Twitter (X) username, Is it possible? we can continue to discuss there.

madhu441 commented 10 months ago

var client = new Client({ restartOnAuthFail: true, takeoverOnConflict: true, takeoverTimeoutMs: 0, puppeteer: { handleSIGINT: false, args: [ '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--no-first-run', '--no-zygote', '--disable-gpu' ], executablePath: chrome_path, }, authStrategy: new LocalAuth( { clientId: sender_id } ) } );
I am this client using on group send message response is success but not delivered why

RAKESHSUVIDYA commented 6 months ago

QR is not working properly in ubuntu platform. Is there anyone who can help

gustavobotti commented 5 months ago

@daveckw Does this apply when working locally?

Im having this same issue but Im working locally and I have space.

And unlike what you guys experienced, with me it happens from the first message, it doesn't need to be running for a while for the problem to occur.

@RAKESHSUVIDYA QR is not working properly in ubuntu platform. Is there anyone who can help

Im running this on ubuntu with no problems to generate QR

gregg-cbs commented 4 months ago

Honestly our support team is so sick of this issue - not to do with this package but the whatsapp api.

The webhooks dont return why the message was sent but not delivered, so all we know is that it was sent. This usually happens when a persons cell does not have data connection at the time of sending the message - in africa this is common! Some people turn their data off to save it.

Honestly you would think a multibillion dollar company could make this work properly.

Nivnivu commented 1 day ago

Problem still exist, i think whatsapp have limitation of messages sent directly throw the api to the same endpoint to prevent flooding.