Facebook Messenger

You are viewing documentation for our open source project which is maintained by the community. If you want to get started building assistants with Rasa please check out our latest documentation here.

Facebook Setup

You first need to set up a facebook page and app to get credentials to connect to Facebook Messenger. Once you have them you can add these to your credentials.yml.

Getting Credentials

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 Apps → Add 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 Settings → Basic. 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 server.

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 local testing of your bot, see Testing Channels on Your Local Machine.

For more detailed steps, visit the Messenger docs.

Running On Facebook Messenger

Add the Facebook credentials to your credentials.yml:

facebook:
  verify: "rasa-bot"
  secret: "3e34709d01ea89032asdebfe5a74518"
  page-access-token: "EAAbHPa7H9rEBAAuFk4Q3gPKbDedQnx4djJJ1JmQ7CAqO4iJKrQcNT0wtD"

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

Supported response attachments

In addition to typical text, image, and custom responses, the Facebook Messenger channel supports the following additional response attachments:

  utter_fb_quick_reply_example:
    - text: Hello World!
      quick_replies:
        - title: Text quick reply
          payload: /example_intent
        - title: Image quick reply
          payload: /example_intent
          image_url: http://example.com/img/red.png

Both Quick Reply and Button titles in Facebook Messenger have a character limit of 20. Titles longer than 20 characters will be truncated.

  utter_fb_element_example:
    - text: Hello World!
      elements:
        - title: Element Title 1
          subtitle: Subtitles are supported
          buttons:
            - title: Example button A
              payload: /example_intent
            - title: Example button B
              payload: /example_intent
            - title: Example button C
              payload: /example_intent
        - title: Element Title 2
          image_url: http://example.com/img/red.png
          buttons:
            - title: Example button D
              payload: /example_intent
            - title: Example button E
              payload: /example_intent
            - title: Example button F
              payload: /example_intent