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 https://www.facebook.com/ 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:
https://www.facebook.com/Connect-Amazon-Lex-to-Messenger-416539788894331/

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 https://developers.facebook.com/apps/ 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:
f11ea12fd6a7f81598f0bbcf09cb533d

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:
EAAczTZAAnLqkBADJoZB7MXuZBRZB2uwbozPKX57DF4N3cXcxUKRMqxFG3NNGLRukqk0DBZAUpE5JOnfdaBGU7sqFZB37JYepZBT9JR4B74FuY3yWfKE1X7ffKMiektd3nGp4ZBINhU98DC0G8gg5JCivqOYxaESavcfZAGBrUUCvi3AZDZD

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 https://console.aws.amazon.com/lex/. 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:
    EAAczTZAAnLqkBADJoZB7MXuZBRZB2uwbozPKX57DF4N3cXcxUKRMqxFG3NNGLRukqk0DBZAUpE5JOnfdaBGU7sqFZB37JYepZBT9JR4B74FuY3yWfKE1X7ffKMiektd3nGp4ZBINhU98DC0G8gg5JCivqOYxaESavcfZAGBrUUCvi3AZDZD
  • For App Secret Key, type the key that you obtained in Step 3. Example:
    f11ea12fd6a7f81598f0bbcf09cb533d

Click Activate button:

Cope and save Endpoint URL. Example:
https://channels.lex.eu-west-1.amazonaws.com/facebook/webhook/1d862eed-c141-44cf-9056-f870197d1d9a

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:
https://channels.lex.eu-west-1.amazonaws.com/facebook/webhook/1d862eed-c141-44cf-9056-f870197d1d9a
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:
https://www.facebook.com/Connect-Amazon-Lex-to-Messenger-416539788894331/

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.

Via: https://chatbotslife.com/lex-to-messenger-f0049ee1e8e9

0
0

No Comments Yet.

What do you think?

Your email address will not be published. Required fields are marked *