pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.5k stars 3.45k forks source link

It takes a very long time for messages to be sent to large chats #2727

Open thedeaddan opened 5 months ago

thedeaddan commented 5 months ago

Is there an existing issue for this?

Describe the bug

When the bot forwards a message to a chat for ~700 people. That's a very high delay in sending. And an error often occurs: [2024-01-15 13:32:37] error: Evaluation failed: Error: msg is not a media msg: unknown, isGif=false at e (https://web.whatsapp.com/:2:4911) at d (https://web.whatsapp.com/app.d61b42d11fedf617d4e8.js:269:59292) at t.getMsgMediaType (https://web.whatsapp.com/app.d61b42d11fedf617d4e8.js:269:57305) at https://web.whatsapp.com/app.d61b42d11fedf617d4e8.js:266:676147 at async Object.window.WWebJS.forwardMediaMessage (__puppeteer_evaluation_script__:308:16) at async Object.window.WWebJS.forwardMessage (__puppeteer_evaluation_script__:234:28) at async __puppeteer_evaluation_script__:7:20

Expected behavior

The forwarding speed should be higher

Steps to Reproduce the Bug or Issue

await msg.forward(msg.chat);

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Debian GNU/Linux 11 (bullseye) x86_64 Phone OS: Android 13 whatsapp-web.js version: v1.23.1-alpha.4 WhatsApp Web version: 2.2402.5 NodeJS ver: v20.9.0

Additional context

No response

thedeaddan commented 5 months ago

The client's constant:

const client = new Client({
    authStrategy: new LocalAuth(),
    puppeteer: {
        executablePath: process.env.CHROME_EXECUTABLE_PATH,
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
        headless: 'new',
    }
});
thedeaddan commented 5 months ago

I can also add that the system is used without a graphical shell (terminal only). If this is important, please let us know

alechkos commented 5 months ago

@thedeaddan Do you use #2272?

thedeaddan commented 5 months ago

@alechkos yep

alechkos commented 5 months ago

@thedeaddan Also please send your code

alechkos commented 5 months ago

@thedeaddan

That's a very high delay in sending

The delay is after each message or after you started the script and it is sending to 700 users and you can't use other funtion?

alechkos commented 5 months ago

@thedeaddan

yep

Do you use the updated pr version?

thedeaddan commented 5 months ago

@pedroslopez Yes

thedeaddan commented 5 months ago

@thedeaddan

That's a very high delay in sending

The delay is after each message or after you started the script and it is sending to 700 users and you can't use other funtion?

There is a delay in sending almost every message. It works in the following mode: It received a message from one chat for 500+ people and forwarded it to another chat for 700+ people. And vice versa

thedeaddan commented 5 months ago

There is also a problem that if there are a lot of messages in the chat, let's say if it has been working for a long time. Then he just stops receiving them. Either it takes a very long time to receive, and it takes even longer to forward

alechkos commented 5 months ago

Already opened issues that maybe can help you: #1567, #2381

thedeaddan commented 5 months ago

@alechkos Unfortunately, it didn't help. I even changed the hosting to a more powerful one. 16 GB OF RAM. 150 GB NVMe. But it didn't help at all, over time he just can't forward. There is a feeling that it depends on the number of messages in the chats. I did the cleanup at startup. But it works for the first time, and then it freezes again

alechkos commented 5 months ago

@thedeaddan

Unfortunately, it didn't help.

Do you use https://github.com/pedroslopez/whatsapp-web.js/pull/2272?

yep

If you currently are using the forward method from the pr, then try to use an old one defined in the library, proceed npm i github:pedroslopez/whatsapp-web.js#main and check.

After it update if you have a problem with forwarding

thedeaddan commented 5 months ago

@alechkos When using this branch, forwarding falls into error:

/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221
            throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
                  ^

