Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views31 pages

AI Chat Bot Documentation

The document outlines the process of building a chatbot named BankerBot using Amazon Lex, detailing its capabilities for customer support through AI/ML intent classification. It describes various features such as intents, custom slots, and AWS Lambda integration to enhance the chatbot's functionality, including context carryover for user information and multiple slots for fund transfers. The author shares their experiences, unexpected ease of use, and the time taken for each project phase, highlighting the efficiency of Amazon Lex and AWS services.

Uploaded by

970lakshya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views31 pages

AI Chat Bot Documentation

The document outlines the process of building a chatbot named BankerBot using Amazon Lex, detailing its capabilities for customer support through AI/ML intent classification. It describes various features such as intents, custom slots, and AWS Lambda integration to enhance the chatbot's functionality, including context carryover for user information and multiple slots for fund transfers. The author shares their experiences, unexpected ease of use, and the time taken for each project phase, highlighting the efficiency of Amazon Lex and AWS services.

Uploaded by

970lakshya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Build a

Chatbot with
Amazon Lex
Introducing Today's Project!
What is Amazon Lex?
Amazon Lex is a tool from AWS for building chatbots that understand and
respond to user messages. It's useful since it enables businesses to easily
create chatbots for customer support. It also uses AI/ML capabilities in
classifying user's intent.

How I used Amazon Lex in this project


In this project, I used Amazon Lex to create a BankerBot, a chatbot that greets
users & provides assistance. It also returns error messages when it doesn't
understand a user's intent, guiding them to clarify their requests for smoother
interactions.

One thing I didn't expect in this project was...


One thing I didnʼt expect in this project was how easy and quick it is to build a
chatbot, along with the impressive capabilities of Amazon Lex.

This project took me...


The whole process took me just about 40 minutes, and I was impressed by
how powerful and user-friendly the platform is.
Setting up a Lex chatbot
I created my chatbot from scratch with Amazon Lex. Setting it up took me about
4 minutes.

While creating my chatbot, I also created a role with basic permissions because
Amazon Lex needs the permission to call other AWS services like AWS Lambda
and Polly which are very useful in this project.

In terms of the intent classification confidence score, I kept the default value of
0.40. This means my chatbot must be at least 40% confident in understanding
the userʼs query to respond; otherwise, error message will display if below this
level.
Intents
Intents are the goals users aim to accomplish with the chatbot, like checking a
balance or booking a flight. In Amazon Lex, you define and categorize intents
so one chatbot can manage multiple related requests.

I created my first intent, Welcome Intent, to greet the user when they say
phrases like "Hello," "Hi," or "I need help," which I included in the sample
utterances. I also set up a closing response to define how the chatbot replies.
FallbackIntent
I launched and tested my chatbot, which could respond successfully to the
sample utterances and similar ones like "Hiya" or even typos like "help m,e."

My chatbot returned the error message Intent FallbackIntent is fulfilled when I


entered phrases like "Good morning." This error occurred because my chatbot
couldnʼt understand the intent of the phrase.
Configuring FallbackIntent
FallbackIntent is a default intent in every chatbot that gets triggered when the
chatbot doesn't recognize the user's intent/goal.

I wanted to configure FallbackIntent because the default closing response


wasnʼt very clear for the user. This way, I can provide a more helpful message
when the chatbot doesnʼt understand something.
Variations
To configure FallbackIntent, I had to customize my own closing response in the
intent's set up page.

I also added variations! What this means for an end user is theyʼll receive
different response styles from my chatbot, making interactions feel more
natural and dynamic. It helps keep conversations engaging by avoiding
repetitive replies.
Build a
Chatbot with
Custom Slots
Introducing Today's Project!
What is Amazon Lex?
Amazon Lex is a tool from AWS for building chatbots that understand and
respond to user messages. It's useful since it enables businesses to easily
create chatbots for customer support. It also uses AI/ML capabilities in
classifying user's intent.

How I used Amazon Lex in this project


In today's project, I used Amazon Lex to build a chatbot named BankerBot. It
helps users check their account balances by recognizing requests through
custom slots and intents, making interactions efficient and user-friendly.

One thing I didn't expect in this project was...


One thing I didn't expect in this project was how easy it was to set up custom
slots in Amazon Lex. In this proj, it streamlined the process of capturing
different bank account types, making the chatbot more efficient in
understanding user requests.

