-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 1.1 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
const qrcode = require('qrcode-terminal')
const { Client, LocalAuth } = require('whatsapp-web.js');
const nodeCron = require('node-cron');
// const url = 'https://www.linkedin.com/jobs/search/?currentJobId=3364459444&geoId=105693087&keywords=web%20developer&location=Lagos%2C%20Lagos%20State%2C%20Nigeria&refresh=true'
// Use the saved values
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 === 'Whatsapp');
client.sendMessage(
myGroup.id._serialized, 'Hello from the other side!'
)
let position = 1
const job = nodeCron.schedule("*/2 * * * *", () => {
client.sendMessage(
myGroup.id._serialized, `Hello, this is a scheduled message(position ${position})!`
)
position++
});
})
});
client.on('message', message => {
console.log(message.body);
});
client.initialize();