Error: Evaluation failed: TypeError: chat.forwardMessages is not a function
    at __puppeteer_evaluation_script__:5:31
    at ExecutionContext._evaluateInternal (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async Message.forward (/root/wapp/node_modules/whatsapp-web.js/src/structures/Message.js:441:9)

Node.js v21.6.1

I am sending it using:

 await msg.forward(target_chat);
alechkos commented 5 months ago

@thedeaddan Use this approach and then comment if it worked for you

thedeaddan commented 5 months ago

@alechkos So is it to overwrite the file after each update?

alechkos commented 5 months ago

So is it to overwrite the file after each update?

No, just check it once

thedeaddan commented 5 months ago

@alechkos

/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221
            throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
                  ^

Error: Evaluation failed: TypeError: window.Store.Chat.forwardMessagesToChats is not a function
    at __puppeteer_evaluation_script__:4:31
    at ExecutionContext._evaluateInternal (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async Message.forward (/root/wapp/node_modules/whatsapp-web.js/src/structures/Message.js:441:9)

Node.js v21.6.1
alechkos commented 5 months ago

@thedeaddan What wweb are you using? console.log(await client.getWWebVersion())

thedeaddan commented 5 months ago

@alechkos 2.2405.4

alechkos commented 5 months ago

@thedeaddan I have to check it

thedeaddan commented 5 months ago

@alechkos And for the rest, does message forwarding work normally, or is it not a popular method? Is there any other way?

alechkos commented 5 months ago

@thedeaddan

And for the rest, does message forwarding work normally, or is it not a popular method? Is there any other way?

Yes it works but in the pr

thedeaddan commented 5 months ago

@thedeaddan

And for the rest, does message forwarding work normally, or is it not a popular method? Is there any other way?

Yes it works but in the pr

This is just a branch

npm install github:alechkos/whatsapp-web.js#forward-with-caption

?

alechkos commented 5 months ago

@thedeaddan Yep

thedeaddan commented 5 months ago

@alechkos Yes, I am on this branch. I will try to do something for now. (Delete the original message after forwarding or clean the chat more often)

alechkos commented 5 months ago

@thedeaddan In my pr I didn't implement the cache while forwarding media if you are using my pr and you forward media then maybe this is the problem with slow forwarding

thedeaddan commented 5 months ago

@alechkos And then what can I do?

alechkos commented 5 months ago

@thedeaddan

And then what can I do?

You can check the code and fix the implementation or to wait until I'll fix it but firstly we have to check if the problem is with unimplemented cache

thedeaddan commented 5 months ago

@alechkos If anything, here are the client settings:

const client = new Client({
    authStrategy: new LocalAuth(),
    puppeteer: {
        executablePath: process.env.CHROME_EXECUTABLE_PATH,
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
        ignoreDefaultArgs: ['--disable-dev-shm-usage'], 
        ignoreHTTPSErrors: true,
        headless: 'new',
    }
});
thedeaddan commented 5 months ago

@alechkos Sometimes such errors also happen:

[2024-02-05 10:41:03] error: Evaluation failed: Error: msg is not a media msg: unknown, isGif=false
    at e (https://web.whatsapp.com/:2:4913)
    at d (https://web.whatsapp.com/app.f048d8d89717819d6c73.js:269:59333)
    at t.getMsgMediaType (https://web.whatsapp.com/app.f048d8d89717819d6c73.js:269:57346)
    at https://web.whatsapp.com/app.f048d8d89717819d6c73.js:266:682842
    at async Object.window.WWebJS.forwardMediaMessage (__puppeteer_evaluation_script__:308:16)
    at async Object.window.WWebJS.forwardMessage (__puppeteer_evaluation_script__:234:28)
    at async __puppeteer_evaluation_script__:7:20

image

davalmeyda commented 4 months ago
/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221
            throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
                  ^

Error: Evaluation failed: TypeError: window.Store.Chat.forwardMessagesToChats is not a function
    at __puppeteer_evaluation_script__:4:31
    at ExecutionContext._evaluateInternal (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async Message.forward (/root/wapp/node_modules/whatsapp-web.js/src/structures/Message.js:441:9)

Node.js v21.6.1

I have the same problem, is there already a solution to this?

thedeaddan commented 4 months ago
/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221
            throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
                  ^

Error: Evaluation failed: TypeError: window.Store.Chat.forwardMessagesToChats is not a function
    at __puppeteer_evaluation_script__:4:31
    at ExecutionContext._evaluateInternal (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (/root/wapp/node_modules/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async Message.forward (/root/wapp/node_modules/whatsapp-web.js/src/structures/Message.js:441:9)

Node.js v21.6.1

I have the same problem, is there already a solution to this?

npm install github:alechkos/whatsapp-web.js#forward-with-caption

But the work is still not stable, even on this branch. You have to constantly restart the script

rbkayz commented 4 months ago

Did you figure out why?