Michal Iakobashvili
Michal Iakobashvili

Reputation: 1

Send Buttons messages for whatsapp bot

My goal is to create whatsapp bot which send a button message or list message. currently cant figure it out. I try to send buttons or list as message in whatsapp using node js. I tried whatsapp-web.js,it looks like it work ('Buttons sent successfully!') but it's not sending any message. I also tried venome and i cant figure why it dont work- the error is that there is no subtitle (but it is there). here is my code for whatsapp-web.js:

const qrcode = require('qrcode-terminal');
const { Client, 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', async msg => {
    console.log('Received a message:', msg.body);
    if (msg.from.endsWith('@c.us')) {
        // Create a buttons object
        const buttons = new Buttons(
            'Choose an option:',
            [
                { body: 'Option 1' },
                { body: 'Option 2' },
                { body: 'Option 3' }
            ],
            'Your Title Here',
            'Your Footer Text Here'
        );

        // Send the buttons message
        try {
            await client.sendMessage(msg.from, buttons);
            console.log('Buttons sent successfully!');
        } catch (error) {
            console.error('Failed to send buttons:', error);
        }
    }
});

client.initialize();

here is my code for venome:


async function tryOptions(client, message) {
  from = message.from;
// Send Messages with Buttons Reply
const buttons = [
  {
    "buttonText": {
      "displayText": "Text of Button 1"
      }
    }
  ]
await client.sendButtons(from, 'Title', 'Description of the buttons- subtitle',buttons);

}

i expected to see messages sent to clients. i saw nothing. if you have another option how i can send buttons i will be happy to learn.

Upvotes: 0

Views: 368

Answers (1)

user755156
user755156

Reputation: 19

they deprecated buttons and lists github link check img

Upvotes: 1

Related Questions