Skip to content

Commit

Permalink
Initial commit for facebook messenger interface
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeFoodPixels committed May 28, 2016
1 parent 92ca7fc commit c195332
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
53 changes: 53 additions & 0 deletions index.js
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;
23 changes: 23 additions & 0 deletions package.json
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"
}
}

0 comments on commit c195332

Please sign in to comment.