open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.09k stars 591 forks source link

Images sent by client.sendImage are not recieved by other clients #2685

Closed gnadelwartz closed 2 years ago

gnadelwartz commented 2 years ago

Are you using the latest version of the library?

What type of session are you experiencing this issue on?

Multi-device and I have set multiDevice to true in my config OR am using the --multi-device flag

What type of host account are you experiencing this issue on?

Personal account (normal)

Mode

My own code

Current Behavior

IF I send an image with caption nothing happend, no exception is raised script continues but image dos not appear in WA Group, BUT onAnyMessage event is fired...

sending text messages works as usual.

Problem starts without any script changes, no WA@automate uodates or script restart on April 26 around midnight.

Expected Behavior

Image should be received by all WA Clients in group

Steps To Reproduce

run my code

create() code OR full CLI command + CONFIG

const wa = require('@open-wa/wa-automate');

const launchConfig = {
        legacy: true,
        useChrome: true,
        chromiumArgs: [
                '--bswi', // disable as many as possible for a small foot print
                '--single-process',
                '--no-first-run',
                '--disable-gpu',
                '--no-zygote',
                '--no-sandbox',
                '--incognito', // use inkonito mode
                '--disable-setuid-sandbox',
                '--disable-dev-shm-usage',
                '--disable-accelerated-2d-canvas',

       ],      
        cacheEnabled: false,
        throwErrorOnTosBlock: true,
        headless: true,
        multiDevice: true
};      

wa.create(launchConfig).then(client => start(client));

send Image Code:
// send picture and deal text
my_log('picture: ' + picurl);
try {
     client.sendImage(FORWARDARR[chat], picurl, picurl.replace(/.*\//, '').replace(/[?&].*/, ''), caption);
   pic_ok = true;
}
catch(error) { my_log("******* Error: Send link/pic failed: "+error.replace(/\n.*/, '')); }
my_log('done ...');

DEBUG INFO

{
  "WA_VERSION": "2.2214.12",
  "WA_AUTOMATE_VERSION": "4.35.12",
  "BROWSER_VERSION": "HeadlessChrome/100.0.4896.127",
  "START_TS": 1651301197249,
  "RAM_INFO": "Total: 6.22 GB | Free: 0.99 GB",
  "PPTR_VERSION": "UNKNOWN",
  "LATEST_VERSION": true,
  "CLI": false,
  "LAUNCH_TIME_MS": 19580,
  "ACC_TYPE": "PERSONAL",
  "chats": 15,
  "messages": 15,
  "contacts": 602,
  "isMd": true,
  "INSTANCE_ID": "d6f71771-8752-401e-9821-86cc0c769686"
}

Environment

- OS: Linux 5.3
- Node: 16.13.2
- npm: 8.1.2

Screenshots/Logs

Startup Message , sent and can be seen as usal by all Group Members:

30.4.2022, 08:46:57 =========== new message ================
30.4.2022, 08:46:57 From: 4915905xxxx@c.us To: 49159058yxyxx-1579623xxx@g.us Sender: 4915905861477@c.us
30.4.2022, 08:46:57 Chat: 491590586xxx-157962xxx@g.us 
30.4.2022, 08:46:57 Content: WhatsApp Bot neu gestartet
30.4.2022, 08:46:57 Save to file: 142d9297-f6a4-451d-a9a1-a3b7912c03bd

Image Message, no error, script continues, but not seen by other clients in group:

30.4.2022, 08:59:15 ******** Forward detected: 
30.4.2022, 08:59:15 picture: https://m.media-amazon.com/images/I/31j+xzPQsZL._SL500_.jpg
30.4.2022, 08:59:15 caption:  🛒 HUDORA 6956016014695 14695 BigWheel ..
30.4.2022, 08:59:15 done ...

Image Message is recieved by onw script, but not seen by others:

30.4.2022, 08:59:16 =========== new message =================
30.4.2022, 08:59:16 From: MYBOT  (491590586xxxxx@c.us) Chat: #MD mnsdsbfbdfjbjdsbf  (491590586xxxx-162684xxxx@g.us)
30.4.2022, 08:59:16 ####### Ignore own messages in this chat, skipping ...

Anything else?

No response

gnadelwartz commented 2 years ago

@smashah suddenly wa-automate wanted to re authenticate with qQR code and afterwards sendImage was working again

issue can be closed. after reading ;-)

gnadelwartz commented 2 years ago

OK, one more update.

once a while it takes a while until sendImage Messages arrive on other clients. Sometimes its helps restart App or reload WA Web on other Client side. Sometimes missing images apeasrs suddely when sending a new image. I think this may happen when sending multiple images in a short timeframe.

This happend with MD before the "not sending at all" issue also.

smashah commented 2 years ago

@gnadelwartz so reproduction steps is to send multiple images in quick succession to the same group chat?

onAnyMessage fires if a message object was added to the msg models array. It will emit even if the message is never actually sent. If you want to check the sent status of a message, listen to onAck (ack).

0 = not sent (clock) 1 = sent (1 tick) 2 = received by the recipient (2 ticks) 3 = seen by recipient (2 blue ticks) - depends on recipient privacy settings.

gnadelwartz commented 2 years ago

The original issue with not sending images at all was gone after re-authentication. What remains is the problem when sending many images in short timeframe. Unfortunately I did not found a trigger amount, currently it seems random. As its a virtual server in a shared hosting environment it may related to timing, server or network activity.

Thanks for the onAnyMessage topic, this explains why image is not sent but event fired.

gnadelwartz commented 2 years ago

@gnadelwartz so reproduction steps is to send multiple images in quick succession to the same group chat?

In two different group chats, containing ~ 300 Users each

smashah commented 2 years ago

@gnadelwartz I think the massive group size has something to do with this.

MD sessions need to fan out messages to all those contacts and all those contacts' MD sessions. So I'm not surprised it will take a while for all those messages to get sent.

Can you try to brute force this issue with 2 groups with only 2 members each please so we can isolate the root cause.

gnadelwartz commented 2 years ago

For now I have set image send rate limit to 1 with p-queue, lets see ...

gnadelwartz commented 2 years ago

@gnadelwartz I think the massive group size has something to do with this.

@smashah sorry it was my fault/typo I mean 30 Users not 300. Nevertheless i'll try with a test account it I find some time.

gnadelwartz commented 2 years ago

no more issues when queing (sorry for not reverting/testing without queue), may related to new issue #2718 when sending picture after reconnect...

smashah commented 2 years ago

Keep using the queue to maintain stability. Assume they're using some sort of leaky bucket method of sending messages

https://en.wikipedia.org/wiki/Leaky_bucket#:~:text=The%20leaky%20bucket%20is%20an,poured%20in%20all%20at%20once.