-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (43 loc) · 1.4 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
process.on('uncaughtException', console.error)
process.on('unhandledRejection', console.error)
import wweb from 'whatsapp-web.js'
const { Client, LocalAuth } = wweb
import { handler } from './handler.js'
import qrcode from 'qrcode-terminal'
import { platform } from 'os'
import {
plugins,
loadPluginFiles,
pluginFolder,
pluginFilter
} from './lib/plugins.js'
const conn = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
args: ['--no-sandbox'],
executablePath: platform() === 'win32' ? 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' : '/usr/bin/google-chrome-stable'
}
});
conn.initialize();
conn.on('loading_screen', (percent, message) => {
console.log('LOADING SCREEN', percent, message);
});
conn.on('qr', (qr) => {
// Generate and scan this code with your phone
console.log('QR RECEIVED', qr);
qrcode.generate(qr, { small: true });
});
conn.on('authenticated', () => {
console.log('AUTHENTICATED');
});
conn.on('auth_failure', msg => {
// Fired if session restore was unsuccessful
console.error('AUTHENTICATION FAILURE', msg);
});
conn.on('ready', () => {
console.log('READY');
});
conn.on('message_create', handler.bind(conn));
// load plugins
loadPluginFiles(pluginFolder, pluginFilter, { logger: console, recursiveRead: false }).then(_ => console.log(Object.keys(plugins))).catch(console.error)
export { conn }