'Nodejs: Error bad rs block @ typeNumber:1/errorCorrectLevel:undefined
I am trying to send messages from nodejs using "whatsapp-web.js" library but during the process I have received some errors, at the moment I am getting the error
when trying to create qr code, really if I'm honest I don't know what happens
This is my app.js
import { writeFile, existsSync } from 'fs';
import { readFile } from 'fs/promises';
import ora from 'ora';
import chalk from 'chalk';
import { Client } from 'whatsapp-web.js';
//import SESSION_FILE_PATH from './session.json'
import pkg from 'qrcode-terminal';
const { generate } = pkg;
//const qrcode = require('qrcode-terminal');
//const chalk = require('chalk');
const SESSION_FILE_PATH = JSON.parse(
await readFile(
new URL('./session.json',
import.meta.url)
)
);
//const SESSION_FILE_PATH = './session.json';
let client;
let sessionData;
const withSession = () => {
const spinner = ora(`Cargando ${chalk.yellow('Validando session con Whatsapp...')}`);
sessionData = SESSION_FILE_PATH;
spinner.start();
client = new Client({
session: sessionData
})
client.on('ready', () => {
console.log('Client is ready!');
spinner.stop();
})
client.on('auth_failure', () => {
spinner.stop();
})
client.initialize();
}
//Create qr to link origin point
const withOutSession = () => {
console.log('not session saved');
client = new Client();
client.on('qr', qr => {
console.log(qr);
generate(qr, { small: true });
});
client.on('authenticated', (session) => {
//Guardamos credenciales de session para usar luego
sessionData = session;
writeFile(SESSION_FILE_PATH, JSON.stringify(session), (err) => {
if (err) {
console.log(err);
}
})
})
client.initialize();
}
(existsSync(SESSION_FILE_PATH)) ? withSession(): withOutSession();
package.json
https://github.com/IzliaB/packagejson-whatsappEnd/blob/main/package.json
Somebody could help me? i'm really lost. Please
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

