Search code examples
chatbotqr-codewhatsapp

I am developing a chat bot with whatsapp-web.js, but I am having a problem. Node js


I am developing a chat bot with whatsapp-web.js, but I am having a problem. I installed npm i whatsapp-web.js and npm i qrcode-terminal. The QR code is generated, I scan it with my phone, but after connecting, when I try to send a message, it does not send automatically.

Code:

const qrcode = require('qrcode-terminal');

const { Client } = 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 => {
    if(message.body === 'Hello') {
        message.reply('Hello Guys!');
    }
});
 

client.initialize();

Normally, when the QR code connection is established, the message Client is ready! should be printed to the terminal. I am not seeing this message in the terminal and the bot is not responding automatically to the message "hello". If you could help me, I would be grateful.

After the QR code connection is established, the message Client is ready! should appear and it should automatically respond to the message hello.


Solution

  • https://github.com/pedroslopez/whatsapp-web.js/issues/2473

    WhatsApp Web was changed.

    Modify selector in Client.js line 175 Now I used textbox as selector

    const INTRO_IMG_SELECTOR = 'div[role=\'textbox\']'; //'[data-icon=\'chat\']';