forked from pedroslopez/whatsapp-web.js
-
Notifications
You must be signed in to change notification settings - Fork 11
/
shell.js
36 lines (28 loc) · 824 Bytes
/
shell.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
28
29
30
31
32
33
34
35
36
/**
* ==== wwebjs-shell ====
* Used for quickly testing library features
*
* Running `npm run shell` will start WhatsApp Web with headless=false
* and then drop you into Node REPL with `client` in its context.
*/
const repl = require('repl');
const { Client, LocalAuth } = require('./index');
const client = new Client({
puppeteer: { headless: false },
authStrategy: new LocalAuth()
});
console.log('Initializing...');
client.initialize();
client.on('qr', () => {
console.log('Please scan the QR code on the browser.');
});
client.on('authenticated', (session) => {
console.log(JSON.stringify(session));
});
client.on('ready', () => {
const shell = repl.start('wwebjs> ');
shell.context.client = client;
shell.on('exit', async () => {
await client.destroy();
});
});