This project took me...


This project took me about 2 hours, including the documentation, and it was
well worth the time invested in building it.
Slots
Slots are details a chatbot needs to fulfill a request, like blanks in a form. For
example, if the intent is to book a table, the chatbot needs specifics such as the
restaurant name, date, time, and number of people.

In this project, I created a custom slot type to capture specific details unique to
the user's request. This allowed the chatbot to better understand and respond
accurately.

This slot type has restricted slot values, which means the chatbot will only
accept specific, preset answers. For example, I used the slot type
"accountType" to ensure that only the options I defined are considered valid
account types.
Connecting slots with intents
I associated my custom slot with CheckBalance, enabling Amazon Lex to
automatically recognize and fill in the {accountType} slot from user input. This
way, if a user specifies an account type, Lex wonʼt need to ask again,
streamlining the process.
Slot values in utterances
I included slot values in some of the utterances by adding the slot name
directly. For example, "What's the balance in my {accountType} account?" lets
the bot capture the account type right away, making the conversation quicker
and easier.

By adding custom slots in utterances, the user experience is improved as the


bot can automatically recognize the account type the user wants to check
without needing to ask repeatedly. This streamlines the conversation and saves
the user time.
Connect a
Chatbot with
Lambda
Introducing Today's Project!
What is Amazon Lex?
Amazon Lex is a tool from AWS for building chatbots that understand and
respond to user messages. It's useful since it enables businesses to easily
create chatbots for customer support. It also uses AI/ML capabilities in
classifying user's intent.

How I used Amazon Lex in this project


In today's project, I used Amazon Lex to create a BankerBot chatbot that helps
users check their bank balance. I set up intents, defined custom slots for
account types, and connected it to Lambda functions to retrieve balance
information dynamically.

One thing I didn't expect in this project was...


I was surprised at how fast I could build a working chatbot with Amazon Lex
and connect it to AWS Lambda for real-time data. I learned that Lambda makes
it easy to access database information, improving the chatbotʼs functionality.

This project took me...


This project took me 2.5 hours to complete, including all the documentation.
AWS Lambda Functions
AWS Lambda is a serverless compute service that runs your code in the cloud
without server management. It executes code only when needed and scales
automatically. Just provide your code in any supported language.

In this project, I created a Lambda function to generate a userʼs bank balance.


Here, itʼs a random number, but in real use, Lambda could retrieve the balance
from a database. Amazon Lex alone canʼt acces this data, so this connection is
essential.
Chatbot Alias
An alias in Amazon Lex acts as a pointer to a specific bot version, so when
connecting to other AWS services or apps, they link to the alias, which directs
to the desired bot version.

TestBotAlias is the default version of your bot for testing and development. It is
a playground to ensure everything works smoothly before launching updates.

To connect Lambda with my BankerBot, I visited my bot's TestBotAlias and


linked it to the latest version of my AWS Lambda function. This setup allows my
bot to access Lambda during testing and development.
Code Hooks
A code hook connects my chatbot to custom Lambda functions to perform
specific tasks. They handle complex actions, such as checking database data
or making decisions based on previous interactions, that a basic chatbot setup
can't manage alone.

Even though I connected my Lambda function with my chatbot's alias, I needed


to use code hooks because the chatbot can't calculate or return a bank
balance by itself. Code hooks are essential for managing complex tasks like this
effectively.

I could find code hooks in the Fulfillment panel by expanding the "On
successful fulfillment" bubble and accessing the advanced option. I then
configured the code hook by checking the box next to 'Use a Lambda function
for fulfillment.'
The final result!
I've set up my chatbot to trigger Lambda and return a random dollar figure
when a user requests their bank balance by entering phrases like 'Check my
balance' or any other sample utterances from the CheckBalance intent and
verifying the request.
Save User Info
with your
Chatbot
Introducing Today's Project!
What is Amazon Lex?
Amazon Lex is a tool from AWS for building chatbots that understand and
respond to user messages. It's useful since it enables businesses to easily
create chatbots for customer support. It also uses AI/ML capabilities in
classifying user's intent.

How I used Amazon Lex in this project


In todayʼs project, I used Amazon Lex to enable context carryover, allowing my
chatbot to remember user info, (birthdate), from the CheckBalance intent. This
lets FollowupCheckBalance access that info for follow-up balance checks w/o
re-verification.

