Add Custom Slots to a Lex Chatbot

Let's upgrade your chatbot and help users check their account balance!

Introduction

⚑️ 30 second Summary

Welcome to Part TWO of the Lex series!

In this five-project Lex series, you'll learn how to create a practical chatbot, BankerBot, that can help your imaginary bank's customers check their account balance and transfer money between accounts.

In Part ONE, you learnt how to:

  • πŸ’¬ Set up a basic intent (WelcomeIntent)
  • πŸ“‹ Create lists of utterances
  • ❌ Handle failures with FallbackIntent
  • πŸ”€ Define a MessageGroup to send variations in your bot's responses
  • πŸ§ͺ Build and test your bot using text and speech

Now you're on part TWO πŸ€–πŸ€–

You'll learn how to set up an intent that helps your users check their account balance!

To successfully check a user's bank balance, BankerBot needs to:

  1. Get the user's details i.e. birthday and account type.
  2. Find the user's account balance figure using those details.
  3. Return the account balance figure to the user.

In this project, we'll complete the first item in the list and use a tool called slots to get the user's details. Then in the next project, we'll use Lambda to complete the second and third item in the list.

Want a complete demo of this project, from start to finish? Check out our 🎬 walkthrough with Maya 🎬

If you're up for a bit of a challenge, quiz yourself on the key concepts up ahead in this project.

This project is part of a series:

  1. Part 1: Build a Chatbot with Amazon Lex
  2. Part 2: You are here!
  3. Part 3: Connect Amazon Lex with Lambda
  4. Part 4: Save User Info with a Lex Chatbot

Before we start...

It's always good to understand exactly what you're here to do.

Set up a new Lex chatbot

In this project, our goal is to get BankerBot to check users' bank account balance.

In this step, get ready to:

  • Create a new bot from scratch on Amazon Lex.

We'll need to repeat the steps from the last project of this series to set up BankerBot's basic functionalities.

Have you completed Part 1 of the Lex Series

Yes, and I've deleted my bot

Perfect! Welcome back to the series, and it's awesome to have you here again. We'll need to repeat the steps from the last project of this series to set up BankerBot's basic functionalities.

πŸ”₯ Here's your mini challenge for this step... Try and recreate the bot you made in Part 1.

Once you're finished, you should have:

  • A new Lex chatbot called BankerBot.
  • WelcomeIntent set up.
  • FallbackIntent customised, i.e. your BankerBot says a customised error message if it doesn't understand the user's input.

Challenge yourself to complete this in less than 10 minutes. πŸ’ͺ

Yes, and I have my bot

Wooh! Let's gooo! πŸ”₯

No, I haven't done it yet!

No worries - you're in good hands!

Once you're finished, you should have:

  • A new Lex chatbot called BankerBot.
  • WelcomeIntent set up.
  • FallbackIntent customised, i.e. your BankerBot says a customised error message if it doesn't understand the user's input.

