Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #317 from sage-bots/master
Browse files Browse the repository at this point in the history
Facebook POST message using JSON and newer endpoint to support Emojis.
  • Loading branch information
Ben Brown authored Aug 13, 2016
2 parents 3837975 + 809cf5d commit 594a0bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/CoreBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ function Botkit(configuration) {
// set up a once a second tick to process messages
botkit.tickInterval = setInterval(function() {
botkit.tick();
}, 1000);
}, 1500);
}
};

Expand Down
35 changes: 19 additions & 16 deletions lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,35 @@ function Facebookbot(configuration) {
facebook_message.message.quick_replies = message.quick_replies;
}

request.post('https://graph.facebook.com/me/messages?access_token=' + configuration.access_token,
//Add Access Token to outgoing request

facebook_message.access_token = configuration.access_token;

request({
method: "POST",
json: true,
headers: {
"content-type": "application/json",
},
body: facebook_message,
uri: 'https://graph.facebook.com/v2.6/me/messages'
},
function(err, res, body) {
if (err) {
botkit.debug('WEBHOOK ERROR', err);
return cb && cb(err);
}

try {

var json = JSON.parse(body);

} catch (err) {

botkit.debug('JSON Parse error: ', err);
if (err) {
botkit.debug('WEBHOOK ERROR', err);
return cb && cb(err);

}

if (json.error) {
botkit.debug('API ERROR', json.error);
return cb && cb(json.error.message);
if (body.error) {
botkit.debug('API ERROR', body.error);
return cb && cb(body.error.message);
}

botkit.debug('WEBHOOK SUCCESS', body);
cb && cb(null, body);
}).form(facebook_message);
})
};

bot.reply = function(src, resp, cb) {
Expand Down

0 comments on commit 594a0bb

Please sign in to comment.