-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
37 lines (33 loc) · 916 Bytes
/
bot.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
const ask = require('./chat')
const qrcode = require('qrcode-terminal');
const { Client,LocalAuth} = require('whatsapp-web.js');
require('dotenv').config()
const client = new Client({
puppeteer: {
args: ['--no-sandbox'],
},
authStrategy: new LocalAuth({
clientId: "client-one"
}),
});
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
})
client.on('message', async message => {
try {
if(message.from === process.env.MESSAGE_FROM){
if (message.body.startsWith("?")) {
const prompt = message.body.substring(1)
ask(prompt).then((response) => {
message.reply(response)
}).catch(err => console.log(err))
}
}
} catch (error) {
console.log(error);
}
})
client.initialize();