-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WhatsApp Web.js - Messages Not Sending Properly #2554
Comments
Okay, so the problem is: Your Client should be global, or you can pass it down as a variable to the sendMessage function. That way, you won't have to instantiate it every time you enter the sendMessage function. Try to think it this way: So you need to pass the session down or make it global, and then you will be able to send messages properly. As a rule of thumb, you can only have the client created ONE TIME at your project, except for very specific use cases. |
"Thanks for your reply sir. Here I have a list of scheduled messages, each with a different sessionID. For example, message[0].sessionID = "2001," and message[1].sessionID = "2002." Each sessionID corresponds to a different WhatsApp account. In this situation, I kindly request your guidance on how to effectively resolve this issue. Your assistance would be greatly appreciated." |
I have made some changes to my code.
Api to create scheduled messages
After storing scheduled messages, the autoCheckScheduledMessages() function will retrieve and execute all messages for which the scheduled delivery times have already passed. autoCheckScheduledMessages() is called every minute.
This function invokes the sendMessage(message, client) function, which contains the following code:
In the sendMessage function, client.on("authenticated") and client.on("ready") events are not working. I got the console.logs here that
I was unable to resolve this issue. I hope someone can offer assistance. Thank you!
|
I have the same problem here, the messages are sent to the whatsapp but the interface of the application not is updated and the messages are not saved to the database. Yesterday on morning the application run normally, but without any changes, the behavior of not sent messages begin and I not find a solution for now |
You got most of it.
The events should be defined before the call of client.initialize().
Just checked and another problem you should me receiving at your console is something like: That problem is because you're returning a HTTP response at every "ready" event. |
Opa amigo! |
O meu problema aconteceu quando eu justamente agendei uma mensagem, antes de agendar uma mensagem tava funcionando normalmente vou tentar seguir sua solução e ver se dá certo |
Thank you, sir, your assistance has resolved my issue. I appreciate your help. |
Solved by @marcioscf |
Is there an existing issue for this?
Describe the bug
I am using the WhatsApp Web.js library to send scheduled messages via WhatsApp Web. The goal is to send messages at specified times, but I'm encountering an issue where the messages are not being sent as expected. Interestingly, when I restart the server, the messages are sent successfully.
Expected behavior
The issue at hand is that when the sendMessage function is called, the message is not sent as expected. However, upon restarting the server, the message is sent successfully. This suggests that there might be a session management or client initialization problem.
Steps to Reproduce the Bug or Issue
NA
Relevant Code
I'm using WhatsApp Web.js for sending scheduled messages, and I'm implementing LocalAuth for managing multiple sessions. In the provided API code, I'm saving scheduled messages to the database and managing client sessions on the server. However, when the sendMessages() function is called, the client isn't authenticated, doesn't listen for the 'ready' event, and fails to send messages. Interestingly, if I restart the server, the messages are sent successfully. I hope you can assist me in correctly sorting out this issue.
Browser Type
Google Chrome
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Additional context
No response
The text was updated successfully, but these errors were encountered: