Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getUserProfile Permissions as Array #164

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ jspm_packages
examples/config/development.json
examples/config/production.json
.vscode/settings.json
.idea/
11 changes: 9 additions & 2 deletions lib/BootBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,17 @@ class BootBot extends EventEmitter {
/**
* Returns a Promise that contains the user's profile information.
* @param {String} userId
* @param {Array} permissions
* @returns {Promise}
*/
getUserProfile(userId) {
const url = `https://graph.facebook.com/${this.graphApiVersion}/${userId}?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=${this.accessToken}`;
getUserProfile(userId, permissions) {

const default_permissions = ['id','first_name', 'last_name', 'profile_pic']
const all_permissions = Array.from(new Set([...default_permissions, ...permissions]));

const permissions_str = all_permissions.join(',');
const url = `https://graph.facebook.com/${this.graphApiVersion}/${userId}?fields=${permissions_str}&access_token=${this.accessToken}`;

return fetch(url)
.then(res => res.json())
.catch(err => console.log(`Error getting user profile: ${err}`));
Expand Down
4 changes: 2 additions & 2 deletions lib/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class Chat extends EventEmitter {
/**
* Returns a Promise that contains the user's profile information.
*/
getUserProfile() {
return this.bot.getUserProfile(this.userId);
getUserProfile(permissions) {
return this.bot.getUserProfile(this.userId, permissions);
}

/**
Expand Down
Loading