Rhymen / go-whatsapp

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

Problems with Official WhatsApp App after using this Library #278

Open x00b opened 4 years ago

x00b commented 4 years ago

Hi,

I've been having a weird problem. I created a software with this library and after couple weeks my Whatsapp app(the official android app) started to stop working sometimes; it send messages but doesnt show that it was received and it does not receive any message at all, its like the cellphone was offline and after some hours it just start working again.

ps: the software i created keep its whatsapp session online constantly or keep trying to restore it constantly too.

Does anyone had this problem or can help me figure out what may be the cause of it?

Tks

gabstv commented 4 years ago

I had the same problem. It seems to be related with a concurrency issue for me (by looking at the device logs) and not go-whatsapp related.

I implemented a mutex for sending messages, presence etc so only one request at a time is sent to the device. It seems to be crashing a little less now after my changes.

gabstv commented 4 years ago

It seems that the mutexes reduced the amount of crashes, but it still happens a lot. If you frequently send messages, the device will crash. Note that this doesn't happen with the official WhatsApp Web app.

x00b commented 4 years ago

The mutexes you implemented in your code or directly in go-whatsapp Send() method?

The weird part is that when i had this error i wasn't sending more than one message at a time and I didn't implemented concurrency in my function that sends message either... Gonna keep investigating it too.

gabstv commented 4 years ago

I implemented the mutexes in my code. All functions that use conn.Send, conn.Presence (updates to the device) have a different mutex (per whatsapp conn). This helped to decrease the Android crashes, but they still happen.

x00b commented 4 years ago

Ps: Just got this error again today(after almost 12 days without, i added Mutexes in these days and removed all conn.Read() calls ). Just letting you guys know :)

gabstv commented 3 years ago

Does anyone have a clue? This problem still happens very often.

beshoo commented 3 years ago

Ps: Just got this error again today(after almost 12 days without, i added Mutexes in these days and removed all conn.Read() calls ). Just letting you guys know :)

I dont follow you, please can you explain, what is the mutexs?

beshoo commented 3 years ago

@SchulteMK any insight!

beshoo commented 3 years ago

@x00b if I have a bot that will respond to the WhatsApp chat users more than 20 at the same time!, do you mean by mutexes we send the messages one by one to the users? which means if I have 5 chats at the same time I need to send ONE message to the device!

What is the best method to sort this out? I am thinking of insert all action to MYSQL database and call them one by one via workers base on the receiver phone number! and add 1 to 5-sec time frame between each message! is it the idea?

gabstv commented 3 years ago

The mutexes actually didn't help much with the official app crashes, it seems. I used mutexes to send only one message at a time (per device).

beshoo commented 3 years ago

I can not see this relevant to the api any how. I believe thus may related to the device it self...

I have same problem sometimes with the whatsapp web.. My advice, try to connect your device to the charger all the time and test...

lesmo commented 3 years ago

I've noticed that the "regular" way of retrieving messages will not mark them as read on the app, could it be related? Is there a way to mark messages as read? I've seen that when a connection is established, you'll receive ALL unread messages, which could potentially make a phone crash if they're just too many.

beshoo commented 3 years ago

Not related, that is how chrome works, it load all messages..

I can not see device problem related to the api. But sending a lot of messages to multiple people at the same time, well, human can not do that. So i believe it is type of protection, or we have to study the broadcast time frame between each message.

I can not find any relation to the api.

Regard

On Fri, 24 Jul 2020, 1:51 am Sinuhé Coronel, notifications@github.com wrote:

I've noticed that the "regular" way of retrieving messages will not mark them as read on the app, could it be related? Is there a way to mark messages as read? I've seen that when a connection is established, you'll receive ALL unread messages, which could potentially make a phone crash if they're just too many.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Rhymen/go-whatsapp/issues/278#issuecomment-663269644, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLT22GYEB3DR2ALICD6R3R5C5FHANCNFSM4KKX4EUQ .

beshoo commented 3 years ago

@gabstv did you try to install WhatsApp business, this app ment to answer users at same time... There is an auto answer..

lesmo commented 3 years ago

Not related, that is how chrome works, it load all messages..

Afaik It doesn't work like that. It requests all messages when you open a chat, and slowly requests more as you scroll back. Upon successful connection, go-whatsapp will receive all unread messages. If you open WhatsApp on the mobile, open all chats to mark them as read, and you re-connect go-whatsapp it will not receive new message events until new messages come in.

I really think that's the problem.

beshoo commented 3 years ago

Even though, the problem happened way after first run of the api.

It is device related echo.. Download WhatsApp business...

On Fri, 24 Jul 2020, 11:37 pm Sinuhé Coronel, notifications@github.com wrote:

Not related, that is how chrome works, it load all messages..

Afaik It doesn't work like that. It requests all messages when you open a chat, and slowly requests more as you scroll back. Upon successful connection, go-whatsapp will receive all unread messages. If you open WhatsApp on the mobile, open all chats to mark them as read, and you re-connect go-whatsapp it will not receive new message events until new messages come in.

I really think that's the problem.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Rhymen/go-whatsapp/issues/278#issuecomment-663723767, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLT27XQ7WP7JGJNBETRZTR5HWIFANCNFSM4KKX4EUQ .

gabstv commented 3 years ago

It crashes often even with Whatsapp Business. It may be related to encoding? Maybe some users are sending invalid texts like backslashes. When the app receives the packet, it tries to parse it as is and crashes. I'll try to reproduce the issue in a more controlled scenario.

beshoo commented 3 years ago

Now it makes sense if the user sends invalid characters. Why don't you log each sent message to Unicode text file, with DateTime!

I think it is kind of hard since you don't know when this happened! If the Whatsapp app stops its self form responding, then it is hard to know when and why this happened.

I am working on a project which will serve hundreds of numbers, so I am super interested in this! We need a robust log scenario to spot out the problem.

I would like to add you to a private chat, who'd you ping me beshoo@gmail.com