forked from ameybh/ww-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 1022 Bytes
/
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
require('dotenv').config();
const qrcode = require('qrcode-terminal');
const { Client } = require('whatsapp-web.js');
let sessionLocal = JSON.parse(process.env.WW_SESSION);
console.log(sessionLocal);
const puppeteerOptions = {
headless: true,
args: ["--no-sandbox"],
};
const client = new Client({
puppeteer: puppeteerOptions,
session: sessionLocal
});
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('authenticated', session => {
// Save this session object in WW_SESSION manually to reuse it next time
console.log(JSON.stringify(session));
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.on('message', message => {
console.log(message);
const check = message.body.toLowerCase();
if (check.indexOf('!hi') != -1 || check.indexOf('!hello') != -1) {
message.reply('Hello there!\nI am ww-bot. This is an automated message.\nRead more at https://github.com/ameybhavsar24/ww-bot');
}
});
client.initialize();