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

Added 'picture' to Facebook User Profile endpoint. #1264

Closed
wants to merge 1 commit into from
Closed
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
46 changes: 21 additions & 25 deletions lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -242,6 +242,7 @@ function Facebookbot(configuration) {
email: identity.email || null,
gender: identity.gender,
timezone_offset: identity.timezone,
picture: identity.picture
};

if (cb) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1574,4 +1570,4 @@ function Facebookbot(configuration) {
return facebook_botkit;
};

module.exports = Facebookbot;
module.exports = Facebookbot;