7.3.6.1 Facebook Messenger

To serve your chatbot through Facebook Messenger, you first need to set up a Facebook page and app to get credentials. Once you have them, you can add them to your credentials.yml.

How to get the Facebook credentials

You need to set up a Facebook app and a page.

  1. To create the app, head over to Facebook for Developers and click on My AppsAdd New App.

  2. Go onto the dashboard for the app, and under Products, find the Messenger section and click Set Up. Scroll down to Token Generation and click on the link to create a new page for your app.

  3. Create your page and select it in the dropdown menu for the Token Generation. The shown Page Access Token is the page-access-token needed later on.

  4. Locate the App Secret in the app dashboard under SettingsBasic. This will be your secret.

  5. Use the collected secret and page-access-token in your credentials.yml, and add a field called verify containing a string of your choice. Start Rasa run with the --credentials credentials.yml option.

  6. Set up a Webhook and select at least the messaging and messaging_postback subscriptions. Insert your callback URL, which will look like https://<host>:<port>/webhooks/facebook/webhook, replacing the host and port with the appropriate values from your running Rasa X or Rasa Open Source server.

  7. Insert the Verify token, which has to match the verify entry in your credentials.yml.

CONFIGURE HTTPS

Facebook Messenger only forwards messages to endpoints via https, so take appropriate measures to add it to your setup.

For more detailed steps, visit the Messenger docs.

To use https on localhost, please check: Setup HTTPS on localhost for testing the API/Channels

Running On Facebook Messenger

Add the Facebook credentials to your credentials.yml:

facebook:
verify: "rasa-bot"
secret: "<secret>"
page-access-token: "<token>"

Restart your Rasa X or Rasa Open Source server to make the new channel endpoint available for Facebook Messenger to send messages to.

Debugging

To check the activity on the webhook, we can see the nginx logs:

sudo docker-compose logs -f nginx

Try a message on messenger and you should be able to see the following:

nginx_1 | some_ip - - [09/Sep/2021:06:12:06 +0000] "POST /webhooks/facebook/webhook HTTP/1.1" 200 7 "-" "facebookexternalua" "-"

If you are not able to see a log like the one above, then the integration is not done properly, so we need to check the credentials and try again.

Making the bot available to public

With the above integration, the bot can only be tested by the test users. To make it public, we need to submit the application for App Review by requesting pages_messaging permission/feature. Furthermore, check out a sample submission here:

https://developers.facebook.com/docs/app-review/resources/sample-submissions/messenger-platform

Last updated