-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 945 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
const fs = require('fs');
const { Client , LocalAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
const grp = require('./config.json');
const client = new Client({
authStrategy: new LocalAuth()
});
client.on('qr', (qr) => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
client.getChats().then(chats => {
const myGroup = chats.find((chat) => chat.name === grp.GroupName);
client.sendMessage(
myGroup.id._serialized,
"Hello !! I Am Ready !!"
);
});
});
client.on('message', async (message) => {
const command = message.body.toLowerCase();
if(command === 'hello') {
const chat = await message.getChat();
const contact = await message.getContact();
await chat.sendMessage(`Hello @${contact.id.user} !!`, {
mentions: [contact]
});
}
});
client.initialize();