Why talk to humans when you can build a bot that does it for you?
This quote summarizes my experience of diving into Amazon Lex, AWS's superpower for building chatbots. I began on a journey to create my own bot: BankerBot. What a rollercoaster ride this was, with its learning curves, errors, and eureka moments! More on that below.
How It All Started
I've always wanted to learn AWS, and when one day, I found a website called Nextwork. It had a tutorial wherein they explained how to build chatbots with Amazon Lex. Curiosity gripped me, and I plunged into action.
Lex looked like a youthful, fun playground for chatbot enthusiasts. It demanded you to reduce the complexity of a conversational interface into easy clicks and configuration steps, a task in itself for a newcomer in chatbots! Armed with the tutorial, I hoped to develop a bot capable of greeting users, fetching bank balance, and following up with subsequent queries.
What is Amazon Lex?
We can think of Amazon Lex as that friend you have who just makes your life easier. It helps in creating chatbots that would just chat with users via text or by talking with them via voice. You could think of it as a bridge between you and artificial intelligence. It is pretty intuitive, integrates seamlessly with other AWS services, and allows automating the mundane conversations. This is great for applications like banking, customer service, or even ordering pizza.
I initially planned to create a bot where the back-and-forth with the customer on banking queries would be minimized. Pretty simple, right? Now what "Spoiler" it wasn't! At least not right at the beginning.
Step 1: Set-up of BankerBot
To start with, I created a bot named BankerBot on the Amazon Lex. Here is what I did:
- Created Intents: Intents are like aims of a bot. I created WelcomeIntent, to greet users, CheckBalance, to fetch account balance, and FollowupCheckBalance, to respond to a follow-up query.
- Added Slots: Slots are allotted to take input from the user. For example, I added two slots - accountType (Savings, Checking, Credit) and dateOfBirth - to personalize the response.
- Designed Responses: I put in the dynamic responses, using placeholders. For instance: ""Your balance in the {accountType} account is $XYZ."
The entire setup process was quite smooth, thanks to Lex's user-friendly interface. At least so I thought.
The Mistake That Taught Me a Lesson π€¦ββοΈβ
Everything was going just fine until I came across a very frustrating roadblock. The bot had been working like a charm in English (India) (en_IN
) for basic tasks-greet the user, take input from the user, and check the balance. When the FollowupCheckBalance
intent was designed, it got stuck.
Picture yourself in this situation:
- To know your balance in your savings bank account, you are required to provide your date of birth.
- You next wanted to check the balance in your credit account.
- The bot asks for your date of birth again. Very frustrating, isn't it?
My intention was to have the user provide the date of birth once (through context tags), and continue using the same for further queries. But the fatal flaw was that context tags were unsupported in en_IN
.
Initially, I thought it was something that I am missing. I went through every little setting and Googled like a maniac until I finally discovered that in order to use context tags, the bot must be created in English (US) (en_US
). Talk about a facepalm moment but a valuable learning experience, nonetheless. I rebuilt the bot using en_US
and, voila, the context feature just popped up like magic.
Step 2: Building a Smarter Bot with AWS Lambda
Setup AWS Lambda to process data, fetch information or provide randomly generated responses. With Lambda, it's almost like the brain of your bot-I used it to simulate reporting on current bank balances.
What I did was as follows:
- Wrote a Lambda function that generates a random number that acts as a simulated balance.
- The function was connected to the bot through code hooks.
- Test it by saying, βWhatβs my balance in the savings account?β
The bot responded, βYour balance in savings is $423.β Success! Truly the thrill of watching a baby take their first step.
Step 3: Adding Multiple Slots
In the upcoming stage, I established a TransferFunds
intent for BankerBot. Three slots will help gather information:
- Source Account Type
- Target Account Type
- Amount to Transfer
I used the same slot type accountType
two times with different names sourceAccountType
and targetAccountType
to ensure clarity in the understanding of which account to be used. I inserted confirmations like, "Are you sure you want to transfer βΉ500 from your Savings account to your Credit account?"
Step 4: Automating Setup with CloudFormation π
After building my bot several times (bless you, en_IN
!), I chanced upon AWS CloudFormation. It's sort of a magic wand to automate setups. Instead of going through the old-fashioned way of creating the bot, intents, and Lambda functions by hand, CloudFormation allowed you to define everything inside a YAML file and deploy it all as one stack.
Using CloudFormation, I set up the entire infrastructure for BankerBot within minutes. This saved me hours of manual configuration and spared me further human error.
Challenges and Fixes
It was not one joyous flying leap completing the building of BankerBot. Part of the unfortunate situations I found with the bot and how I solved them is listed below.
Error: Missing context tag in
en_IN
β
Fix: The bot was rebuilt inen_US
for context support πError: Lambda function is not returning the responses β‘
Fix: Adjusted the IAM permissions for the function to be able to speak to Lex πError: Slot values not occurring correctly π
Fix: Utilized detailed utterances and a validation prompt to guide user input π£οΈ
Key Takeaways
- Start Simple: πβ Begin with the basicsβno need to boil the ocean! Add complexity gradually.
- Read the Docs: ππ Small details (like language settings) can make or break your bot.
- Embrace Errors: ββ‘οΈπ‘ Treat errors as stepping stones to learning.
- Use CloudFormation: βοΈπ€ Automation = saved time + happier you! π
Conclusions
It was fine learning to build BankerBot; at first, it was not easy to handle, but it became quite fun after I learned it. With Amazon Lex and lots of trial and error, I have my bot that is interacting just like a pro. If I can do it, you can, too.
What are you waiting for? π Dive into Lex, embrace the mistakes, and craft something amazing. π€β¨ Have a blast building your dream bots! ππ»
Top comments (0)