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.62k stars 3.48k forks source link

Error sending WhatsApp-web.js buttons #1759

Closed Ayperoz closed 1 year ago

Ayperoz commented 1 year ago

Is there an existing issue for this?

Describe the bug

Hello I am having two problems when trying to create a bot with buttons for whatsapp in nodejs. one is a calculation bug and the other a query. The first error I have when trying to send a button as marked by the example in the documentation. And the second is that I am not entirely clear on how to make the message be sent only to the first interaction and somehow that the process is activated only once per client every 24 hours. The code is this:

the result is the following

image

Expected behavior

that when having an incoming message send the button

Steps to Reproduce the Bug or Issue

1 link 2 receive message 3 send button

Relevant Code

const qrcode = require('qrcode-terminal'); const { Client, LocalAuth } = require('whatsapp-web.js'); const { Message, ClientInfo, Buttons } = require('whatsapp-web.js/src/structures');

const client = new Client({ authStrategy: new LocalAuth(), puppeteer: { headless: false } });

client.on('ready', () => { console.clear(); console.log('season ok'); });

client.on('qr', qr => { console.log('link QR'); qrcode.generate(qr, { small: true }); });

client.initialize();

client.on('message', msg => { console.log('mensaje de: ', msg.from, 'Texto: ', msg.body) if (msg.body === 'Hello') { let button = new Buttons('Button body', [{ body: 'Aceptar' }, { body: 'rechazar' }], 'title', 'footer'); client.sendMessage(msg.from, button); } });

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

•SO Windows 10 x64 professional. • Phone Android. • Version WhatsApp-web.js 1.18.0. • Version node 18.12.0.

Additional context

sin contexto adicional

PurpShell commented 1 year ago

Use the experimental branch

npm install github:pedroslopez/whatsapp-web.js#fix-buttons-list
Ayperoz commented 1 year ago

Usar la rama experimental

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

same fails to install this image

astroincz commented 1 year ago

Usar la rama experimental

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

same fails to install this image

npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list

Ayperoz commented 1 year ago

npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list

same mistake

fmarmolejo commented 1 year ago

Try updating npm, I fixed that bug with version 1.18.2 and buttons are sent

Ayperoz commented 1 year ago

Try updating npm, I fixed that bug with version 1.18.2 and buttons are sent

update and... image

same

image

I already had version 1.18.2

image

Ayperoz commented 1 year ago

when i send "Hello" show me this

image

PurpShell commented 1 year ago

@Ayperoz install git

https://git-scm.com

Ayperoz commented 1 year ago

fixed, step 1 install Git Bash. step 2 run npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list from Git Bash in the project directory. step 3 - run project

And the buttons work

image

rezabayupamungkas commented 1 year ago

i can run button/list using this step:

  1. delete folder node_modules
  2. run this "npm i github:pedroslopez/whatsapp-web.js#fix-buttons-list"
AmarKhoirudin commented 1 year ago

button can use this version but normal chat without button error

const templateButtons = buttons.filter(button => button.url || button.number).slice(0,3);

TypeError: buttons.filter is not a function

Ayperoz commented 1 year ago

How do I make sure that when I select a button the others are disabled?

imismaindra commented 1 year ago

does this have to use WhatsApp business?

Ayperoz commented 1 year ago

¿Esto tiene que usar WhatsApp Business?

Yes, same detail as the description, Whatsapp business. android, multi device, chrome browser :D

manigedit commented 1 year ago

@PurpShell Please rebase / merge your branch on latest main. It seems the LegacyPhoneFeatures thing is breaking the fix-buttons-list branch right now

matheuspbmarques commented 1 year ago

I did npm i github:pedroslopez/whatsapp-web.js#fix-buttons-list, and show this error:

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'LegacyPhoneFeatures')

skibaalex commented 1 year ago

@matheuspbmarques I got the same error. are there any solutions?

matheuspbmarques commented 1 year ago

@skibaalex , anything.

uthx commented 1 year ago

Guys, I'm not getting any errors while sending the button, but I cannot receive the button on the receiver side.

matheuspbmarques commented 1 year ago