One thing I didn't expect in this project was...


I didn't expect in this project is how smoothly context carryover worked to
retain user info, making follow-up interactions simpler and more seamless.

This project took me...


I completed this project in about 3 hours, including building the chatbot from
scratch (starting from project one in this series) and the project documention.
Context Tags
Context tags are used to store and check for specific information across
different parts of a conversation. They help save the user from having to repeat
certain information.

There are two types of context tags: Output context tags, which store details
after an intent finishes to share with other parts of the conversation, & Input
context tags, which check if specific details are already present before intent
activation.

I created a context tag called 'contextCheckBalance' in the CheckBalance


intent. It stores information about the user's account type, so the bot can
access this detail later in the conversation, & for smoother responses without
needing to re-ask.
FollowUpCheckBalance
I created a new intent called FollowupCheckBalance. The purpose of this intent
is to enable a quick follow-up balance check without requiring re-
authentication, so users donʼt need to re-enter their date of birth for
verification.

This intent is connected to the previous intent, CheckBalance, because


FollowupCheckBalance is triggered only when a user makes a second balance
check request, allowing the conversation to flow smoothly without re-
verification.
Input Context Tag
I created an input context, contextCheckBalance, that matches the output
context tag from the CheckBalance intent. This setup allows
FollowupCheckBalance to access data provided during CheckBalance,
enabling smooth follow-up without re-entering info.
The final result!
To see the context tags and followup intent in action, I triggered CheckBalance
by saying "check my balance" and entered my birthdate for verification, then
followed up with "what about savings?" to activate FollowupCheckBalance.

If I had gone straight to trying to trigger FollowupCheckBalance without setting


up any context, my chabot wouldnʼt have the necessary information from the
initial CheckBalance intent and will prompt for the 'FallbackIntent.'
Build a
Chatbot with
Multiple Slots
Introducing Today's Project!
What is Amazon Lex?
Amazon Lex is a tool from AWS for building chatbots that understand and
respond to user messages. It's useful since it enables businesses to easily
create chatbots for customer support. It also uses AI/ML capabilities in
classifying user's intent.

How I used Amazon Lex in this project


In todayʼs project, I used Amazon Lex to complete BankerBot by creating the
"TransferFunds" intent, enabling users to transfer funds between accs with
shared slot types for source & target accounts, plus a confirmation prompt for
added verification.

One thing I didn't expect in this project was...


One thing I didnʼt expect in this project was how seamlessly I completed
BankerBot with Amazon Lex and utilized Amazon CloudFormation to swiftly
deploy resources from various AWS services, including the entire BankerBot
defined in the YAML file.

This project took me...


I spent about 1 hour completing my BankerBot and an additional 1.5 hours using
Amazon CloudFormation for the first time, troubleshooting errors during the
bot's deployment and working on the documentation process.
TransferFunds
An intent I created for my chatbot was TransferFunds, which help user transfer
funds between different bank accounts.
Using multiple slots
For this intent, I used the same slot type twice because the TransferFunds
intent needs both a source account, where funds are transferred from, and a
target account, where funds are transferred to.

I also learned to create confirmation prompts, which let the chatbot confirm a
userʼs intent. In this project, a prompt was set to confirm transfers between
accounts, and I added a decline response in case the user decides not to
proceed.
Exploring Lex features
Lex also has a special conversation flow feature that guides the interaction
between the user and the chatbot. This editable structure helps the chatbot
follow a clear path, making conversations smoother and more intuitive.

You could also set up your intent using a visual builder! A visual builder
transforms the setup page into a flowchart, making it easy to visualize and
organize the conversation flow. You can also adjust intents as needed.
AWS CloudFormation
AWS CloudFormation is service that gives you an easy way to create and set
up AWS resources. It's an infrastructure as code service - meaning you will use
a file that describes all the resources you want to create and their
dependencies as code.

I used CloudFormation to quickly deploy BankerBot with a YAML file, setting it


up in one go or in a single stack file.
The final result!
Re-building my bot with CloudFormation was quick. It only took me a minute to
set up CloudFormation stack and 5-6 minutes for deployment to finish.

There was an error after deploying my bot! It showed Access Denied when
invoking the Lambda function. I resolved it by updating the functionʼs policy to
grant the necessary permissions, allowing the bot to access the Lambda as
needed.

You might also like