Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send buttons and Lists #756

Merged
merged 25 commits into from
Sep 13, 2021
Merged

Send buttons and Lists #756

merged 25 commits into from
Sep 13, 2021

Conversation

tuyuribr
Copy link
Collaborator

@tuyuribr tuyuribr commented Jul 14, 2021

Add list and buttons.
Thanks to @purpshell

tuyuribr added 2 commits July 14, 2021 11:10
Draft to add list and buttons.
Thanks to @purpshell
@purpshell purpshell changed the title Add buttons && List Send buttons, and Lists. Jul 14, 2021
@purpshell purpshell changed the title Send buttons, and Lists. Send buttons and Lists Jul 14, 2021
@tuyuribr
Copy link
Collaborator Author

tuyuribr commented Jul 14, 2021

Button example:

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


//media button ( Testing, images works fine )

let media = MessageMedia.fromFilePath("image.png");
let button = new Buttons(media,[{body:"bt1"},{body:"bt2"},{body:"bt3"}],"title","footer");
client.sendMessage(message['from'], button,{'caption':"body"});

Button tests needed :
Android Business
IOS Standard and Business

@ghost
Copy link

ghost commented Jul 14, 2021

(node:6580) UnhandledPromiseRejectionWarning: ReferenceError: Buttons is not defined

I received this, even updating the project

@purpshell
Copy link
Collaborator

(node:6580) UnhandledPromiseRejectionWarning: ReferenceError: Buttons is not defined

I received this, even updating the project

have you cloned the PR????? are you using NPM?

@ghost
Copy link

ghost commented Jul 14, 2021

i use npm

@ghost
Copy link

ghost commented Jul 14, 2021

now it worked!

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

it was missing to declare the Buttons

WhatsApp Image 2021-07-14 at 18 25 45

@tuyuribr
Copy link
Collaborator Author

List example:

let sections = [{title:'sectionTitle',rows:[{id:'customId', title:'ListItem1', description: 'desc'},{title:'ListItem2'}]}];
let list = new List('aaa','btnText',sections,'Title','footer');
client.sendMessage(message['from'], list);

Lists aren't working on business right now

Tests needed:
Ios Standard

@esteves67
Copy link

Button example:

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


//media button ( Testing, images works fine )

let media = MessageMedia.fromFilePath("image.png");
let button = new Buttons(media,[{body:"bt1"},{body:"bt2"},{body:"bt3"}],"title","footer");
client.sendMessage(message['from'], button,{'caption':"body"});

Button tests needed :
Android Business
IOS Standard and Business

Tested on Android Business, and iOS Standard, and its working.
Idk about iOS Business.

@esteves67
Copy link

I've been testing this DRAFT, and took notes of some things.

