-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
45 lines (35 loc) · 991 Bytes
/
app.ts
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
import { Client, LocalAuth } from "whatsapp-web.js";
import qrcode from "qrcode-terminal";
import { CommandHandler } from "./src/bot/commandsHandler";
require('dotenv').config();
const client = new Client({
authStrategy: new LocalAuth,
puppeteer: {
headless: true,
// executablePath: "/usr/bin/google-chrome-stable",
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
]
}
});
const prefix = 'bb'
const command_handler = new CommandHandler(prefix, client);
client.on('qr', (qr: string) => {
// Generate and scan this code with your phone
qrcode.generate(qr, { small: true });
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.on('message', msg => {
try {
if (msg.fromMe) return
if (msg.body.startsWith(prefix)) {
command_handler.handleCommand(msg)
}
} catch (error) {
console.log(error)
}
});
client.initialize();