Amazon Lex is a service for building conversational interfaces into any application using voice and text. Amazon Lex enables you to quickly and easily build sophisticated, natural language, conversational bots (“chatbots”).
This step is designed to demonstrate how to create a new bot, add intents and define slots types.
You can either choose to create Lex bot manually or use an existing json file to import directly. For those who don’t have any Lex or Alexa developing experience, we recommend creating lex bot manually to better understand the logic behind. If you are interested, you could also try out both methods and experience the difference. But again, the only difference is manually or automatically.
Use N.Virginia(us-east-1) region for this lab, the CloudFormation template used resources in us-east-1. Choosing other regions is ok if you skip Bring Lex Bot to Web.
Log in to AWS Lex Console
If you have never created a bot, click Get Started
Choose Custom bot
Our bot name will be PersonalBanker
Choose your preferred Output Voice
Session timeout should be 5 minute
Choose “No” to the Children’s Online Privacy Protection Act (COPPA) question
Click Create to continue
We will start by creating an intent, which represents an action that the user wants to perform. For example, we’re going to create three intents in this lab for different actions a user can perform: Get Account Details; Get Loan Details; Get Loan Products. Under the Editor tab, Click Create Intent button.
In the window that pops-up click the Create new intent link.
Our first intent enables the user to get account details, enter name GetAccountDetail
for Intent Name, then click Add to continue
We now want to provide samples of what our user would type or say to perform this action (i.e. to activate this intent). Under Sample utterances, type the below phrases and hit [enter] or click the blue “+” button after each phrase. Make sure you do not add a question mark at the end of the phrase as this will cause build issues later on.
What is my {AccountType} balance
{AccountType} account balance
{AccountType} represents a ‘slot’ which is information that we need to process the users request. Type it exactly as shown above with the braces, and in the next step we will define the ‘AccountType’ slot and list the acceptable values (checking, savings). Once the lab is complete, the user will interact with our bot by saying something like “What is my checking balance”.
Next we define a slot which is information we need to process the users request. This information can be included in the utterance (query) that the user types or says, and if not included, Lex will prompt the user for the information. While Lex includes many built-in slot types (such as number, color, city, food, etc), in this case we want to define a custom slot to get the account type that the user is referring to. Click on the blue “+” button under “Slot types” on the left navigation bar, and click Create slot type to continue
For Slot type name enter AccountType
and input an optional description
For Value, we want to allow the user to make queries against either their checking
or saving
account, so enter those as values, clicking the blue “+” sign after each word.
Click Add slot to intent
Change the Name to AccountType
so that it matches the slot name that we specified when
we created the sample utterances.
Specify What type of account?
for the Prompt. This prompt will be used by our bot if the
user does not specify an account type when asking a question.
Scroll down and click “Save Intent”
Let’s build this simple Bot: Hit the grey Build button at the top right corner. You will be
asked for confirmation to build. Click Build to continue. The build process takes approximately
a minute. Once complete, you can ask your bot a question as a way to test it. For example, you
could type what is my checking balance?
in the chat window. At this stage since we have not added
in the backend Lambda function, the response will be that the bot is ready for fulfillment.
If at any point you made a mistake in the steps above, selecting the “Latest” version of the intent at the top, next to the intent name, will allow you to edit your choices.
Let’s add 2 more intents and one more slot type.
Click the blue “+” button next to “Intents” on the left hand side of the page, then click Create new intent.
This intent will allow users to get information on their outstanding home or car loan
balance, so set the name to GetLoanDetail
then click Add
For sample utterances (the things we expect out users to type/say to our bot to trigger a specific intent/action), add the following phrase then click the blue “+” at the end of the sample utterance box
Get my {LoanType} loan balance
Now we’ll create a new slot type which we’ll use to store a response from the user as to whether they are wanting the intent to access their car loan balance or their home loan balance. Click the blue “+” button under ‘Slot types’ on the left hand side of the screen
For Slot type name enter LoanType
and optionally provide a description
Enter the following two options as values:
Click Add slot to intent
Change the name of the slot from “slotOne” to “LoanType”
Provide a prompt, for example such as Which loan account?
Make sure that the Required column is selected
Click Save Intent. Now we’ll add a final intent to allow users to get more information on the loan products that we have.
Click the blue “+” button next to “Intents” on the left hand side of the page, then click Create new intent
Set the name of the intent to GetLoanProducts
then click Add
For sample utterances, add the following two phrases. Make sure not to include punctuation (such as comma’s or question marks). The “More loan info” utterance will be used as a follow-up after a user has asked for information on their outstanding loan balance.
What is the rate on the {LoanType} loan
More loan info
Add a slot (this allows us to get the loan type that the user wants to query) with the following values
LoanType
LoanType
(select from the drop-down list)Which loan type?
Click the blue “+” button to the right of the Slots information to add this slot to the intent
Click Save Intent
Click Build, and click Build again when prompted for confirmation
You don’t need to do this section if you have already manually finished Lex creating.
Go to AWS Lex Console
Click Action
Click Import
Choose the zip file. You need to download the file lex-import-personal-banker.json.zip
Click Import
Click Overwrite and Continue if you are not using these slot type.
Click on the bot you just build
Click Build
The build process takes approximately a minute. Once complete, you can ask your bot a question as a way to test it. For example, you could type “what is my checking balance?” in the chat window. At this stage since we have not added in the backend Lambda function, the response will be that the bot is ready for fulfillment.
Our bot is almost ready, all it needs now is a smart backend. Now please go to Create Lex Lambda Function for next step where we will implement the backend logic for our chatbot.