-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for facebook messenger interface
- Loading branch information
1 parent
92ca7fc
commit c195332
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 = bluebird.promisifyAll(api); | ||
|
||
this.api.listenAsync().then(function(message) { | ||
this.messageRecieved(message.threadID, message.body, message.senderID); | ||
}.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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "woodhouse-interface-facebook-messenger", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Woodhouse/woodhouse-interface-facebook-messenger.git" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Woodhouse/woodhouse-interface-facebook-messenger/issues" | ||
}, | ||
"homepage": "https://github.com/Woodhouse/woodhouse-interface-facebook-messenger#readme", | ||
"dependencies": { | ||
"bluebird": "^3.4.0", | ||
"facebook-chat-api": "^1.1.0" | ||
} | ||
} |