And now for something completely different. Chat bots are a technology that I have not had the opportunity to use in the past. Recently I was given a opportunity to get one working for a proof of concept. There are a few different options in this space, but we chose to go forward with AWS Lex.
I had two main goals
- Understand the technology stack and integration options.
- Learn how to program Lex.
There are a few key terms that you need to be familiar with when discussing AWS Lex based chat bots.
- Intent – This is the context of the conversation. If a chat conversation is usually a more human friendly method for collecting information then the intent is the questionnaire to be filled in through the chat. A chat bot can have any number of intents. For example Purchase and Returns could be two intents for a shopping chat bot
- Utterance – How a user might convey the intent. I think of them as trigger words/phrases to identify the intent
- Slot – This is the information to be collected as part of the intent, you can have zero or more Slots as part of an intent. In developer terms this can be thought of as the variables to be populated for an intent.
- Slot Value – This defines that expected values of a slot. In developer terms this is similar to the data type. These can range from a custom set of words including aliases for those words to a built in type such as date or numbers.
Thankfully creating a fully functional web accessible Chat bot was very painless. AWS has already spent some time writing some good starting material for Lex. In one of their posts has a link to a cloud formation template for creating a complete environment. You can just accept all the default settings during the deployment. One thing to note is that this will stand up the stack in region us-east-1. Lex is not available in all regions at this time. This should only be a temporary restriction as AWS has a long history of rolling out their services to all regions over time.
The cloud formation template stands up everything you will need just accept all the defaults and deploy. To try out the Sample Chat bot just go to the ParentPageUrl that gets populated in the cloud formation template
All things working well you will be presented with web page and a chat bot built-in.
It’s good that Lex has got the basic smarts to translate textual versions of words to their slot type equivalents eg twelve = 12 , Noon = 12:00, Tuesday = 19/2/2019
I did discover a small issue with the default chat bot. When talking about dates/times for a slot you can say things like “today” was evaluated based on the region where Lex is running not your locale. I haven’t investigated if there a way to change this setting.
The next step was to customise the default chat bot. Thankfully the basic chat bot can be controlled via the standard AWS console website. Changing the chat bot through the GUI was painless if you remember to change the version of your slots to Latest when you build the chat bot. Otherwise it will compile it with the version of the Slot from the last successful build meaning slot updates are never incorporated. From the GUI you can edit the intents, Utterances, slots and slot values. Building a more advance chat bot which has conditional logic and any sort of dynamic validation requires Lambda compatible code to be written to implement the feature. There is a lot or prebuilt types from Languages, There is also the capability to test your chat bot within the console as well.
I’m impressed with the easy foundations that AWS gives you for building a chat bot. Using Lambda Code hooks with Lex to integrate with other AWS services opens up options for what you can do. This means you can create some interesting chat bot functionality without too much pain. Lex meets the standard 80/20 rule. I can see making a chat box to deal with simple scenarios will be quick, but making it smarter to deal with the vagaries of human communication will take a lot effort in training/code. An example of this complexity is a simple intent which starts by the user typing a greeting. How many utterances could someone use to say hello to you? Hi, Hello, Good Morning, kia ora, greetings …..