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.53k stars 3.7k forks source link

SendMessage not working and not throwing any error. #2348

Closed dvillegasGlobalis closed 11 months ago

dvillegasGlobalis commented 1 year ago

Is there an existing issue for this?

Describe the bug

I am trying to make a chatbot with automatic responses, sometimes the sendMessage is not working. There is no error but the message is not sending. If i execute in non-headless mode i see the red icon that says that there was an error.

image

as you can see in the image it was working and then start to show the error.

Expected behavior

Send a message after the user writes a specific word.

Steps to Reproduce the Bug or Issue

  1. Connect with qr with LocalAuth strategy.
  2. Some send a message.
  3. The bot should respond to the user
  4. The message is not sending.

Relevant Code

const { Client, LocalAuth, List } = require('whatsapp-web.js'); const qrcode = require('qrcode-terminal');

const client = new Client({ authStrategy: new LocalAuth(), puppeteer: { headless: false } });

const lastMessages = new Map();

client.on('qr', qr => { qrcode.generate(qr, { small: true }); });

client.on('ready', () => { console.log('Dispositivo conectado'); });

client.on('message', message => { //console.log('message: ', message); if(message.body.trim() === 'test_bot') { client.sendMessage(message.from, 'Some text'); } });

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Windows Phone: Android whatsapp-web.js: 1.21.0 WhatsApp Web: 2.2329.9 Node.js 18.16.0

Additional context

The problem appears from time to time.

guidopontet commented 1 year ago

Same here :hand:

Redskinsjo commented 1 year ago

same i guess, for me one message is sent then the code doesn't throws but stops running (the code after doesn't execute)

Redskinsjo commented 1 year ago

i am on 1.21 and same was occuring on 1.20

Redskinsjo commented 1 year ago

also, exiting process of the terminal doesn't close chrome browser because i am headless: false

tofers commented 1 year ago

Don't send buttons or lists.

They don't work and break the web. Upgrade your connection and everything will work.

dvillegasGlobalis commented 1 year ago

Don't send buttons or lists.

They don't work and break the web. Upgrade your connection and everything will work.

As you can see in the code the message is just plain text

Moraes2854 commented 1 year ago

Hi, did you solved it?

tarsomatos commented 1 year ago

Same here :hand:

nugrahawahyu commented 1 year ago

We're also facing the same issue

daveckw commented 1 year ago

I am facing the same issue. Sometimes the message is not sent out even though there is no error.

templar-ajay commented 1 year ago

same here, the sendMessage method returns success result but the message is not sent

matbks commented 1 year ago

Here it wont even "fake send". it just wont reply neither sendMessage, 0 errors also.

edit:

Solved my problem:

npm i github:pedroslopez/whatsapp-web.js#9a6466edbc4af5b5eeea060917c15f86b283f510

Redskinsjo commented 1 year ago

still have the error. did you solve it?

dvillegasGlobalis commented 1 year ago

still have the error. did you solve it?

Still have the error

Redskinsjo commented 1 year ago

found this answer in #2473

Redskinsjo commented 1 year ago

i resolved it by correcting my own code: in my cas the for loop was incorrectly set, and so it was releasing an infinite loop and preventing the code to be executed smoothly