@matheuspbmarques I got the same error. are there any solutions?

Solution of problem are in other issue. Follow link:

https://github.com/pedroslopez/whatsapp-web.js/issues/1945#issuecomment-1400246316

Resolved for me.

matheuspbmarques commented 1 year ago

Guys, I'm not getting any errors while sending the button, but I cannot receive the button on the receiver side.

Follow: https://github.com/pedroslopez/whatsapp-web.js/issues/1759#issuecomment-1403722722

PedroVic12 commented 1 year ago

npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list

to fix this I had to make a temporary fix that I got from the discord group.

image

Pelo oq ue eu li, foi por causa de uma atualização do wpp web (12/01/2023)

Go into file -> node_modules

enter the file -> whatsapp-web.js/src/util/Injected.js

and do like in this picture, this worked for me!

mauriciopfl commented 1 year ago

It's not working even in version 1.19.4, already with the Branch modification in Message.js line 497.

yberman8 commented 1 year ago

From Tuesday this week the buttons stopped working, I didn't make any changes in the code, does anyone have a solution? I tried to update to the latest version and it still doesn't work.

Ayperoz commented 1 year ago

Personally I changed my script to use the normal bot, because whatsapp detected the buttons almost automatically as an unauthorized version of whatsapp and blocked the line in a matter of minutes, I currently have ticket #1759 open with the solution I found in your moment but it no longer applies to the current version, I recommend, as a person who uses wha-js to send mass messages, not to use it until further notice. Greetings!

yberman8 commented 1 year ago

The option of deleting a message also stopped working, it gives me this error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'promises')

‫בתאריך שבת, 25 במרץ 2023 ב-6:04 מאת ‪leandro-giar‬‏ <‪ @.***‬‏>:‬

Personally I changed my script to use the normal bot, because whatsapp detected the buttons almost automatically as an unauthorized version of whatsapp and blocked the line in a matter of minutes, I currently have ticket #1759 https://github.com/pedroslopez/whatsapp-web.js/issues/1759 open with the solution I found in your moment but it no longer applies to the current version, I recommend, as a person who uses wha-js to send mass messages, not to use it until further notice. Greetings!

— Reply to this email directly, view it on GitHub https://github.com/pedroslopez/whatsapp-web.js/issues/1759#issuecomment-1483698051, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASLDS2ERFTQNQI6DDTJSEJDW5ZOD3ANCNFSM6AAAAAARPCOSPI . You are receiving this because you commented.Message ID: @.***>

Muhammed-Rashid-07 commented 1 year ago

const { Client, LocalAuth, MessageMedia, Buttons } = require('whatsapp-web.js');

const qrcode = require('qrcode-terminal')

const client = new Client({ authStrategy: new LocalAuth(), });

client.on('qr', (qr) => { qrcode.generate(qr, { small: true }) });

client.on('authenticated', () => { console.log('Authenticated'); });

let chatId = "" client.on('message', message => { console.log(message.body); chatId = message.from; console.log(chatId); });

client.on('message', message => { console.log('message from', message.from) if (message.body === "button") { try { console.log(message.body); let button = new Buttons('Button body', [{ body: 'bt1' }, { body: 'bt2' }, { body: 'bt3' }], 'title', 'footer'); console.log(button); client.sendMessage(chatId, button); } catch (error) { console.log(error); }

}

});

client.on('ready', () => { console.log("Client is ready"); });

client.initialize();

I installed "npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list" I get replies whatsapp web in laptop. I don't see the button in mobile application. I did everthing you mentioned above to get the button list. But nothing is working. pls give me the right solution. pls help.

joseangelguerrerosanchez commented 1 year ago

Hola, today is May 7 and Buttons not work, ¿Do you know what happen? Thanks,

Ayperoz commented 1 year ago

Hola, today is May 7 and Buttons not work, ¿Do you know what happen? Thanks,

At the moment we are still waiting for an update of the package that supports the buttons again, I chose to stop using them and use a conditional in the incoming with numbers, for example option1 option 2 option 3 and from there to verify the message or an error if the option is not valid

matheuspbmarques commented 1 year ago

