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:

  • Create an Amazon Lex bot.

  • Integrate Facebook Messenger with your Amazon Lex bot.

Step 1: Create an Amazon Lex Bot

In this section, you create an Amazon Lex bot.

  1. Create an Amazon Lex bot. For instructions, see Getting Started with Amazon Lex.

  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:

  • App Secret for the Facebook App.

  • 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.

  1. Open the Amazon Lex console, and then associate Facebook Messenger with your Amazon Lex bot.

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

    1. Choose your Amazon Lex bot.

    2. Choose the Channels tab.

    3. Choose Facebook under For Chatbots. The console displays the Facebook integration page.

    4. On the Facebook integration page, provide the following information:

      • Type a name: BotFacebookAssociation

      • Choose "aws/lex" from the KMS key drop-down.

      • Choose the bot alias from the drop-down.

      • Type the verify token. This can be any string you choose (for example, ExampleToken). You use this same token in the Facebook developer portal in the Webhook setup step.

      • Type the page access token and the app secret key you obtained from Facebook in the preceding step.

    5. Choose Activate.

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

  2. On the Facebook developer portal, choose your app. Then, select 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.

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

    • For Callback URL, type the callback URL provided in the Amazon Lex console in the preceding section.

    • 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 results in a handshake between Facebook and Amazon Lex.

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

    Note

    If you update or recreate a webhook, you must unsubscribe and then subscribe to the page again.

Step 4: Test the Integration

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

  1. Open your Facebook page and choose, Message.

  2. In the Messenger window that opens, use the same test utterances provided in getting started with your Amazon Lex bot.