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

Facebook Messenger v3.2 Fix #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

prathmj
Copy link

@prathmj prathmj commented Apr 9, 2019

(I can add more information to a README PR for set up purposes). The main change here is that Facebook has changed the URL of the POST request you need in order to setup a FB messenger chat bot. You will recall that when setting up a Facebook app and creating the webhook, you had to subscribe to certain fields. All you need for the chatbot to function is the "messages" field. In v3.2 of the Facebook Graph API, you now had to explicitly send FB, in the POST request, what fields you were planning on subscribing to. That is why 'messages' is now hard-coded into line 95. This POST request also required that you put the "pageID" of the Facebook page your chatbot was going to message from (the same page you got your Page Access Token from). This is either available in the settings of your Facebook page, or by viewing the source of the Facebook page and looking for the variable called "pageID".

Another weird addition is that chatbots now require a permission called "manage_pages". You can't actually give your FB app and chatbot the manage_pages permission from the main developer console. Instead, you need to go to this link: https://developers.facebook.com/tools/explorer/?classic=0 and from there choose your page, and add a new permission of "manage_pages".

(I can add more information to a README PR for set up purposes). The main change here is that Facebook's v3.2 Graph API has changed the URL of the POST request you need in order to setup a FB messenger chat bot. You will recall that when setting up a Facebook app and creating the webhook, you had to subscribe to certain fields. All you need for the chatbot to function is the "messages" field. In v3.2 of the Facebook Graph API, you now had to explicitly send FB, in the POST request, what fields you were planning on subscribing to. That is why 'messages' is now hard-coded into line 95. This POST request also required that you put the "pageID" of the Facebook page your chatbot was going to message from (the same page you got your Page Access Token from). This is either available in the settings of your Facebook page, or by viewing the source of the Facebook page and looking for the variable called "pageID".

Another weird addition is that chatbots now require a permission called "manage_pages". You can't actually give your FB app and chatbot the manage_pages permission from the main developer console. Instead, you need to go to this link: https://developers.facebook.com/tools/explorer/?classic=0 and from there choose your page, and add a new permission of "manage_pages".
Reposting this commit because syntax differences caused Travis to fail on the last one. 
(I can add more information to a README PR for set up purposes). The main change here is that Facebook has changed the URL of the POST request you need in order to setup a FB messenger chat bot. You will recall that when setting up a Facebook app and creating the webhook, you had to subscribe to certain fields. All you need for the chatbot to function is the "messages" field. In v3.2 of the Facebook Graph API, you now had to explicitly send FB, in the POST request, what fields you were planning on subscribing to. That is why 'messages' is now hard-coded into line 95. This POST request also required that you put the "pageID" of the Facebook page your chatbot was going to message from (the same page you got your Page Access Token from). This is either available in the settings of your Facebook page, or by viewing the source of the Facebook page and looking for the variable called "pageID".

Another weird addition is that chatbots now require a permission called "manage_pages". You can't actually give your FB app and chatbot the manage_pages permission from the main developer console. Instead, you need to go to this link: https://developers.facebook.com/tools/explorer/?classic=0 and from there choose your page, and add a new permission of "manage_pages".
Copy link
Member

@stojanovic stojanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! As they have multiple changes to the platform, we might need to add additional info to our README, but I'll try to create a demo project and see if anything is missing from a README file.

@@ -69,13 +69,14 @@ module.exports = function fbSetup(api, bot, logError, optionalParser, optionalRe
console.log(`\n\n${color.green}Facebook Messenger setup${color.reset}\n`);
console.log(`\nFollowing info is required for the setup, for more info check the documentation.\n`);
console.log(`\nYour webhook URL is: ${color.cyan}${lambdaDetails.apiUrl}/facebook${color.reset}\n`);
console.log(`Your verify token is: ${color.cyan}${token}${color.reset}\n`);
console.log(` fda Your verify token is: ${color.cyan}${token}${color.reset}\n`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is fda?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought I deleted this in the second commit. Just a typo! That shouldn't be there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this - done!

if (!data.variables || (!data.variables.facebookAppSecret && !results['Facebook App Secret']))
console.log(`\n${color.yellow}Deprecation warning:${color.reset} your bot is not using facebook validation. Please re-run with --configure-fb-bot to set it. This will become mandatory in the next major version. See https://github.com/claudiajs/claudia-bot-builder/blob/master/docs/API.md#message-verification for more information.\n`);

return utils.apiGatewayPromise.createDeploymentPromise(deployment);
})
.then(() => rp.post(`https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=${pageAccessToken}`));
.then(() => rp.post(`https://graph.facebook.com/v3.2/${pageID}/subscribed_apps?subscribed_fields=['messages']&access_token=${pageAccessToken}`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other values for subscribed_fields that users might use? If yes, maybe we can set a default value to 'messages' and ask users if they want to provide any additional ones.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is a messages received value that users might be interested in? In case they are creating logs as to how many people click on their messages. The first answer here has all of them:
https://stackoverflow.com/questions/53778224/how-to-solve-the-parameter-subscribed-fields-is-required-error-while-subscribi

@@ -69,13 +69,14 @@ module.exports = function fbSetup(api, bot, logError, optionalParser, optionalRe
console.log(`\n\n${color.green}Facebook Messenger setup${color.reset}\n`);
console.log(`\nFollowing info is required for the setup, for more info check the documentation.\n`);
console.log(`\nYour webhook URL is: ${color.cyan}${lambdaDetails.apiUrl}/facebook${color.reset}\n`);
console.log(`Your verify token is: ${color.cyan}${token}${color.reset}\n`);
console.log('\nYour verify token is: ${color.cyan}${token}${color.reset}\n`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis build is failing with 'unterminated string' due to the mismatch between the opening quote and closing back-tick.

Suggested change
console.log('\nYour verify token is: ${color.cyan}${token}${color.reset}\n`);
console.log(`\nYour verify token is: ${color.cyan}${token}${color.reset}\n`);

if (!data.variables || (!data.variables.facebookAppSecret && !results['Facebook App Secret']))
console.log(`\n${color.yellow}Deprecation warning:${color.reset} your bot is not using facebook validation. Please re-run with --configure-fb-bot to set it. This will become mandatory in the next major version. See https://github.com/claudiajs/claudia-bot-builder/blob/master/docs/API.md#message-verification for more information.\n`);

return utils.apiGatewayPromise.createDeploymentPromise(deployment);
})
.then(() => rp.post(`https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=${pageAccessToken}`));
.then(() => rp.post(`https://graph.facebook.com/v3.2/${pageID}/subscribed_apps?subscribed_fields=['messages']&access_token=${pageAccessToken}`));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Minimum Graph API version for new Messenger apps is 5.0.
  • I think 'subscribed_fields' should include 'messaging_postbacks' by default; postback buttons, the 'Get Started' button and persistent menus all use this field.
Suggested change
.then(() => rp.post(`https://graph.facebook.com/v3.2/${pageID}/subscribed_apps?subscribed_fields=['messages']&access_token=${pageAccessToken}`));
.then(() => rp.post(`https://graph.facebook.com/v5.0/${pageID}/subscribed_apps?subscribed_fields=['messages','messaging_postbacks']&access_token=${pageAccessToken}`));

@vitualizz
Copy link

Ward 🇵🇪

@nLight
Copy link

nLight commented Oct 30, 2020

Can I somehow support the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants