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.21k stars 3.63k forks source link

Error sending a Buttons Message in branch fix-buttons-list #2014

Closed gnumarquez closed 1 year ago

gnumarquez commented 1 year ago

Is there an existing issue for this?

Describe the bug

(node:12656) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'id') at puppeteer_evaluation_script:64:51 at Array.map () at Object.window.WWebJS.prepareMessageButtons (puppeteer_evaluation_script:63:71) at Object.window.WWebJS.sendMessage (puppeteer_evaluation_script:184:43) at puppeteer_evaluation_script:10:45 at ExecutionContext._evaluateInternal (C:\Users\Equipo\Desktop\wweb\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221:19) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) at async ExecutionContext.evaluate (C:\Users\Equipo\Desktop\wweb\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:16) at async Client.sendMessage (C:\Users\Equipo\Desktop\wweb\node_modules\whatsapp-web.js\src\Client.js:686:28) (Use node --trace-warnings ... to show where the warning was created) (node:12656) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:12656) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior

It should send the buttons with no problem

Steps to Reproduce the Bug or Issue

let selectButton = new Buttons('Button body', [{ body: 'Aceptar' }, { body: 'rechazar' }, { body: 'rechazar' }], '', 'footer'); client.sendMessage(${telf}@c.us, selectButton);

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

Windows 11

Additional context

No response

gnumarquez commented 1 year ago

in commit 8ae50ec99c55550aab5675b0ce1a714fc3121552 works!!!

tapan-thapa commented 1 year ago

Hi, I am facing the same issue. Will this gets fixed?

dollyzn commented 1 year ago

Hi, I am facing the same issue. Will this gets fixed?

consider using this commit 8ae50ec version of the branch

AugustoSavi commented 1 year ago

Hi, I am facing the same issue. Will this gets fixed?

consider using this commit 8ae50ec version of the branch

This version has other problems that generate impediments

tapan-thapa commented 1 year ago

We are waiting this branch (Button/List) to be merged at master branch. If this feature is not supported now, we should remove the same from supported feature list.

jmarcosltc commented 1 year ago

Hi, I am facing the same issue. Will this gets fixed?

consider using this commit 8ae50ec version of the branch

This version has other problems that generate impediments

Im facing the same issue, but latest release 1.19.4 also does not support buttons apparently

OctavioSI commented 1 year ago

I am trying to use this commit: eafdfe12f2e5af9ae017dbe3accf5f38adf4a697

So far it works to send buttons

AugustoSavi commented 1 year ago

So far it works to send buttons

I am using whatsapp business, ubuntu 20.04.5 LTS and node v14.18.1...

I tried to use this commit:

git reset --hard eafdfe12f2e5af9ae017dbe3accf5f38adf4a697

I deleted the .wwebjs_auth and the node_modules folders

Then

npm i

Then I ran my code:

client.on('message_create', async (msg) => {
    // Fired on all message creations, including your own
    if (msg.fromMe) {
        if (msg.body === '!'){
            const GROUP_NAME = 'GrupoTesteBot';

            const chats = await client.getChats();
            const group = chats.find(chat => chat.isGroup && chat.name === GROUP_NAME);

            console.log('group: ' + group.name);

            if (group) {
                const participants = await group.participants;
                const contacts = participants.map(participant => participant.id._serialized);
                console.log(`contacts do grupo ${GROUP_NAME}: ` + contacts);

                for (const contact of contacts) {
                    const buttons = [
                        {
                            body: 'Gostaria de continuar'
                        },
                        {
                            body: 'Pode me remover'
                        }
                    ];
                    const message = new Buttons(
                        `Olá! Sou o chatbot do admin do grupo ${GROUP_NAME}, estou entrando em contato pois estamos no inicio do semeste e precisamos limpar o grupo para adicionar os novos alunos... \n\n Ai gostaria de saber se você gostaria de continuar no grupo ${GROUP_NAME}?`,
                        buttons,
                        `Questionário sobre o grupo ${GROUP_NAME}`,
                        ''
                    );

                    console.log(`sendMessage to: ${contact}, message: ${message}`);
                    await client.sendMessage(contact, message);
                }
            } else {
                console.log('Grupo não encontrado');
            }
        }
    }
});

The message is sent but never delivered:

Desktop-screenshot (1)

Am I doing something wrong?

group2tts commented 1 year ago

@AugustoSavi the same

gnumarquez commented 1 year ago

This branch works github:pedroslopez/whatsapp-web.js#f655453

group2tts commented 1 year ago

This branch works github:pedroslopez/whatsapp-web.js#f655453

No. buttons are sent but never delivered like in the screenshot above

gnumarquez commented 1 year ago

This branch works github:pedroslopez/whatsapp-web.js#f655453

No. buttons are sent but never delivered like in the screenshot above

Do you try with other whatsapp account?? i'm using this branch in this moment and i can send buttons and lists and both are delivered

group2tts commented 1 year ago

This branch works github:pedroslopez/whatsapp-web.js#f655453

No. buttons are sent but never delivered like in the screenshot above

Do you try with other whatsapp account?? i'm using this branch in this moment and i can send buttons and lists and both are delivered

You use android or iOS ?

tapan-thapa commented 1 year ago

I just tried with below branch and still it does not work.

"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#fix-buttons-list"

Message goes but never reached to destination.

This is how i am sending.

 let button = new Buttons('Button body', [{ body: 'bt1' }, { body: 'bt2' }, { body: 'bt3' }], 'title', 'footer');
 client.sendMessage(msg.from, button);

Can you give your code sample?

OctavioSI commented 1 year ago

I've just replaced in my package.json with

"whatsapp-web.js": "github:pedroslopez/whatsapp-web.js#eafdfe12f2e5af9ae017dbe3accf5f38adf4a697"

It's been 2 days and still working just fine

rafosolima commented 1 year ago

Hi guys to fix this problem I made these changes in src/util/Injected.js take a look at the commit of the fix: https://github.com/meetscrm/whatsapp-web.js/commit/8a46b65e2284ae2b031b5a9217e33ec2bab2e579

leobaldoneto commented 1 year ago

Hi guys to fix this problem I made these changes in src/util/Injected.js take a look at the commit of the fix: meetscrm@8a46b65

It worked!

Do that to use that commit: npm remove whatsapp-web.js

npm i https://github.com/meetscrm/whatsapp-web.js/commit/8a46b65e2284ae2b031b5a9217e33ec2bab2e579

Later you can reinstall via npm again, when Pedro merge the branch.

s4suryapal commented 1 year ago

https://github.com/meetscrm/whatsapp-web.js/commit/8a46b65e2284ae2b031b5a9217e33ec2bab2e579

Getting error

npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar TAR_BAD_ARCHIVE: Unrecognized archive format npm ERR! code TAR_BAD_ARCHIVE npm ERR! TAR_BAD_ARCHIVE: Unrecognized archive format

shirser121 commented 1 year ago

Buttons and lists currently not supported

rokhmad92 commented 1 year ago

i have same errors