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

Facebook POST message using JSON and newer endpoint to support Emojis. #317

Merged
merged 5 commits into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

@anonrig anonrig Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason to change the interval to 1500 ms?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out you can revert this as I don’t think it makes a difference. Basically the issue with the framework with Facebook is that if you send 2 or 3 messages, and one of them is an image for some reason it will come out of order. It’s something with facebooks queue on the backend. So i think what needs to happen is to wait in between messages before sending

Tom Kornblit

On Jul 17, 2016, at 8:44 PM, Yagiz Nizipli notifications@github.com wrote:

In lib/CoreBot.js #317 (comment):

@@ -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);
    
    Is there a particular reason to change the setInterval method to 1500 ms?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/howdyai/botkit/pull/317/files/809cf5d21ca7ca7ba5f4168cda8fb58ec0eb723c#r71093302, or mute the thread https://github.com/notifications/unsubscribe-auth/AB7b-SlWA9071Oinid5i1DBWlSJPN4ZDks5qWsxvgaJpZM4JI56v.

}
};

Expand Down
35 changes: 19 additions & 16 deletions lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use JSDoc for documentation purposes.


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