Let's get started!

  • Log in to your AWS Account.
  • Navigate to Amazon Lex (type Lex into your console's search bar).
  • Check your URL in your web browser - does it say ...console.aws.amazon.com/lexv2/...?
    • If you're not seeing "lexv2" in your URL, click on Switch to the new Lex V2 console link in your left-hand menu.
  • Select Create bot.
  • Select Create a blank bot.

Can't find the Create a blank bot option?

You might need to select the Traditional tab first to see it.

If you're stuck, ask the NextWork community!

  • For Bot name, enter BankerBot
  • For Description, enter Banker Bot to help customer check their balance and make transfers.
  • Under IAM permissions, select Create a role with basic Amazon Lex permissions. We'll be using it to call another service called Lambda in a future project
  • Under Children’s Online Privacy Protection Act (COPPA), select No.
  • Under Idle session timeout, keep the default of 5 minutes.
  • Select Next.
  • Keep the language as English so you can explore Lex's full set of features in this project.
  • Under Voice interaction, click on the dropdown that says Danielle.
  • Click around different voice options to choose your favorite one. Two favorites in the NextWork community are Gregory and Ruth :D
  • For Intent classification confidence score threshold, keep the default value of 0.40.

What is intent classification confidence score threshold?

When you're using Amazon Lex to build a chatbot, this threshold is like a minimum score for your chatbot to confidently understand what the user is trying to say.

Setting this to 0.4 means that your chatbot needs to be at least 40% confident that it understands what the user is asking to be able to give a response.

So if a user's input is ambiguous and your chatbot's confidence score is below 0.4, it'll throw an error message.

  • Select Done.

Set Up WelcomeIntent

  • When your bot is created, you will automatically see a page called Intent: NewIntent.

What are intents?

An intent is what the user is trying to achieve in their conversation with the chatbot. For example, checking a bank account balance; booking a flight; ordering food.

In Amazon Lex, you build your chatbot by defining and categorising different intents. If you set up different intents, one single chatbot can manage a bunch of requests that are usually related to each other.

  • Under Intent details, enter WelcomeIntent for the Intent name.
  • Add the description Welcoming a user when they say hello.
  • Scroll down to the Sample utterances panel.
  • Click the Plain Text button.
  • Copy the text below, which represent the user inputs (called utterances) that will trigger this intent, and paste it into the text window:
Hi
Hello
I need help
Can you help me?
  • Scroll down to Closing response, and expand the arrow for Response sent to the user after the intent is fulfilled.
  • In the Message field, enter the following message: Hi! I'm BB, the Banking Bot. How can I help you today?
  • Choose Save intent.
  • Choose Build, which is close to the top of the screen.
  • This can take 30 seconds - time for a stretch!
  • Choose Test.
  • The following dialog will pop up, and you can interact with the bot by entering your opening message.
  • Try various different phrases and see what comes up. It's also a good way to check that you've set up your chatbot without any errors:
    • Help me
    • Hiya
    • How are you
    • Good morning

Manage FallbackIntent

  • In your left hand navigation panel, choose FallbackIntent.

What is FallbackIntent?

Remember the intent classification confidence score threshold, and how it's been set to 0.4?

If your chatbot has a confidence score below 40% for all the intents you've defined (in our case, it's just the WelcomeIntent for now), the FallbackIntent is triggered.

Think of it as a custom error message that your chatbot will use to tell the user it doesn't understand their input.

  • The default FallbackIntent message you saw just now ("Intent FallbackIntent is fulfilled") can be a little confusing.
  • Let's re-phrase that message so it's clearer to the user that your chatbot doesn't understand the user's request.
  • Scroll down to Closing responses.
  • Expand the arrow for Response sent to the user after the intent is fulfilled.
  • In the Message field, add the following text:‍ Sorry I am having trouble understanding. Can you describe what you'd like to do in a few words? I can help you find your account balance, transfer funds and make a payment.
  • You'll notice another arrow next to the label Variations - optional.
  • Expand the arrow.
  • Enter the following text: Hmm could you try rephrasing that? I can help you find your account balance, transfer funds and make a payment.
  • Your turn to add a variation - what is another response that the chatbot could use to get clarification if it doesn't understand the user's intent?
  • Choose Save intent.
  • Choose Build - time for another stretch!
  • Choose Test.
  • Let's test 2-3 message that failed in your last try - what do you see now?

Woooo set up DONE πŸ’ͺ

Create a custom slot for account types

Now that bot set up is done, we'll upgrade BankerBot by getting it to check a user's bank balance!

To make that happen, BankerBot will need to ask users for their bank account type and birthday for verification too.

We'll use a cool Lex feature called slots to tell BankerBot what bank account types it should recognize.

In this step, get ready to:

  • Create your first slot to store a user's bank account type.
  • Save different bank account types that Lex should know.
  • In the Amazon Lex console, choose Slot types in your left hand navigation panel.

What are slots?

Slots are pieces of information that a chatbot needs to complete a user's request. Think of them as blanks that need to be filled in a form.

For example, if the intent is to book a table at a restaurant, the chatbot needs specific details like: restaurant name, date, time, number of people.

