-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
33 lines (29 loc) · 1.21 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
const { create } = require('@open-wa/wa-automate')
const { color } = require('./util')
const clientOptions = require('./util').options
const msgHandler = require('./handler/message')
const startServer = () => {
create('xtrvts', clientOptions(true))
.then((client) => {
console.log('[DEV]', color('xtrvts', 'yellow'))
console.log('[CLIENT] CLIENT Started!')
// Force it to keep the current session
client.onStateChanged((state) => {
console.log('[Client State]', state)
if (state === 'CONFLICT' || state === 'UNLAUNCHED') client.forceRefocus()
})
// listening on message
client.onMessage((message) => {
// Message Handler
msgHandler(client, message)
})
// listen group invitation
client.onAddedToGroup(({ groupMetadata: { id }, contact: { name } }) =>
client.getGroupMembersId(id)
.then((ids) => {
console.log('[CLIENT]', color(`Invited to Group. [ ${name} : ${ids.length}]`, 'yellow'))
}))
})
.catch((err) => new Error(err))
}
startServer()