Skip to content

Commit

Permalink
Add Graph API version option to BootBot constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lehainam-dev committed Oct 28, 2018
1 parent c2adc78 commit 575feaa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Then use the provided HTTPS URL to config your webhook on Facebook's Dashboard.
| `appSecret` | string | | `Y` |
| `webhook` | string | `"/webhook"` | `N` |
| `broadcastEchoes` | boolean | `false` | `N` |
| `graphApiVersion` | string | `v2.12` | `N` |

Creates a new `BootBot` instance. Instantiates the new express app and all required webhooks. `options` param must contain all tokens and app secret of your Facebook app. Optionally, set `broadcastEchoes` to `true` if you want the messages your bot send to be echoed back to it (you probably don't need this feature unless you have multiple bots running on the same Facebook page).

Expand Down
6 changes: 4 additions & 2 deletions lib/BootBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BootBot extends EventEmitter {
* @param {String} options.appSecret
* @param {String} [options.webhook=/webhook]
* @param {Boolean} [options.broadcastEchoes=false]
* @param {String} [options.graphApiVersion=v2.12]
*/
constructor(options) {
super();
Expand All @@ -28,6 +29,7 @@ class BootBot extends EventEmitter {
this.verifyToken = options.verifyToken;
this.appSecret = options.appSecret;
this.broadcastEchoes = options.broadcastEchoes || false;
this.graphApiVersion = options.graphApiVersion || 'v2.12';
this.app = express();
this.webhook = options.webhook || '/webhook';
this.webhook = this.webhook.charAt(0) !== '/' ? `/${this.webhook}` : this.webhook;
Expand Down Expand Up @@ -270,7 +272,7 @@ class BootBot extends EventEmitter {
sendRequest(body, endpoint, method) {
endpoint = endpoint || 'messages';
method = method || 'POST';
return fetch(`https://graph.facebook.com/v2.12/me/${endpoint}?access_token=${this.accessToken}`, {
return fetch(`https://graph.facebook.com/${this.graphApiVersion}/me/${endpoint}?access_token=${this.accessToken}`, {
method,
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -334,7 +336,7 @@ class BootBot extends EventEmitter {
* @returns {Promise}
*/
getUserProfile(userId) {
const url = `https://graph.facebook.com/v2.12/${userId}?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=${this.accessToken}`;
const url = `https://graph.facebook.com/${this.graphApiVersion}/${userId}?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=${this.accessToken}`;
return fetch(url)
.then(res => res.json())
.catch(err => console.log(`Error getting user profile: ${err}`));
Expand Down

0 comments on commit 575feaa

Please sign in to comment.