forked from brunohash/onurb-wa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
28 lines (23 loc) · 880 Bytes
/
app.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
const { create, Client} = require('@open-wa/wa-automate')
const messageHandler = require('./messageHandler')
const options = require('./config/options')
const start = async (client = new Client()) => {
console.log('[SERVER] Servidor iniciado!')
client.onStateChanged((state) => {
console.log('[Status do cliente]', state)
if (state === 'CONFLICT' || state === 'UNLAUNCHED') client.forceRefocus()
})
// listening on message
client.onMessage((async (message) => {
client.getAmountOfLoadedMessages()
.then((msg) => {
if (msg >= 3000) {
client.cutMsgCache()
}
})
messageHandler(client, message)
}))
}
create(options(true, start))
.then(client => start(client))
.catch((error) => console.log(error))