-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
executable file
·35 lines (29 loc) · 951 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
29
30
31
32
33
34
35
const login = require("facebook-chat-api");
const fs = require("fs");
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) =>
{
fs.writeFileSync("appstate.json", JSON.stringify(api.getAppState()));
api.setOptions(
{
selfListen: true,
logLevel: 'warn'
});
api.listenMqtt((err, msgReceived) =>
{
if (msgReceived.type === 'message' && msgReceived.body.indexOf('@everyone', 0) >= 0)
{
api.getThreadInfo(msgReceived.threadID, (err, info)=>
{
//This is a work-around for a bug (see facebook-chat-api issue #857)
//mention doesn't work if tag is at index zero in body string
const emptyChar = '\u200E';
var msgToSend = { body: emptyChar + 'AAAAAAAAAAAAA', mentions: [] };
for(var i=0; i< info.participantIDs.length; i++)
{
msgToSend.mentions.push({tag: 'AAAAAAAAAAAAA', id: info.participantIDs[i]});
}
api.sendMessage(msgToSend, info.threadID);
});
}
});
});