Interpret caller input using grammar slot types in Amazon Lex
Customer service calls require customer agents to have the customer’s account information to process the caller’s request. For example, to provide a status on an insurance claim, the support agent needs policy holder information such as the policy ID and claim number. Such information is often collected in the interactive voice response (IVR) flow at the beginning of a customer support call. IVR systems have typically used grammars based on the Speech Recognition Grammar Specification (SRGS) format to define rules and parse caller information (policy ID, claim number). You can now use the same grammars in Amazon Lex to collect information in a speech conversation. You can also provide semantic interpretation rules using ECMAScript tags within the grammar files. The grammar support in Amazon Lex provides granular control for collecting and postprocessing user input so you can manage an effective dialog.
In this post, we review the grammar support in Amazon Lex and author a sample grammar for use in an Amazon Connect contact flow.
Use grammars to collect information in a conversation
You can author the grammar as a slot type in Amazon Lex. First, you provide a set of rules in the SRGS format to interpret user input. As an optional second step, you can write an ECMA script that transforms the information collected in the dialog. Lastly, you store the grammar as an XML file in an Amazon Simple Storage Service (Amazon S3) bucket and reference the link in your bot definition. SRGS grammars are specifically designed for voice and DTMF modality. We use the following sample conversations to model our bot:
Conversation 1
IVR: Hello! How can I help you today?
User: I want to check my account balance.
IVR: Sure. Which account should I pull up?
User: Checking.
IVR: What is the account number?
User: 1111 2222 3333 4444
IVR: For verification purposes, what is your date of birth?
User: Jan 1st 2000.
IVR: Thank you. The balance on your checking account is $123 dollars.
Conversation 2
IVR: Hello! How can I help you today?
User: I want to check my account balance.
IVR: Sure. Which account should I pull up?
User: Savings.
IVR: What is the account number?
User: I want to talk to an agent.
IVR: Ok. Let me transfer the call. An agent should be able to help you with your request.
In the sample conversations, the IVR requests the account type, account number, and date of birth to process the caller’s requests. In this post, we review how to use the grammars to collect the information and postprocess it with ECMA scripts. The grammars for account ID and date cover multiple ways to provide the information. We also review the grammar in case the caller can’t provide the requested details (for example, their savings account number) and instead opts to speak with an agent.
Build an Amazon Lex chatbot with grammars
We build an Amazon Lex bot with intents to perform common retail banking functions such as checking account balance, transferring funds, and ordering checks. The CheckAccountBalance
intent collects details such as account type, account ID, and date of birth, and provides the balance amount. We use a grammar slot type to collect the account ID and date of birth. If the caller doesn’t know the information or asks for an agent, the call is transferred to a human agent. Let’s review the grammar for the account ID:
The grammar has two rules to parse user input. The first rule interprets the digits provided by the caller. These digits are appended to the output via an ECMA script tag variable (out
). The second rule manages the dialog if the caller wants to talk to an agent
. In this case the out
tag is populated with the word agent. After the rules are parsed, the out tag carries the account number (out.AccountNumber
) or the string agent
. The downstream business logic can now use the out
tag handle the call.
Deploy the sample Amazon Lex bot
To create the sample bot and add the grammars, perform the following steps. This creates an Amazon Lex bot called BankingBot
, and two grammar slot types (accountNumber
, dateOfBirth
).
- Download the Amazon Lex bot.
- On the Amazon Lex console, choose Actions, then choose Import.
- Choose the file
BankingBot.zip
that you downloaded, and choose Import. In the IAM Permissions section, for Runtime role, choose Create a new role with basic Amazon Lex permissions. - Choose the bot
BankingBot
on the Amazon Lex console. - Download the XML files for accountNumber and dateOfBirth. (Note: In some browsers you will have to “Save the link” to download the XML files)
- On the Amazon S3 console, upload the XML files.
- Navigate to the slot types on the Amazon Lex console, and click on the
accountNumber
slot type - In the slot type grammar select the S3 bucket with the XML file and provide the object key. Click on Save slot type.
- Navigate to the slot types on the Amazon Lex console, and click on the
dateOfBirth
slot type - In the slot type grammar select the S3 bucket with the XML file and provide the object key. Click on Save slot type.
- After the grammars are saved, choose Build.
- Download the supporting AWS Lambda and Navigate to the AWS Lambda console.
- On the create function page select Author from scratch. As basic information please provide the following: function name
BankingBotEnglish
, and RuntimePython 3.8
. - Click on Create function. In the Code source section, open
lambda_funciton.py
and delete the existing code. Download the code and open it in a text editor. Copy and paste the code into the emptylambda_funciton.py
tab. - Choose deploy.
- Navigate to the Amazon Lex Console and select
BankingBot
. Click on Deployment and then Aliases followed byTestBotAlias
- On the Aliases page select languages and navigate to English (US).
- For source select
BankingBotEnglish
, for Lambda version or alias select$LATEST
- Navigate to the Amazon Connect console, choose Contact flows.
- Download the contact flow to integrate with the Amazon Lex bot.
- In the Amazon Lex section, select your Amazon Lex bot and make it available for use in the Amazon Connect contact flows.
- Select the contact flow to load it into the application.
- Make sure the right bot is configured in the “Get Customer Input” block. Add a phone number to the contact flow.
- Choose a queue in the “Set working queue” block.
- Test the IVR flow by calling in to the phone number.
- Test the solution.
Test the solution
You can call in to the Amazon Connect phone number and interact with the bot. You can also test the solution directly on the Amazon Lex V2 console using voice and DTMF.
Conclusion
Custom grammar slots provide the ability to collect different types of information in a conversation. You have the flexibility to capture transitions such as handover to an agent. Additionally, you can postprocess the information before running the business logic. You can enable grammar slot types via the Amazon Lex V2 console or AWS SDK. The capability is available in all AWS Regions where Amazon Lex operates in the English (Australia), English (UK), and English (US) locales.
To learn more, refer to Using a custom grammar slot type. You can also view the Amazon Lex documentation for SRGS or ECMAScript for more information.
About the Authors
Kai Loreck is a professional services Amazon Connect consultant. He works on designing and implementing scalable customer experience solutions. In his spare time, he can be found playing sports, snowboarding, or hiking in the mountains.
Harshal Pimpalkhute is a Product Manager on the Amazon Lex team. He spends his time trying to get machines to engage (nicely) with humans.
Tags: Archive
Leave a Reply