Amazon Lex provides many ready-to-use slot types for common information, like dates and times, but you can also create your own custom slot types to fit your specific needs. That's what we're about to do.

  • Choose Add slot type.
  • From the dropdown, choose Add blank slot type.
  • Enter accountType for the Slot type name.
  • Choose Add.
  • This will bring up a large Slot types editor panel ✨
  • In the Slot value resolution panel, choose Restrict to slot values.

What does this selection mean?

Selecting Restrict to slot values makes sure that only the values that you specify will count as a valid accountType!

Otherwise, Amazon Lex might use machine learning to accept other values that it frequently encounters from users.

In our case, we don't want Lex to use machine learning to accept other values. We have a set list of bank account types that we offer - Checking, Savings, and Credit accounts - and we don't offer any other bank account types.

If Lex starts accepting other values outside of these three, users could end up having conversations about bank account types we don't actually offer! To prevent that from happening, we'll restrict Lex to only acknowledge the bank account types we set up here.

  • Now let's add the three account types!
  • In the Values field, enter Checking
  • Select Add value, or just press Enter on your keyboard.
  • Do the same for Savings
  • Enter Credit, and add a few synonyms in the second field. Press ; on your keyboard after every time you add in a new one:
    • credit card
    • visa
    • mastercard
    • amex
    • american express
  • Choose Add value to finish up your work for Credit.

Why are we creating slot values?

In this project, we're setting up a new intent that lets users check their bank account balance. Our BankerBot will need to know what bank account type the user is wanting to check, so BankerBot will have to ask for the user's bank account type in the conversation.

By entering specific slot type values, we make sure that our BankerBot only recognizes and accepts the bank account types we offer - Checking, Savings, and Credit. This prevents any confusion or misunderstandings with the user, as the chatbot won't suggest or accept account types that aren't available.

You'll be using these slot values in a conversation with BankerBot by the end of this project to put this in practice!

  • Choose Save slot type.

Create the CheckBalance intent

Alrighty, that's your custom slot all set up βœ…

Now that BankerBot knows about different bank account types, it's ready to take on users' requests to check their account balance.

In this final step, let's put together two things we know, intents and slots, to make it happen!

In this step, get ready to:

  • Set up a new intent for checking user's bank account balance.
  • Add slots in your intent, so Lex can store the user's bank account type and birthday.
  • In your left hand navigation panel, head back to Intents.
  • Choose Add intent, then Add empty intent.
  • Enter CheckBalance as your intent name.
  • Choose Add.
  • Enter the following description in the Intent details panel: Intent to check the balance in the specified account type.
  • Scroll down to Sample utterances.
  • Switch to Plain Text and paste in the following utterances:
What’s the balance in my account?
Check my account balance
What’s the balance in my {accountType} account?
How much do I have in {accountType} ?
I want to check the balance
Can you help me with account balance?
Balance in {accountType}

Why do some of the utterances have the text {accountType}?

This means that Amazon Lex is now prepared to look for slot values from the user's input.

If a word fits what's expected for the accountType slot, Lex will automatically fill in that information and won't need to prompt the user for their accountType anymore (saving time for the user)!

  • Scroll down until you can see the Slots pane.
  • Choose Add slot button.
  • For slot's Name, enter accountType.
  • For the Slot type, choose your custom slot value accountType - which you created in Part 1!
  • Enter the following for Prompts: For which account would you like your balance?
  • Choose Add.
  • You might remember that we mentioned the CheckBalance intent should also check for the user's birthday... let's create a Slot for the birth date!
  • Choose Add slot.
  • Use these values for your next slot:
    • Name: dateOfBirth
    • Slot type: AMAZON.Date
    • Prompts: For verification purposes, what is your date of birth?
  • Choose Save intent.
  • Choose Build - shall we answer some questions while you wait? πŸ‘€
  • Choose Test.
  • Now let's chat with your new chatbot.
  • Enter I want to check my balance please.
  • Then, follow Amazon Lex's prompts and enter an account type and birth date.

Why does my bot say 'Intent CheckBalance fulfilled'?

