Messenger from Facebook

Using the Dialogflow Facebook Messenger integration, you can create a Facebook Messenger bot to interact with your end-users.

How it works

This is how the integration works:

Setup

To set up the integration:

  1. Follow the steps to create a Facebook app: Facebook App Development.

  2. Set up the Facebook app to use the Facebook Messenger Platform. Follow steps in the Setting Up Your Facebook App documentation to accomplish the following:

    • Add the Messenger Platform to your Facebook app.
    • Subscribe your app to a Facebook page. You are provided with an access token at this step. Copy this value. This token will be used to configure the integration from the Dialogflow Console.
    • Do not configure the webhook or test your integration yet.
  3. Configure the integration from the Dialogflow Console:

    1. Go to the Dialogflow ES Console.
    2. Click Integrations in the left sidebar menu.
    3. Click Facebook Messenger.
    4. A configuration dialog opens:

      • Integration toggle: Use the integration toggle at the top of the dialog to enable the integration.
      • Show old callback URL: If this toggle is shown, it defaults to off. This is a temporary option to accommodate a recent modification to the Facebook Messenger API. Do not change this toggle unless instructed by Dialogflow support. Once all agents have been updated, this option will be removed.

      • Callback URL: Copy this value. This will be used to configure the Facebook Messenger Webhook.

      • Verify Token: You can enter any private token you desire. Copy this value. This will be used to configure the Facebook Messenger Webhook.

      • Page Access Token: Enter the access token you copied when creating the Facebook page.

      • Start: Click to start this integration service for your agent.

  4. Finish setup of the Facebook app and test it. Follow steps in the Setting Up Your Facebook App documentation to accomplish the following:

    • Configure the Facebook webhook for your app. Use the Callback URL and Verify Token values you copied above. Be sure to enable messages and messaging_postbacks.
    • Test your app.

Events

The following events are invoked by this integration:

Event Description
FACEBOOK_WELCOME Triggered when an end-user starts a conversation with your bot.

Rich response messages

This integration translates some rich response messages messages to Facebook Messenger Platform message types.

Image responses

Image responses are sent to Facebook Messenger as Facebook Messenger file attachment messages. The message.attachment.type value is set to image. The following formats are supported:

  • jpg
  • png
  • static gif
  • animated gif

Card responses

Card responses are sent to Facebook Messenger as Facebook Messenger generic templates.

Quick reply responses

Quick reply responses are sent to Facebook Messenger as Facebook Messenger quick replies.

Custom payload responses

To send other types of Facebook Messenger messages, you can use a custom payload.

The general format of the custom payload looks like:

{
  "facebook": {
    message
  }
}

In place of message, provide the Facebook Messenger message object. For details of the message object, see the Facebook Messenger API reference.

For example:

  • Send an audio link:
    {
      "facebook": {
        "attachment": {
          "type": "audio",
          "payload": {
            "url": "https://example.com/audio/test.mp3"
          }
        }
      }
    }
        
  • Send a playable video:
    {
      "facebook": {
        "attachment": {
          "type": "video",
          "payload": {
            "url": "https://example.com/video.mp4"
          }
        }
      }
    }
        
  • Send a file:
    {
      "facebook": {
        "attachment": {
          "type": "file",
          "payload": {
            "url": "https://example.com/file.pdf"
          }
        }
      }
    }