We already have a functioning bot from the last post. If you have not read it please follow the steps in it and build a working bot as this post is a follow up to it. What is the use of bot if it is not linked to any platform, so here we will integrate our bot to Facebook messenger and access it from messenger. Lets get started.
First we need to create a Facebook app. Go to Facebook Developer page and create a new app.
Go to “Add a product” and add Facebook messenger and you will be taken to the settings page of messenger.
You need to generate the Page Access Token. You can either create a new Facebook page or select an existing page(Make sure the page is not published if you are just testing).
Once you provide a page, page access token is generated.
Go to “Dashboard” and get the App Secret.
Thats all we need from Facebook for now.
Go to Amazon Lex console and go to settings tab and create an alias.
Go to the Channel taband choose Facebook channel.
Provide the name, description and the Alias you created in the settings.
Provide a random text as Verify Token. This will be used as authentication for the calls from Facebook. You need to provide the same Verify Token in Facebook.
Get the Page Access Token and App Secret key from Facebook app as mentioned and fill in them.
ClickActivate and a callback url should be generated for you.
Click Build and build the bot .
The settings should look something like below:
Now that we got the callback url we need to configure it in Facebook app we created.
Go to the Facebook app we created.
Copy the callback url from Lex and provide it in Webhook settings in messenger.
Provide the same Verify Tokenas you gave in Lex channel settings.
Provide the events messages, messaging_postbacks, messaging_optinsand verify and save.
Select the page and click on subscribe in the Webhook window to listen to chat from the page.
Go to Settings in your Facebook page.
Select Messenger Platform from the left tab.
You will see your Facebook app being listed there.
Set the role as Primary Receiver.
That’s it, now we are all set to chat with our bot. You can go to the Facebook page you created and click on Send Message to start chatting.
If all well well, Facebook messenger will be able to communicate with our Lex Bot and you will get response as below.
If you liked this story, feel free to reach out to me at Kaizen Coder.