Yes, you read it right! If you follow this article, you can build your own functional chatbot in under 15 minutes!
The final result is something like this:
Oh, and full disclosure: You will only type 11 lines of code to build this incredibly simple but reasonably scalable bot. Excited yet?
If you are new to Amazon Lex, you can try it for free. From the date you get started with Amazon Lex, you can process up to 10,000 text requests for free for the first year, after that it costs $0.00075 per text request, what that means is that you will pay $0.38 – yes thirty-eight cents – at every five hundred times your bot is texted. Very friendly pricing, no doubts.
Now go create that AWS account if you don’t have one, and if you do, go log in, I’ll be waiting here! But fast! We only have 15 minutes, remember?
Now look for Lex within the services tab, should look something like this:
Click on “Create” to create a new bot, the configuration of your bot should be as follows
I would explain all of this but we’re running against the clock here! Some highlights:
Output voice – Amazon Lex allows you to create more than text-based bots. You can automate entire call centers with it!
Try a sample – These samples are a very good way to get acquainted with the different features you can use.
I strongly recommend you come back later to try these different settings, for now, let’s keep moving!
Once you created your bot, let’s create our intent. Intents are the essentially the things you bot can understand, the more intents, the more things your bot can talk about. Since this is a bot that understands politics, let’s create our “trump” intent:
Utterances are essentially the different ways you can ask the same thing. Amazon Lex will take care of small variants and typos for you. What that means is that you don’t have to worry about your bots phrasing like “what u think of trump?“, Lex will make sure the bot understands that too.
So after you put the above utterances in, let’s make sure the bot can reply to them by scrolling down and filling the responses, like so:
Boom! Save the intent and your bot is now capable of talking about politics. Well, about Trump anyways. You will notice there’s an area on the right within Amazon Lex that allows you to test your bot. To test what we have just done, you will need to “Build” your bot first, so make sure you hit that button before testing it out! The test should look something like this:
We’re going to start coding your bot now so that it works outside Amazon’s dash! But first, there are a couple things we still need to do. The first one is publishing your bot. You can play around with your bot as much as you want, but your customers will only see these changes after you publish it. The publishing button is just beside the “build” button. You will be asked for an “alias”, an “alias” could be things like “production_environment” or “test_environment”. Let’s just name it “politicsbot” for now.
The last thing we need to do is to generate API keys for our application to access the bot.
Chop Chop! On Amazon, head to services again and look for “IAM”. Click on “Users” and add a new one. Name it “bot_user” and select the access type to “programatic”. Like so:
Great! We’re almost there. When asked about permissions, select “attach existing policies directly” and select “AmazonLexFullAccess”.
Hit create user! Save the “Access Key ID” and “Secret Access Key” given to you as we will use it soon.
You must be thinking “There is just no way we will make it in time!”. Well, remember I said all it takes to get this working is 11 lines of code?
Here they are:
To run this, create a python file named “bot.py” and run it by typing python “python bot.py <aws_key_id> <aws_key_secret>”.
The only requirement is to have “boto3” installed, boto3 is Amazon’s Python library, install it by typing “pip install boto3”.
The code above is only compatible with Python 3.
So… DID YOU MAKE IT IN TIME?
What is next?
I recommend you start playing around with Amazon Lex, add some more intents, make your bot really smart!
And if you want to take it to the next level, Read Using Amazon Lex to build a Facebook chatbot (Coming soon), you can also subscribe to our Conversational Interfaces Newsletter and receive free tips on how to make better chatbots just below
If you are really serious about building conversational interfaces or is looking for a career as a conversational engineer, I recommend getting my ebook on How to build clever conversational interfaces in a few hours where I discuss how you can make your chatbot smarter using API’s and your existing database, besides discussing techniques to improve customer experience and to humanise your chatbot. The ebook is completely free if you have Kindle and super cheap if you don’t.