Bots are becoming an important part of our lifestyle. Let's look into how to build one. We have a good number of platform choices for building a bot. However, each has its pros, cons and we’ll be discussing integration details on how to build a bot using Lex and export it onto the Facebook Messenger Platform.
Please look into AWS docs and the following tutorial. AWS docs are very good and complete to get your Lex bot running. AWS Lex uses Lambda as its core engine to handle the bot's intelligence.
Follow AWS Docs. It explains very neatly how to hook up the messenger platform to your Lex chatbot. However, the Lex bot cannot start a conversation.
If any of the use cases excite you, you are at the right place and can go forward to read the complete tutorial.
After following the above tutorials, you should be able to picture the flow similar to the diagram below.
FB Permissions and Webhooks Required
Let's get familiar with a few terms.
Lot of the terms don’t make sense at the start, but eventually they would. So let's look at our challenges for recognizing a user from your page on Facebook.
We need to identify the user. FB identifies every user with a unique UID. We need to store these credentials during the person's FB Login. However, FB sends PSID to identify a user to the Lex bot, Lambda which is eventually received by your server. To recognize the user, you would need to find a match between PSID and UID. This can be done using the following steps at the time of login on your server.
Given values at time of login are UID, Page ID, App Secret, and User Access Token (UAT).
Pictorially…
By following and implementing the above four APIs, you will be able to obtain the PSID of every user at the time of login. When queried from Lambda using PSID, it should be easy to identify the user and provide a seamless experience.
Coming to using SEND API. You would need Page Access Token and PSID (Page Scoped Identity). Since we have obtained both of them at the time of login, they can be used for pinging the user when required. We would need pages_messaging_subscription for pinging users randomly at any time. You would need to submit for a review to Facebook stating your purpose of requiring such a permission. If the FB team feels it's a valid use case, they would grant the permission.
For example @Yatis, we provide IoT solutions primarily in the automobile industry. We have a feature where any user can communicate with his/her vehicle remotely using the Yatis App. With the advance in chatbot technology, we are able to provide the same features by just chatting with our page. Pinging the user when the vehicle has crossed a geofence required pages_messaging_subscriptionpermission as it could be anytime out of the 24 hr window, rest of the features required just pages_messagingpermission only.
All the best, hope the tutorial was of good help. I have spent a lot of time researching different pages and figuring things out.