1. Create Lex Bot

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.

Create an Intent Manually

  1. Log in to AWS Lex Console

  2. If you have never created a bot, click Get Started

  3. Choose Custom bot

  4. Our bot name will be PersonalBanker

  5. Choose your preferred Output Voice

  6. Session timeout should be 5 minute

  7. Choose “No” to the Children’s Online Privacy Protection Act (COPPA) question

  8. Click Create to continue

  9. 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.

  10. In the window that pops-up click the Create new intent link.

  11. Our first intent enables the user to get account details, enter name GetAccountDetail for Intent Name, then click Add to continue

  12. 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”.

  13. 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

  14. For Slot type name enter AccountType and input an optional description

  15. 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.

  16. Click Add slot to intent

  17. Change the Name to AccountType so that it matches the slot name that we specified when we created the sample utterances.

  18. 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.

  19. Scroll down and click “Save Intent”

  20. 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.

Add More Intents

Let’s add 2 more intents and one more slot type.

  1. Click the blue “+” button next to “Intents” on the left hand side of the page, then click Create new intent.

  2. 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

  3. 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
  4. 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

  5. For Slot type name enter LoanType and optionally provide a description

  6. Enter the following two options as values:

    • car
    • home
  7. Click Add slot to intent

  8. Change the name of the slot from “slotOne” to “LoanType”

  9. Provide a prompt, for example such as Which loan account?

  10. Make sure that the Required column is selected

  11. Click Save Intent. Now we’ll add a final intent to allow users to get more information on the loan products that we have.

  12. Click the blue “+” button next to “Intents” on the left hand side of the page, then click Create new intent

  13. Set the name of the intent to GetLoanProducts then click Add

  14. 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
  15. Add a slot (this allows us to get the loan type that the user wants to query) with the following values

    • Required: yes
    • Name: LoanType
    • Slot Type: LoanType (select from the drop-down list)
    • Prompt: Which loan type?
  16. Click the blue “+” button to the right of the Slots information to add this slot to the intent

  17. Click Save Intent

  18. 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.

  1. Go to AWS Lex Console

  2. Click Action

  3. Click Import

  4. Choose the zip file. You need to download the file lex-import-personal-banker.json.zip

  5. Click Import

  6. Click Overwrite and Continue if you are not using these slot type.

  7. Click on the bot you just build

  8. Click Build

  9. 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.

Next Step

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.