-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrun.js
37 lines (30 loc) · 952 Bytes
/
run.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 fs = require('fs')
const path = require('path')
const Client = require('./api')
const credentials = JSON.parse(
fs.readFileSync(path.join(__dirname, 'config.json'), 'utf8')
)
credentials.session = fs.existsSync(path.join(__dirname, '.appstate.json'))
? JSON.parse(fs.readFileSync(path.join(__dirname, '.appstate.json'), 'utf8'))
: null
const api = new Client()
;(async () => {
await api.login(credentials.email, credentials.password)
// Save current cookie
fs.writeFileSync(
path.join(__dirname, '.appstate.json'),
JSON.stringify(await api.getSession())
)
api.listen(json => {
// json.class === 'NewMessage'
// json.body
// json.messageMetadata.actorFbId
// json.messageMetadata.threadKey.threadFbId
// json.messageMetadata.messageId
// json.messageMetadata.timestamp
console.log("LISTEN RESP", json)
if (json.body=="yes") {
api.sendMessage(json.thread, "yup")
}
})
})()