Menu
Amazon Lex
Developer Guide

Integrating an Amazon Lex Bot with Facebook Messenger

This exercise shows how to integrate Facebook Messenger with your Amazon Lex bot. You perform the following steps:

  1. Create an Amazon Lex bot

  2. Create a Facebook application

  3. Integrate Facebook Messenger with your Amazon Lex bot

  4. Validate the integration

Step 1: Create an Amazon Lex Bot

If you don't already have an Amazon Lex bot, create and deploy one. In this topic, we assume that you are using the bot that you created in Getting Started Exercise 1. However, you can use any of the example bots provided in this guide. For Getting Started Exercise 1, see Exercise 1: Create an Amazon Lex Bot Using a Blueprint (Console).

  1. Create an Amazon Lex bot. For instructions, see Exercise 1: Create an Amazon Lex Bot Using a Blueprint (Console).

  2. Deploy the bot and create an alias. For instructions, see Exercise 3: Publish a Version and Create an Alias.

Step 2: Create a Facebook Application

On the Facebook developer portal, create a Facebook application and a Facebook page. For instructions, see Quick Start in the Facebook Messenger platform documentation. Write down the following:

  • The App Secret for the Facebook App

  • The Page Access Token for the Facebook page

Step 3: Integrate Facebook Messenger with the Amazon Lex Bot

In this section, you integrate Facebook Messenger with your Amazon Lex bot.

After you complete this step, the console provides a callback URL. Write down this URL.

To integrate Facebook Messenger with your bot

    1. Sign in to the AWS Management Console and open the Amazon Lex console at https://console.aws.amazon.com/lex/.

    2. Choose your Amazon Lex bot.

    3. Choose Channels.

    4. Choose Facebook under Chatbots. The console displays the Facebook integration page.

    5. On the Facebook integration page, do the following:

      • Type the following name: BotFacebookAssociation.

      • For KMS key, choose aws/lex .

      • For Alias, choose the bot alias.

      • For Verify token, type a token. This can be any string you choose (for example, ExampleToken). You use this token later in the Facebook developer portal when you set up the webhook.

      • For Page access token, type the token that you obtained from Facebook in Step 2.

      • For App secret key, type the key that you obtained from Facebook in Step 2.

    6. Choose Activate.

      The console creates the bot channel association and returns a callback URL. Write down this URL.

  1. On the Facebook developer portal, choose your app.

  2. Choose the Messenger product, and choose Setup webhooks in the Webhooks section of the page.

    For instructions, see Quick Start in the Facebook Messenger platform documentation.

  3. On the webhook page of the subscription wizard, do the following:

    • For Callback URL, type the callback URL provided in the Amazon Lex console earlier in the procedure.

    • For Verify Token, type the same token that you used in Amazon Lex.

    • Choose Subscription Fields (messages, messaging_postbacks, and messaging_optins).

    • Choose Verify and Save. This initiates a handshake between Facebook and Amazon Lex.

  4. Enable Webhooks integration. Choose the page that you created, and then choose subscribe.

    Note

    If you update or recreate a webhook, unsubscribe and then resubscribe to the page.

Step 4: Test the Integration

You can now start a conversation from Facebook Messenger with your Amazon Lex bot.

  1. Open your Facebook page, and choose Message.

  2. In the Messenger window, use the same test utterances provided in Step 1: Create an Amazon Lex Bot (Console).