Rhymen / go-whatsapp

WhatsApp Web API
MIT License
2.08k stars 491 forks source link

How to maintain an active connection #361

Closed beshoo closed 4 years ago

beshoo commented 4 years ago

My API is working fine, but if

func (wh *WaHandler) HandleJsonMessage(message string) { } give you message "asleep" , the message handler will not be able to receive messages until sending 3 times

Base on https://github.com/Rhymen/go-whatsapp/issues/223#issuecomment-531088345 I test sending my self a message each time "asleep" appear. but it does not help. image handle will not catch anything!

The only confirmed working solution is to reconnect the session... But I have my concern reconnecting session on each "asleep"!

What do you think and what is the best way to maintain an active connection!

x00b commented 4 years ago

As you said reconnecting the session frequently i think is the way to go and not sure if there's any other way at all. But let's wait and see if anyone else have a suggestion..

beshoo commented 4 years ago

@x00b is there any risk of reconnecting the sessions? I mean i will preform this on each sleep....

x00b commented 4 years ago

Not sure but if you think that might be the way whatsapp web itself keeps an session online, since the library simulates it

beshoo commented 4 years ago

I turned it on, lets see when WhatsApp bann my number 🤣

beshoo commented 4 years ago

My problem is the following, when some one send a message to my number while it is a sleep, the handler did not receive the message.... Until the next up coming message....

I believe we are missing something here .... The reconnecting sessions thing .. Nah.... I think there is a missing part here.

I dont believe WhatsApp doing the reconnecting each 3 min.

What is in you mind my friend. @x00b

beshoo commented 4 years ago

Is it normal to get Sellp each 3 min? @x00b @Rhymen

time="2020-05-15T00:24:31Z" level=info msg="Process Que Recieved Signal PAUSE"
time="2020-05-15T00:25:05Z" level=info msg="The Session Reconnecting... "
time="2020-05-15T00:25:05Z" level=info msg="Handel session d19b4438-ae89-4491-923e-6f39eee8cb70"
time="2020-05-15T00:25:05Z" level=info msg="TimeOutFlag: 15 , TimeOut: 15s"
time="2020-05-15T00:25:07Z" level=info msg="14049190651@c.us Reconnected ... sessionId d19b4438-ae89-4491-923e-6f39eee8cb70"
time="2020-05-15T00:25:07Z" level=info msg="Process Que Recieved Signal RESUME"
time="2020-05-15T00:27:51Z" level=info msg="Process Que Recieved Signal PAUSE"
time="2020-05-15T00:28:25Z" level=info msg="The Session Reconnecting... "
time="2020-05-15T00:28:25Z" level=info msg="Handel session d19b4438-ae89-4491-923e-6f39eee8cb70"
time="2020-05-15T00:28:25Z" level=info msg="TimeOutFlag: 15 , TimeOut: 15s"
time="2020-05-15T00:28:26Z" level=info msg="14049190651@c.us Reconnected ... sessionId d19b4438-ae89-4491-923e-6f39eee8cb70"
time="2020-05-15T00:28:26Z" level=info msg="Process Que Recieved Signal RESUME"
beshoo commented 4 years ago

After monitoring the api beavers it seems the sleep last for 15 min, then the api will receive a resume signal.

If the api is sleeping, and someone send a text message, at first 5 min the api will wake up, but not if the message type is media.

After 5 min you need to receive more than 2 messages from your contacts to wake up the lib. Api will last 2~4 min in resume state.

Disconnect & Reconnecting the sessions I end up with a broken session, you have to hold the device and open WhatsApp to be able to reconnect your session.

Still struggling with this problem... Any ideas?

beshoo commented 4 years ago

New update This is json updated, i believe there is a problem with the handler of receive messages

My device was a sleep for 4 min, i sent an image to the device, the json handle triggered and here is the json

