How to create Lex bot to Facebook Messenger?


Amazon Lex empowers you to rapidly fabricate a chatbot in no time flat. A couple of months back, I endeavored to coordinate a Lex chatbot with Facebook — and spent too long in light of the poor documentation and direction. Need help? Call us today!

Table of Contents

  • Step 1: Create a Facebook page
  • Step 2: Create a Facebook developer account
  • Step 3: Create and configure the Facebook app
  • Step 4: Configure AWS Lex bot
  • Step 5: Configure Facebook app webhook
  • Step 6: Test

Step 1: Create a Facebook page

If you don’t already have a Facebook page, create one.

Navigate to and select Create menu. Select Page:

Choose Facebook page category. For example Community or Public Figure. Click Get Started:

Enter Page Name (e.g. Connect Amazon Lex to Messenger). Select Category(e.g. Education Website). Click Continue button:

Click Skip button. Click Skip button.

Copy and save link to your new Facebook page. Example:

Do not close the browser tab with Facebook page. We will test Amazon Lex bot here later.

Step 2: Create a Facebook developer account

If you don’t already have a Facebook developer account, create one.

Open Getting Started docs and click Create Developer Account button:

Click Next button. Click Next button. Select Student.

Top 4 Bot Tutorials

1. Chatbot Conference 2019 in NYC

2. Best chatbot platforms to build a chatbot

3. Build simple ChatBot in Python with RASA — Part 1

4. Build a simple ChatBot in Python with RASA — Part 2

Step 3: Create and configure the Facebook app

Navigate to and click Add a New Appbutton:

Enter Display Name (e.g. Medium). Click Create App ID button:

Click Skip button:

Find App Secret. Click Show button and copy App Secret. Example:

Copy and save your App Secret.

Navigate to PRODUCTS and click plus button.

Find Messenger and click Set Up button:

Navigate to Access Tokens section. Select you Facebook page (e.g. Connect Amazon Lex to Messenger). Click Edit Permissions button:

Select your Facebook page (e.g. Connect Amazon Lex to Messenger) and click Next. Select all options and click Done button:

Click OK. Navigate to Access Tokens section again and copy Page Access Token. Example:

Copy and save your Page Access Token.

Do not close the browser tab. We will configure Webhooks the section here later.

Step 4: Configure AWS Lex bot

Sign in to the AWS Management Console and open the Amazon Lex console at Choose your Amazon Lex bot. Select Channels tab. Select Facebook subtab. The console displays the Facebook integration page.

On the Facebook integration page, do the following:

  • Type the following name: BotFacebookAssociation.
  • For KMS Key, select aws/lex .
  • For Alias, choose the bot alias (e.g. BETA).
  • For Verify Token, type a token. This can be any string you choose (e.g. MediumToken). You use this token later in the Facebook developer portal when you set up the Webhooks.
  • For Page Access Token, type the token that you obtained in Step 3. Example:
  • For App Secret Key, type the key that you obtained in Step 3. Example:

Click Activate button:

Cope and save Endpoint URL. Example:

You can close the browser tab with Amazon Lex bot.

Step 5: Configure Facebook app webhook

Navigate back to your tab with Facebook app (e.g. Connect Amazon Lex to Messenger).

Navigate to Webhooks section in PRODUCTS-Messenger-Settings. Click Subscribe To Events button:

For Callback URL, type the Endpoint URL provided in the Amazon Lex console earlier in Step 4. Example:
For Verify Token, type the same token that you used in Amazon Lex in Step 4 (e.g. MediumToken). Choose Subscription Fields (messagesmessaging_postbacks, and messaging_optins). Click Verify and Savebutton:

In Webhooks section select your Facebook page (e.g. Connect Amazon Lex to Messenger) and click Subscribe button:

You can close browser tab with Facebook app.

Step 6: Test

Navigate back to your browser tab Facebook page. Example:

Select View as Page Visitor option:

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

You can test my PizzaOrderingBot here.


0/5 (0 Reviews)

No Comments Yet.

What do you think?

Your email address will not be published.