To successfully check a user's bank balance, BankerBot needs to:

  1. Get the user's details i.e. birthday and account type.
  2. Find the user's account balance figure using those details.
  3. Return the account balance figure to the user.

So far, your BankerBot can do the first item in the list - we created slots for accountType and dateOfBirth to get the user's details!

The second item? Not yet, BankerBot will actually find the user's bank balance in the next project of this series.

If your bot returns Intent CheckBalance fulfilled, that means your bot has successfully taken in the user's details, but it doesn't actually know how to calculate the bank balance yet.

Because of this, it just returns the generic closing response to tell you it's finished running the intent.

  • Now choose Inspect near the top of your chat window.
  • Oooo, the chatbot has already filled both slots - accountType and dateOfBirth - with information it now knows about you.
  • In your chat window, now enter What's the balance in my savings account?
  • This time, Amazon Lex will only prompt you for your date of birth, as it already knows that it should be the Savings account it checks.
  • Nice - you've passed on accountType through your utterance!

That's your job done for this project!

You've successfully set up slots so that BankerBot can get a user's details βœ…

Your next challenge is to use those details to calculate and return a bank account balance to the user, which we'll tackle in the next project.

Secret mission

Welcome to your 🀫 exclusive 🀫 secret mission!

Your mission, should you choose to accept it, is to upgrade your chatbot's error handling skills πŸͺ„

πŸ’Ž In this secret mission, get ready to:

  • Add failure responses.
  • Test your bot's error handling skills!
  • Showcase your secret mission in your project documentation.

Handling Errors in Responses

Delete Your Resources

Delete Your Resources

Make sure you delete all your resources to avoid getting charged. This is a super important task for every single project you set up. Don't keep your resources in your account if you'll wait to come back to this series on another day.

If you're doing you're doing Part Three of this chatbot series today

Did you know Part Three is going to pick up right where you left off in this project?

Yup, that means you'll be repeating all the steps in this project when you start Part Three from scratch again.

You don't have to delete your resources (so you won't have to repeat this project's steps) IF you're also doing Part Two's project today. Just make sure to:

  1. Complete all your tasks and
  2. Download today's documentation before heading to Part Three.

We challenge you to try to give this a go yourself πŸ’ͺ

Do you think you can delete the resources you've created today?

  • Lex Bot

Before diving into the steps for deleting your resources, why not challenge yourself to delete everything in this project on your own?

Keeping track of your resources, and deleting them at the end, is absolutely a skill that will help you reduce waste in your account.

Yep, all done.

Fantastic! It's the home stretch!

I know, but also, I don't...

If you're feeling stuck (we've all been there!), here's a little guide:

  • Head to your Amazon Lex console.
  • Select Bots on the left-hand sidebar.
  • Select the circle radio button next to BankerBot.
  • Select Delete from your Action drop-down.
  • Select Delete.

Nice Work!

Nice Work!

WOOOOOOOO that's another AWS project done βœ… and in the bag!

And there's more to come. In the next project, your chatbot will ⬆️ level up ⬆️ and tell a user their bank balance.

πŸ‘‰ Start project three of this chatbot series now!

To wrap things up, today you've learnt how to:

  1. 🌟 Set up a custom slot type: You created a custom slot type in Amazon Lex to help your chatbot understand different bank account types.
  2. πŸ“š Link slots to your intent: You connected both custom and standard slots to your intent.
  3. πŸ” Check for slot values in conversation: You've learnt how to use Input to check for the slot values your chatbot collects on the user during a conversation.

Phew that's a pretty decent list, you've outdone yourself you champ!

Thanks for joining us in today's project, and we'll see you in the next part. 🀝

p.s. Does it say "Still tasks to complete!" at the bottom of the screen?

This means you still have screenshots left to upload, or questions left to answer!

  1. Press Ctrl+F (Windows) or Command+F (Mac) on your keyboard.
  2. Search for the text Return to later.
  3. Jump straight to your incomplete tasks!
  4. πŸ™‹β€β™€οΈ Still stuck? Ask the community!