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
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
10 changes: 5 additions & 5 deletions lib/facebook/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function fbSetup(api, bot, logError, optionalParser, optionalRe
stageName: lambdaDetails.alias
}).then(data => {
if (options['configure-fb-bot']) {
let token, pageAccessToken;
let token, pageAccessToken, pageID;

return Promise.resolve().then(() => {
if (data.variables && data.variables.facebookVerifyToken)
Expand All @@ -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`);


return prompt(['Facebook page access token', 'Facebook App Secret']);
return prompt(['Facebook page access token', 'Facebook App Secret', 'Facebook Page ID']);
})
.then(results => {
console.log('\n');
pageAccessToken = results['Facebook page access token'];
pageID = results['Facebook Page ID'];
const deployment = {
restApiId: lambdaDetails.apiId,
stageName: lambdaDetails.alias,
Expand All @@ -84,13 +85,12 @@ module.exports = function fbSetup(api, bot, logError, optionalParser, optionalRe
facebookAppSecret: results['Facebook App Secret']
}
};

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

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}`));

}
});
})
Expand Down