Skip to content

Commit

Permalink
fix(messenger): made profiles fields option for FB (resolve #829)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Paniontko authored and epaminond committed Sep 28, 2018
1 parent ebf12f4 commit ed74212
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/channels/botpress-channel-messenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ npm i @botpress/channel-messenger

`"greetingMessage"` - set default messege. `Default: "Default greeting message"`

`"enableAllProfileFields"` - If you need to know user timezone, gender, locale set `true` and send you app to review.

<img alt='Greeting Message' src='assets/greeting-message-example.png' width='300px !important;' />

`"persistentMenu"` - added menu to your messenger. [See more](https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu)
Expand Down
1 change: 1 addition & 0 deletions packages/channels/botpress-channel-messenger/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

"graphVersion": "2.12",
"enabled": true,
"enableAllProfileFields": false, // To be able to fetch all profile fields you need to submit your application for FB review

"displayGetStarted": true,
"greetingMessage": "Default greeting message",
Expand Down
1 change: 1 addition & 0 deletions packages/channels/botpress-channel-messenger/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = {
appSecret: { type: 'string', required: true, default: '', env: 'MESSENGER_APP_SECRET' },
verifyToken: { type: 'string', required: false, default: '', env: 'MESSENGER_VERIFY_TOKEN' },
enabled: { type: 'bool', required: true, default: true },
enableAllProfileFields: { type: 'bool', required: true, default: false },
hostname: { type: 'string', required: false, default: '', env: 'MESSENGER_HOST' },

graphVersion: { type: 'string', required: true, default: '2.12' },
Expand Down
9 changes: 7 additions & 2 deletions packages/channels/botpress-channel-messenger/src/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ class Messenger extends EventEmitter {

getUserProfile(userId) {
const token = this.config.accessToken
const url = `https://graph.facebook.com/v${this.config
.graphVersion}/${userId}?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=${token}`
const profileFields = ['first_name', 'last_name', 'profile_pic'].concat(
this.config.enableAllProfileFields ? ['locale', 'timezone', 'gender'] : []
)
const url = `https://graph.facebook.com/v${this.config.graphVersion}/${userId}?fields=${profileFields.join(
','
)}&access_token=${token}`

return fetch(url)
.then(this._handleFacebookResponse)
.then(res => res.json())
Expand Down

0 comments on commit ed74212

Please sign in to comment.