Chatbot using Amazon Lex - Reserve a table
Chat bots or conversational UI is very much discussed topic these days and many developers are exploring different options for building these intelligent bots.
A chatbot uses AI to understand natural language input either text or voice and then respond automatically to the user without any manual intervention.
There are many platforms available which allow you to build these bots. Below are the major bot maker platforms in my opinion-
- Google's API.ai
- Facebook’s Wit.ai
- Microsoft’s LUIS
- IBM’s Watson Dialog Service
- Amazon Lex
The Amazon Lex is a new entrant in this space but more importantly it supports a voice interface as well which is based on the same Alexa skills voice platform. I have not explored other bot frameworks yet and can not comment how these bot frameworks compare to each other.
Bot for booking a table in a restaurant-
I did try the Amazon Lex API recently to build a sample bot for booking a table in a restaurant.
A developer who has experience in developing Alexa skills should be able to develop bots easily on Lex as it uses the same conversational model definition and theAmazon Lambda (serverless function framework) for backend interaction with your services.
To build a bot using Lex you need to create a bot in Amazon Lex console and then define the various user intents (an action which user wants to perform). You need to define the slot types of your intent.
Below screenshot shows the different slots I have created for booking a table bot-
The Lex will go through each of the slot definitions to get the valid context from the user and store it in the conversation session attributes. You can also add some sample user prompts in each slot definition which is used by Lex for training the bot.
Whenever, the bot elicit a slot it can make a call to backend Amazon lambda function to validate the user input and if validation fails you can program the lambda function to elicit the slot again or else you can delegate the call to the next slot. The basic trivial validation is already handled by Lex for inbuilt slot types. Like if you enter a date for booking a table ( for slot type Amazon.DATE ) and the user enters a numeric value or non-date string in his input then Lex will automatically ask the user to submit the response again.
The sample code for this bot is available here - https://github.com/kunalgaba/aws-lex-bookatable
Once you have defined your bot you can test it in Amazon Lex console and then publish it. Lex allows you to integrate the bot on your website/mobile apps and other messaging platforms like Slack.
Demo
You can see the demo of my bot in the below youtube video-
In the demo you can see that I gave past date to book a table and bot after validation elicited the same slot again after showing the user friendly error message. The validation code is executed in Amazon Lambda function - https://github.com/kunalgaba/aws-lex-bookatable
You can build these bots on Amazon Lex console directly or you can use Amazon AWS CLI to upload bot model definitions in JSON formats.
Happy bot building!
References
- How to build a bot using Amazon Lex? - https://docs.aws.amazon.com/lex/latest/dg/getting-started-ex2.html
- Amazon Lex FAQs - https://aws.amazon.com/lex/faqs/