msg="[\"Conn\",{\"protoVersion\":[0,17],\"binVersion\":11,\"phone\":{\"wa_version\":\"2.20.157\",\"mcc\":\"417\",\"mnc\":\"001\",\"os_version\":\"10\",\"device_manufacturer\":\"samsung\",\"device_model\":\"a50\",\"os_build_number\":\"QP1A.190711.020.A505FDDS4BTD2\"},\"features\":{\"URL\":true,\"FLAGS\":\"EAEYASgBOAFAAUgBWAFgAWgBeAGYAQGgAQGwAQK4AQHIAQHYAQHoAQLwAQP4AQOIAgE=\"},\"pushname\":\"Mojeeb\"}]"

msg="[\"Props\",{\"camelotWeb\":false,\"preloadStickers\":false,\"webVoipInternalTester\":false,\"webCleanIncomingFilename\":1,\"webEnableModelStorage\":false,\"wsCanCacheRequests\":true,\"fbCrashlog\":true,\"bucket\":\"\",\"gifSearch\":\"giphy\",\"maxFileSize\":100,\"media\":64,\"maxSubject\":25,\"maxParticipants\":257,\"imageMaxKBytes\":1024,\"imageMaxEdge\":1600,\"statusVideoMaxDuration\":30,\"frequentlyForwardedMessages\":1,\"restrictGroups\":1,\"productCatalogOpenDeeplink\":1,\"multicastLimitGlobal\":5,\"finalLiveLocation\":1,\"frequentlyForwardedMax\":1,\"mmsMediaKeyTTL\":172800,\"stickers\":1,\"announceGroups\":1001,\"groupDescLength\":512,\"suspiciousLinks\":1,\"fwdUiStartTs\":1531267200}]"

But the handler of the photo receive dos not activated...

How can we solve this?

But if i send again, it activate..

Valdenirmezadri commented 3 years ago

New update This is json updated, i believe there is a problem with the handler of receive messages

My device was a sleep for 4 min, i sent an image to the device, the json handle triggered and here is the json

msg="[\"Conn\",{\"protoVersion\":[0,17],\"binVersion\":11,\"phone\":{\"wa_version\":\"2.20.157\",\"mcc\":\"417\",\"mnc\":\"001\",\"os_version\":\"10\",\"device_manufacturer\":\"samsung\",\"device_model\":\"a50\",\"os_build_number\":\"QP1A.190711.020.A505FDDS4BTD2\"},\"features\":{\"URL\":true,\"FLAGS\":\"EAEYASgBOAFAAUgBWAFgAWgBeAGYAQGgAQGwAQK4AQHIAQHYAQHoAQLwAQP4AQOIAgE=\"},\"pushname\":\"Mojeeb\"}]"

msg="[\"Props\",{\"camelotWeb\":false,\"preloadStickers\":false,\"webVoipInternalTester\":false,\"webCleanIncomingFilename\":1,\"webEnableModelStorage\":false,\"wsCanCacheRequests\":true,\"fbCrashlog\":true,\"bucket\":\"\",\"gifSearch\":\"giphy\",\"maxFileSize\":100,\"media\":64,\"maxSubject\":25,\"maxParticipants\":257,\"imageMaxKBytes\":1024,\"imageMaxEdge\":1600,\"statusVideoMaxDuration\":30,\"frequentlyForwardedMessages\":1,\"restrictGroups\":1,\"productCatalogOpenDeeplink\":1,\"multicastLimitGlobal\":5,\"finalLiveLocation\":1,\"frequentlyForwardedMax\":1,\"mmsMediaKeyTTL\":172800,\"stickers\":1,\"announceGroups\":1001,\"groupDescLength\":512,\"suspiciousLinks\":1,\"fwdUiStartTs\":1531267200}]"

But the handler of the photo receive dos not activated...

How can we solve this?

But if i send again, it activate..

Hello, how did you solve this problem

danielspk commented 3 years ago

Hello @beshoo , how did you solve this problem?

beshoo commented 3 years ago

@danielspk , good internet connection

danielspk commented 3 years ago

Thank @beshoo