forked from tuhinpal/WhatsBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
genToken.js
27 lines (24 loc) · 1.19 KB
/
genToken.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { Client } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
const fs = require('fs');
const client = new Client({ puppeteer: { headless: true, args: ['--no-sandbox'] } });
client.initialize();
client.on('qr', (qr) => {
console.log(`Scan this QR Code and copy the JSON\n`)
qrcode.generate(qr, { small: true });
});
client.on('authenticated', (session) => {
console.log(JSON.stringify(session))
fs.readFile(__dirname + '/session.json', { encoding: 'utf8' }, function(err, data) {
if (err) {
fs.writeFileSync(__dirname + '/session.json', JSON.stringify(session))
console.log("\n\nToken also saved on a file named session.json in this directory. Please delete this file after copy if you will use enviroment variable.")
process.exit()
} else {
fs.unlinkSync(__dirname + '/session.json')
fs.writeFileSync(__dirname + '/session.json', JSON.stringify(session))
console.log("\n\nToken also saved on a file named session.json in this directory. Please delete this file after copy if you will use enviroment variable.")
process.exit()
}
})
});