Number 1:
When you have a conversation with buttons (using this PR), if you use client.getChats you get a problem with map (#297)
The only solution for now its to delete the whole conversation that has buttons in it, and the map function works again.
If you guys can test it, test it out, just to make sure its not my fault in my client.getChats function.

Number 2:
Buttons are not getting logged on the console, only the main message gets logged to the console, i guess its not being recognized by whatsapp-web.js yet.

@purpshell
Copy link
Collaborator

I've been testing this DRAFT, and took notes of some things.

Number 1:
When you have a conversation with buttons (using this PR), if you use client.getChats you get a problem with map (#297)
The only solution for now its to delete the whole conversation that has buttons in it, and the map function works again.
If you guys can test it, test it out, just to make sure its not my fault in my client.getChats function.

Number 2:
Buttons are not getting logged on the console, only the main message gets logged to the console, i guess its not being recognized by whatsapp-web.js yet.

Makes more sense since buttons_message is way different than templateMessage which msg.buttons is trying to act with

@tuyuribr
Copy link
Collaborator Author

I've been testing this DRAFT, and took notes of some things.

Number 1:
When you have a conversation with buttons (using this PR), if you use client.getChats you get a problem with map (#297)
The only solution for now its to delete the whole conversation that has buttons in it, and the map function works again.
If you guys can test it, test it out, just to make sure its not my fault in my client.getChats function.

Number 2:
Buttons are not getting logged on the console, only the main message gets logged to the console, i guess its not being recognized by whatsapp-web.js yet.

Thanks for your help!

@tuyuribr tuyuribr changed the title Send buttons and Lists Send buttons and Lists [Commits are welcome] Jul 23, 2021
@esteves67
Copy link

I've been testing this DRAFT, and took notes of some things.

Number 1:
When you have a conversation with buttons (using this PR), if you use client.getChats you get a problem with map (#297)
The only solution for now its to delete the whole conversation that has buttons in it, and the map function works again.
If you guys can test it, test it out, just to make sure its not my fault in my client.getChats function.

Number 2:
Buttons are not getting logged on the console, only the main message gets logged to the console, i guess its not being recognized by whatsapp-web.js yet.

Ignore number 1, as it is already solved by #386

@iamshouvikmitra
Copy link

Any idea when we can have this shipped?
Super excited!

@jhohenr
Copy link

jhohenr commented Aug 26, 2021

@pedroslopez Please add this functionality!

@renjop
Copy link
Contributor

renjop commented Sep 1, 2021

It seems that the most recent WhatsApp version (2.2134.9) broke the sending of this buttons:
{ "message": "Msg", "name": "ModelCreateError", "stack": "ModelCreateError: Msg\n at new i (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:403072)\n at new k (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:56:209667)\n at https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:470293\n at V (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:373738)\n at MutationObserver.K (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:373319)",

@tuyuribr
Copy link
Collaborator Author

tuyuribr commented Sep 1, 2021

It seems that the most recent WhatsApp version (2.2134.9) broke the sending of this buttons:
{ "message": "Msg", "name": "ModelCreateError", "stack": "ModelCreateError: Msg\n at new i (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:403072)\n at new k (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:56:209667)\n at https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:470293\n at V (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:373738)\n at MutationObserver.K (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:373319)",

Hmmm it's working here, are you using whatsapp-web.js@1.14.1 ?

@renjop
Copy link
Contributor

renjop commented Sep 1, 2021

It seems that the most recent WhatsApp version (2.2134.9) broke the sending of this buttons:
{ "message": "Msg", "name": "ModelCreateError", "stack": "ModelCreateError: Msg\n at new i (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:403072)\n at new k (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:56:209667)\n at https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:470293\n at V (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:373738)\n at MutationObserver.K (https://web.whatsapp.com/bootstrap_qr.abbc2ea8366e2cd9a145.js:2:373319)",

Hmmm it's working here, are you using whatsapp-web.js@1.14.1 ?

Yep, I'm using the latest whatsapp-web.js@1.41.1. Before the WhatsApp update it was working perfectly, This error seems to be an internal "error" from WhatsApp not necessarily from the whatsapp-web.js library.

@makanSukros
Copy link

Not Working on MD Version @purpshell

@makanSukros
Copy link

Not Working on MD Version @purpshell

vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34 TypeError: Cannot read properties of undefined (reading 'length')
    at bootstrap_main.e39859bf8358eb1e7271.js:13
    at Array.some (<anonymous>)
    at t.default (bootstrap_main.e39859bf8358eb1e7271.js:13)
    at ia (vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34)
    at Hs (vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34)
    at Pu (vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34)
    at Eu (vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34)
    at Su (vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34)
    at mu (vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34)
    at vendor1~bootstrap_qr.8d5b7620b726968ba154.js:34

@tuyuribr tuyuribr changed the title Send buttons and Lists [Review + Tests needed] Send buttons and Lists [Review needed] Sep 8, 2021
@Inevitable-Dev
Copy link

Inevitable-Dev commented Sep 9, 2021

Can I identify the custom ID returned from a Message of type List?

List2

@rmaafs
Copy link

rmaafs commented Sep 11, 2021

I tested it for two weeks and I don't have any problem.
Tested on Android and iOS. Nice work!

@makanSukros
Copy link

I tested it for two weeks and I don't have any problem.
Tested on Android and iOS. Nice work!

Problem only for Beta MultiDevices

@tuyuribr tuyuribr changed the title Send buttons and Lists [Review needed] Send buttons and Lists Sep 11, 2021
Copy link

@Inevitable-Dev Inevitable-Dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I spent some time testing some things to see if I could come up with a solution, but I wasn't able to come up with this excellent solution

Copy link
Collaborator

@aliyss aliyss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@purpshell
Copy link
Collaborator

Merge time

@purpshell purpshell merged commit b60029e into pedroslopez:main Sep 13, 2021
@Goomer2
Copy link

Goomer2 commented Sep 16, 2021

When I send a Button Message the Whatsapp Web Chat throws the following exception.

image

@tuyuribr
Copy link
Collaborator Author

@Goomer2 , could you send us some code?
Are you using standard wa or biz?

Image for reference:
image

@Goomer2
Copy link

Goomer2 commented Sep 16, 2021

@Goomer2 , could you send us some code?
Are you using standard wa or biz?

Image for reference:
image

I'm using biz.

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

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

client.on('qr', (qr) => {
  // Generate and scan this code with your phone
  console.log('QR RECEIVED', qr);
  qrcode.generate(qr, {small: true});
});

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

  let button = new Buttons('Button body', [{body:'Sim'},{body:'Não'},{body:'Não enviar mais'}],'title','footer');
  client.sendMessage('xxxxx@c.us', button);
});

client.on('message', msg => {
  if (msg.body == '!ping') {
    msg.reply('pong');
  }
});

client.initialize();

The error is on Whatsapp Web.

@victorfreire100
Copy link

		case '!button':
		await client.sendButtons(chatId, "Option", [
		{
        id: "1",
        "text": "Option 1"			
		},
		{
        id: "2",
        "text": "Option 2
		},
		], "")
		
		===========================
		
		When the user chooses an option I want him to make a request in an api with the option id and send a confirmation msg. Can anyone help me?

@user3470
Copy link

user3470 commented Nov 7, 2021

Oh, I spent some time testing some things to see if I could come up with a solution, but I wasn't able to come up with this excellent solution

Maybe you could look into how these guys are doing it

https://github.com/adiwajshing/Baileys

@user3470
Copy link

user3470 commented Nov 7, 2021

@Goomer2 , could you send us some code?
Are you using standard wa or biz?
Image for reference:
image

I'm using biz.

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

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

client.on('qr', (qr) => {
  // Generate and scan this code with your phone
  console.log('QR RECEIVED', qr);
  qrcode.generate(qr, {small: true});
});

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

  let button = new Buttons('Button body', [{body:'Sim'},{body:'Não'},{body:'Não enviar mais'}],'title','footer');
  client.sendMessage('xxxxx@c.us', button);
});

client.on('message', msg => {
  if (msg.body == '!ping') {
    msg.reply('pong');
  }
});

client.initialize();

The error is on Whatsapp Web.

Maybe you could look into how these guys handled it:

https://github.com/adiwajshing/Baileys

@tinyCoder32
Copy link

When I send a Button Message the Whatsapp Web Chat throws the following exception.

image

Is there any fix for this yet? It's pretty annoying 😓

Yazi-cohen pushed a commit to Yazi-cohen/whatsapp-web.js that referenced this pull request Aug 23, 2022
Belfio pushed a commit to Belfio/whatsapp-web.js that referenced this pull request Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.