-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
50 lines (40 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var login = require('facebook-chat-api');
var handleMessage = require('./src/handleMessage.js');
var userInfo = {
email: '[email protected]',
password: 'Your_Password'
};
var timeout = undefined; // 1000 for one second
var inTimeout = {};
login({email: userInfo.email, password: userInfo.password}, function(err, api){
if(err) return console.log(err);
function sendMessage(str, id){
return new Promise((resolve, reject) => {
api.sendMessage(str, id, function(err){
if(err){
reject(err);
return;
}
resolve('send str success');
});
});
}
api.listen(function(err, message){
if(err){
console.log(err);
return;
}
console.log(message);
var req = message.body ? message.body.toLowerCase() : '';
var id = message.threadID;
if(req && !inTimeout[id]){
handleMessage(req, id, sendMessage);
if(timeout){
inTimeout[id] = true;
setTimeout(function(){
inTimeout[id] = false;
}, timeout);
}
}
});
});