-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (47 loc) · 1.4 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
50
51
52
53
54
var bluebird = require('bluebird'),
messenger = bluebird.promisify(require('facebook-chat-api')),
facebook = function(){
this.name = 'facebook';
this.displayname = 'Facebook Messenger';
this.description = 'Send messages to woodhouse via Facebook Messenger';
this.defaultPrefs = [{
name: 'username',
displayname: 'Username',
type: 'text',
value: ''
},{
name: 'password',
displayname: 'Password',
type: 'password',
value: ''
}];
};
facebook.prototype.init = function(){
this.getPrefs().done(function(prefs){
this.prefs = prefs;
this.connect();
}.bind(this));
}
facebook.prototype.connect = function() {
messenger({
email: this.prefs.username,
password: this.prefs.password
}, {
logLevel: 'silent'
}).then(function(api) {
this.api = api;
this.api.listen(function(err, message) {
this.messageRecieved(message.threadID, message.body, message.senderID);
this.api.markAsRead(message.threadID)
}.bind(this));
this.addMessageSender(function(message, to) {
this.api.sendMessage(message, to);
}.bind(this));
}.bind(this));
}
facebook.prototype.exit = function(){
if (this.api) {
this.api.logout();
}
}
module.exports = facebook;