From f96c4cc864077f22d3dc7ddab5fc83c3d195b20e Mon Sep 17 00:00:00 2001 From: se Date: Sat, 24 Feb 2018 12:24:13 +0300 Subject: [PATCH] Added 'picture' to Facebook User Profile endpoint. --- lib/Facebook.js | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/lib/Facebook.js b/lib/Facebook.js index 9e68aa731..612c313d3 100644 --- a/lib/Facebook.js +++ b/lib/Facebook.js @@ -28,7 +28,7 @@ function Facebookbot(configuration) { facebook_botkit.middleware.format.use(function(bot, message, platform_message, next) { platform_message.recipient = {}; - platform_message.message = message.sender_action ? undefined : {}; + platform_message.message = message.sender_action ? undefined : {}; if (typeof(message.channel) == 'string' && message.channel.match(/\+\d+\(\d\d\d\)\d\d\d\-\d\d\d\d/)) { platform_message.recipient.phone_number = message.channel; @@ -124,14 +124,14 @@ function Facebookbot(configuration) { } request({ - method: 'POST', - json: true, - headers: { - 'content-type': 'application/json', + method: 'POST', + json: true, + headers: { + 'content-type': 'application/json', + }, + body: message, + uri: 'https://' + api_host + '/' + api_version + '/me/messages' }, - body: message, - uri: 'https://' + api_host + '/' + api_version + '/me/messages' - }, function(err, res, body) { if (err) { @@ -242,6 +242,7 @@ function Facebookbot(configuration) { email: identity.email || null, gender: identity.gender, timezone_offset: identity.timezone, + picture: identity.picture }; if (cb) { @@ -282,8 +283,7 @@ function Facebookbot(configuration) { uri += '&appsecret_proof=' + appsecret_proof; } - request.get(uri, - {}, + request.get(uri, {}, function(err, res, body) { if (err) { if (cb) cb(err); @@ -401,7 +401,7 @@ function Facebookbot(configuration) { // in case of Checkbox Plug-in sender.id is not present, instead we should look at optin.user_ref if (!message.sender && message.optin && message.optin.user_ref) { - message.sender = {id: message.optin.user_ref}; + message.sender = { id: message.optin.user_ref }; } // capture the user ID @@ -513,11 +513,11 @@ function Facebookbot(configuration) { // loop through all active conversations this bot is having // and mark messages in conversations as delivered = true // note: we don't pass the real event in here because message_delivered events are excluded from conversations and won't ever match! - bot.findConversation({user: message.user}, function(convo) { + bot.findConversation({ user: message.user }, function(convo) { if (convo) { for (var s = 0; s < convo.sent.length; s++) { if (convo.sent[s].sent_timestamp <= message.delivery.watermark || - (convo.sent[s].api_response && convo.sent[s].api_response.message_id == mid)) { + (convo.sent[s].api_response && convo.sent[s].api_response.message_id == mid)) { convo.sent[s].delivered = true; } } @@ -534,7 +534,7 @@ function Facebookbot(configuration) { // Validate that requests come from facebook, and abort on validation errors if (facebook_botkit.config.validate_requests === true) { // Load verify middleware just for post route on our receive webhook, and catch any errors it might throw to prevent the request from being parsed further. - webserver.post('/facebook/receive', bodyParser.json({verify: verifyRequest})); + webserver.post('/facebook/receive', bodyParser.json({ verify: verifyRequest })); webserver.use(abortOnValidationError); } @@ -643,8 +643,7 @@ function Facebookbot(configuration) { uri += '&appsecret_proof=' + appsecret_proof; } - request.post(uri, - {form: message}, + request.post(uri, { form: message }, function(err, res, body) { if (err) { facebook_botkit.log('Could not configure messenger profile'); @@ -678,8 +677,7 @@ function Facebookbot(configuration) { uri += '&appsecret_proof=' + appsecret_proof; } - request.delete(uri, - {form: message}, + request.delete(uri, { form: message }, function(err, res, body) { if (err) { facebook_botkit.log('Could not configure messenger profile'); @@ -719,14 +717,13 @@ function Facebookbot(configuration) { }; if (ref) { - message.data = {'ref': ref}; + message.data = { 'ref': ref }; } if (facebook_botkit.config.require_appsecret_proof) { uri += '&appsecret_proof=' + appsecret_proof; } - request.post(uri, - {form: message}, + request.post(uri, { form: message }, function(err, res, body) { if (err) { facebook_botkit.log('Could not configure get messenger code'); @@ -778,8 +775,7 @@ function Facebookbot(configuration) { uri += '&appsecret_proof=' + appsecret_proof; } - request.post(uri, - { form: message }, + request.post(uri, { form: message }, function(err, res, body) { if (err) { facebook_botkit.log('Could not upload attachment'); @@ -908,7 +904,7 @@ function Facebookbot(configuration) { var user_profile = function(uid, fields, cb) { if (!fields) { - fields = 'first_name,last_name,timezone,gender,locale,email'; + fields = 'first_name,last_name,timezone,gender,locale,email,picture'; } return new Promise(function(resolve, reject) { var uri = 'https://' + api_host + '/' + api_version + '/' + uid + '?fields=' + fields + '&access_token=' + configuration.access_token; @@ -1574,4 +1570,4 @@ function Facebookbot(configuration) { return facebook_botkit; }; -module.exports = Facebookbot; +module.exports = Facebookbot; \ No newline at end of file