Hi, guys.

I fix buttons erro, but not work in current version, I create a zip that buttons work, but not is unofficial, or I can create a whatsapp group and send the file them.

abdallah0x01 commented 1 year ago

@matheuspbmarques can you send the file here ?

ChenhuaFan commented 1 year ago

sendMessage doesn't work now (May 17th). can't send any message to clients.

josuearaujomoreira commented 1 year ago

Atualizei, tudo funcionando menos os botões e listas

MijanurR commented 1 year ago

does it require whatsapp business account to send buttons in chat?

Ayperoz commented 1 year ago

does it require whatsapp business account to send buttons in chat?

no, just have whatsapp

PurpShell commented 1 year ago

Buttons are going to be deprecated incrementally over the coming versions.

codemakesense07 commented 1 year ago

fixed, step 1 install Git Bash. step 2 run npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list from Git Bash in the project directory. step 3 - run project

And the buttons work

image

can i see reply button message when cliked?? please

darkcaesar0721 commented 1 year ago

I installed fix-buttons-list library on my project, but it is not still working. This is my detailed code.

After update fix-buttons-list library, message.reply() function is also not working.

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

const { Client, MessageMedia, Buttons } = require('whatsapp-web.js');

const client = new Client();

client.on('qr', (qr) => { qrcode.generate(qr, {small: true}); });

client.on('ready', () => { console.log('Client is ready!'); });

client.on('message', message => { let buttons = new Buttons('Button body', [{ body: 'Aceptar' }, { body: 'rechazar' }], 'title', 'footer'); await client.sendMessage(message.from, buttons); });

darkcaesar0721 commented 1 year ago

fixed, step 1 install Git Bash. step 2 run npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list from Git Bash in the project directory. step 3 - run project And the buttons work image

can i see reply button message when cliked?? please

I'd like to discuss about your experience quickly. My gmail is darkcaesar0721@gmail.com.

molettta commented 1 year ago

Thanks for a while! This project is great!! Today I started to try send buttons, and it's not working. A almost all here. If I try isntall https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list the messageSend completly stop to work. So a install the defaul version and its run ok again (witout buttons) For a while I will send only text and make robot with number. Thankyou

valmeidavr commented 12 months ago

Estou com mesmo problema não envia mensagem, quando coloco a atualização

Ashish-bmn commented 11 months ago

i can run button/list using this step:

  1. delete folder node_modules
  2. run this "npm i github:pedroslopez/whatsapp-web.js#fix-buttons-list"

getting this error now :

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'CallCollection') at puppeteer_evaluation_script:9:66 at ExecutionContext._evaluateInternal (C:\sample\biz-chat-nest\node_modules\puppeteer\src\common\ExecutionContext.ts:273:13) at processTicksAndRejections (node:internal/process/task_queues:95:5) at ExecutionContext.evaluate (C:\sample\biz-chat-nest\node_modules\puppeteer\src\common\ExecutionContext.ts:140:12) at Client.initialize (C:\sample\biz-chat-nest\node_modules\whatsapp-web.js\src\Client.js:274:9)

PauloPinto87 commented 10 months ago

Estou com mesmo problema não envia mensagem, quando coloco a atualização

Same

user-matth commented 9 months ago

Still the same error, anyone has solved it?

rokhmad92 commented 9 months ago

same error

Shashank22082002 commented 9 months ago

Any alternatives for using buttons, they don't seem working now, after the updates. I am installing wweb.js by using hotfix, as described here https://github.com/pedroslopez/whatsapp-web.js/issues/2437

amrallam-appaout commented 7 months ago

Any updates about the Interactive Messages Support?

Samyak2501 commented 3 months ago

fixed, step 1 install Git Bash. step 2 run npm i git+https://github.com/pedroslopez/whatsapp-web.js#fix-buttons-list from Git Bash in the project directory. step 3 - run project

And the buttons work

image

Samyak2501 commented 3 months ago

When I run this command then my client ready is not triggered so then I run this command npm i github:pedroslopez/whatsapp-web.js#main After running this client ready is triggered but button are not working, I think only one command is working at one in my laptop