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
15.24k stars 3.64k forks source link

ERROR WHEN SENDING MESSAGE #2341

Closed minnigagustin closed 10 months ago

minnigagustin commented 1 year ago

Is there an existing issue for this?

Describe the bug

/root/backpack/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: Cannot read properties of undefined (reading 'WidFactory') at puppeteer_evaluation_script:2:42 at ExecutionContext._evaluateInternal (/root/backpack/whatsapp-web.js/node_modules/puppeteer/lib/cjs/pup peteer/common/ExecutionContext.js:221:19) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ExecutionContext.evaluate (/root/backpack/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppet eer/common/ExecutionContext.js:110:16) at async Client.sendMessage (/root/backpack/whatsapp-web.js/src/Client.js:815:28)

Expected behavior

send message

Steps to Reproduce the Bug or Issue

.

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

.

Additional context

No response

carlosdarwed commented 1 year ago

Same thing here, trying to send a message and receiving the same error

Milton-scz commented 1 year ago

I have the same problem, while sending the messages

alechkos commented 1 year ago

@minnigagustin @carlosdarwed @Milton-scz @malikmub What wweb version do you use?

console.log(await client.getWWebVersion());

also provide the lib version you use and the code you are using to send a message

tofers commented 1 year ago

lib version update ?

alechkos commented 1 year ago

Tested on the latest stable wweb v2.2328.5 + lib v1.21.0 and works as expected

minnigagustin commented 1 year ago

lib 1.21.0. The problem only happens sometimes, it started 2 days ago. It gets stuck from time to time, I restart the service and it works.

minnigagustin commented 1 year ago

Error: Evaluation failed: Error: wid error: invalid wid at e (https://web.whatsapp.com/:2:3883) at new p (https://web.whatsapp.com/app.c84a9214dcf0e06fb30b.js:89:263582) at Object.l [as createWid] (https://web.whatsapp.com/app.c84a9214dcf0e06fb30b.js:89:269046) at puppeteer_evaluation_script:2:49 at ExecutionContext._evaluateInternal (/root/backpack/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/backpack/whatsapp-web.js/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16) at async Client.sendMessage (/root/backpack/whatsapp-web.js/src/Client.js:929:24)

Milton-scz commented 1 year ago

Tested on the latest stable wweb v2.2328.5 + lib v1.21.0 and works as expected

I use version 2.2329.9

alechkos commented 1 year ago

@Milton-scz

I use version 2.2329.9

Just tested on the WWeb v2.2329.9 + lib v1.21.0 and works as expected I think you are runnig the sendMessage() method in a wrong way

T3uZ commented 1 year ago

@Milton-scz

I use version 2.2329.9

Just tested on the WWeb v2.2329.9 + lib v1.21.0 and works as expected I think you are runnig the sendMessage() method in a wrong way

to work correctly I'm using your contacts fix, why isn't it in official git yet? not approved? it usually happens with old groups.

With your fix everything works correctly.

Milton-scz commented 1 year ago

@Milton-scz

I use version 2.2329.9

Just tested on the WWeb v2.2329.9 + lib v1.21.0 and works as expected I think you are runnig the sendMessage() method in a wrong way

I've been using the library for 2 years now. and it has worked perfectly for me, but now that error has started to appear. when sending messages to whatsapp business

wandersondavid commented 1 year ago

Same problem here.

wandersondavid commented 1 year ago

caught error

Error: Evaluation failed: Error: wid error: invalid wid at e (https://web.whatsapp.com/:2:3883) at new p (https://web.whatsapp.com/app.cab989f5c25dd08ddd99.js:89:264787) at Object.d [as createWid] (https://web.whatsapp.com/app.cab989f5c25dd08ddd99.js:89:270650) at puppeteer_evaluation_script:2:53 at ExecutionContext._evaluateInternal (/home/wandersondavid/www/projects/work/whatsapp-backend/node_modules/puppeteer/src/common/ExecutionContext.ts:273:13) at processTicksAndRejections (node:internal/process/task_queues:95:5) at ExecutionContext.evaluate (/home/wandersondavid/www/projects/work/whatsapp-backend/node_modules/puppeteer/src/common/ExecutionContext.ts:140:12) at Client.sendMessage (/home/wandersondavid/www/projects/work/whatsapp-backend/node_modules/whatsapp-web.js/src/Client.js:795:28)

T3uZ commented 1 year ago

mesmo problema e nenhuma alteração foi feita no código. qualquer ajuda pls

FIX: npm install github:alechkos/whatsapp-web.js#fix-contact

Chronos093 commented 1 year ago

Boa tarde, Fiz a instalação, mas a mensagem de erro continua aparecendo. Precisa fazer algo a mais depois de instalar?

Obrigado.

mesmo problema e nenhuma alteração foi feita no código. qualquer ajuda pls

FIX: npm install github:alechkos/whatsapp-web.js#fix-contact

thank you a lot. its working fine now appreciate your help.

Heucles commented 1 year ago

Boa tarde, Fiz a instalação, mas a mensagem de erro continua aparecendo. Precisa fazer algo a mais depois de instalar?

Obrigado.

mesmo problema e nenhuma alteração foi feita no código. qualquer ajuda pls

FIX: npm install github:alechkos/whatsapp-web.js#fix-contact

thank you a lot. its working fine now appreciate your help.

I haven't used the fixed version, I've simply used the chatId instead of the number

For more info you can look into this doc: https://chat-api.com/en/docs.html

But if you take a look into the implementation, @pedroslopez is calling for the API using the chatId and not the number, in here:

https://github.com/pedroslopez/whatsapp-web.js/blob/abac063b779570729476cf42e29dc694e5345ca6/src/Client.js#L869

        const newMessage = await this.pupPage.evaluate(async (chatId, message, options, sendSeen) => {
            const chatWid = window.Store.WidFactory.createWid(chatId);
            const chat = await window.Store.Chat.find(chatWid);

            if (sendSeen) {
                window.WWebJS.sendSeen(chatId);
            }

            const msg = await window.WWebJS.sendMessage(chat, message, options, sendSeen);
            return msg.serialize();
        }, chatId, content, internalOptions, sendSeen);

So basically you need to add @c.us into the number at the end and remove the plus sign in the beginning if you have it...

Hope it helps