whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

Client.getState() returning with state connected but in reality it's not connected. Session Falling.

Open samuelfaj opened this issue 1 year ago • 10 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I have an interval function in my robot that checks the connection status every 10 seconds using the setInterval method. The code is as follows:

checkInterval = setInterval(async () => {
	const state = await Robot.client.getState();

	console.log('Status do Robô:', state)

	if(state != WAState.CONNECTED && state != WAState.OPENING && state != WAState.PAIRING){
		await Robot.fallDown('Status do Robô: ' + state);
	}
}, 10 * 1000);

The code appears to be working fine as it consistently shows that the robot is connected and able to send messages. However, I have noticed that sometimes the robot loses its connection with the WhatsApp server, which I can see from the lack of ACK responses. Even though the robot continues to display a connected status, it is actually disconnected and unable to really send or receive messages.

When this happens, I have to restart the robot, and It asks to scan the QR Code again to reestablish the connection. It seems that something happens to the session during these intermittent connection drops.

Expected behavior

It should keep the connection opened, or client.getState() should display the right state.

Steps to Reproduce the Bug or Issue

Just stay connected for a while

Relevant Code

No response

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Ubuntu 22.04 Node.js: 16.16 whatsapp-web.js: ^1.19.5 Phone: Android WhatsApp: 2.2314.7

Additional context

No response

samuelfaj avatar Apr 05 '23 18:04 samuelfaj

Same here

kikemarto avatar Apr 08 '23 21:04 kikemarto

I don't lose the session but if that happens to me what do you explain, any solution?

kikemarto avatar Apr 11 '23 21:04 kikemarto

Exact same thing here, also change_state neither disconnected events are never triggered. I saw that sometimes the change state event is triggered after hours of disconnection, but by checking the state changes they indicate a lost connection for only a couple of seconds, despite the connection to send messages or get messages info is not working, neither before or after those state_change events... The only thing that makes everything comes back to normal is to reset the whole application, and everytime that this happen I need to rescan the qr code again...

HiramNeto avatar Apr 28 '23 14:04 HiramNeto

any solution for this issue?

mbnaj avatar Oct 05 '23 00:10 mbnaj

@samuelfaj Is still relevant?

alechkos avatar Dec 04 '23 22:12 alechkos

This is happening to us too, is there any way to solve this?It's very important for us! Thanks!

juancruzsosagab avatar Dec 20 '23 16:12 juancruzsosagab

We are dealing with this issue as well!

FrancoAlfano avatar Dec 22 '23 16:12 FrancoAlfano

getstate is definitely broken

justoverclockl avatar Jan 14 '24 10:01 justoverclockl

Any solution here?

rbkayz avatar Mar 24 '24 09:03 rbkayz

Anywhere find any solution?

matheuspbmarques avatar Jun 16 '24 21:06 matheuspbmarques