Search code examples
javascriptqr-codewhatsapp

QR RECEIVED <some code> . How to connect to whatsapp web with this code? whatsapp-web.js


This spams in console when i run my code . Module - whatsapp-web.js

CODE

const { Client } = require('whatsapp-web.js');
const client = new Client();

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



client.on('message', async(msg) => {
    const mentions = await msg.getMentions();

    for (let contact of mentions) {
        console.log(`${contact.pushname} was mentioned`);
    }
});

client.initialize();

How to connect to whatsapp web with this module ?

CONSOLE

QR received 
1@wCO3HYi6B1wat+cAyHe3+tlzfbjiWNxCTP30fEY16YNgmaBuknL/bBDpMNzA2SgfFPfCgQ==,yycd40PiAgEvrk961s+wiBLoMlsFb/eqVpRTN9Ec3FE=,E37yNJ5fmhoX3G/A==

Something like the above appear in console .


Solution

  • this should do the thing

    $ npm i qrcode-terminal
    

    then

    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.initialize();