-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add Facebook insights API #1183
Add Facebook insights API #1183
Conversation
lib/Facebook.js
Outdated
uri: uri | ||
}, function (err, res, body) { | ||
if (err) { | ||
facebook_botkit.log('Could call Facebook Insights API'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this log message is wrong.
Also logging err.message helps with debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch 👍
} else { | ||
if (body.error) { | ||
facebook_botkit.log('ERROR in Facebook Insights API call: ', body.error.message); | ||
cb(body.error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
body.error is not an instance of Error, is it?
If it isn't, then it would probably be better to use cb(new Error(body.error.message));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not, body.error
is the error object returned by FB, it contains other useful data than message.
If we call the callback with an error object and juste the message, we couldn't use those useful data (code, ...).
examples/facebook_bot.js
Outdated
@@ -488,6 +488,11 @@ controller.hears(['send tagged message'], 'message_received', function (bot, mes | |||
bot.reply(message, taggedMessage); | |||
}); | |||
|
|||
controller.hears(['insights'], 'message_received', function (bot, message) { | |||
controller.api.insights.get_insights(['page_messages_active_threads_unique', 'page_messages_blocked_conversations_unique'], null, null, function (err, body) { | |||
bot.reply(message, JSON.stringify(body.data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit of error handling would be nice here, especially because many people use examples with little modification.
body can be undefined, if that's the case then accessing body.data would throw an error.
if (err) {
bot.reply(message, 'Insights error');
} else {
bot.reply(message, JSON.stringify(body.data));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks nice, done 👍
be3fb6d
to
85ae1c9
Compare
@Naktibalda thanks for the review 👍 |
Hello,
This PR add the new FB insights API to the awesome Botkit.
Fix #1126
Enjoy