Amazon Lex is a service for building conversational interfaces into any application using voice and text. With Amazon Lex, you can easily build sophisticated, natural language, conversational bots (chatbots), virtual agents, and interactive voice response (IVR) systems. You can now use industry grammars to accelerate IVR development on Amazon Lex as part of your IVR migration effort. Industry grammars are a set of XML files made available as a grammar slot type. You can select from a range of pre-built industry grammars across domains, such as financial services, insurance, and telecom. In this post, we review the industry grammars for these industries and use them to create IVR experiences.
Financial services
You can use Amazon Lex in the financial services domain to automate customer service interactions such as credit card payments, mortgage loan applications, portfolio status, and account updates. During these interactions, the IVR flow needs to collect several details, including credit card number, mortgage loan ID, and portfolio details, to fulfill the user’s request. We use the financial services industry grammars in the following sample conversation:
Agent: Welcome to ACME bank. To get started, can I get your account ID?
User: Yes, it’s AB12345.
IVR: Got it. How can I help you?
User: I’d like to transfer funds to my savings account.
IVR: Sure. How much would you like to transfer?
User: $100
IVR: Great, thank you.
The following grammars are supported for financial services: account ID, credit card number, transfer amount, and different date formats such as expiration date (mm/yy) and payment date (mm/dd).
Let’s review the sample account ID grammar. You can refer to the other grammars in the documentation.
<?xml version="1.0" encoding="UTF-8" ?>
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="en-US" version="1.0"
root="main"
mode="voice"
tag-format="semantics/1.0">
<!-- Test Cases
Grammar will support the following inputs:
Scenario 1:
Input: My account number is A B C 1 2 3 4
Output: ABC1234
Scenario 2:
Input: My account number is 1 2 3 4 A B C
Output: 1234ABC
Scenario 3:
Input: Hmm My account number is 1 2 3 4 A B C 1
Output: 123ABC1
-->
<rule id="main" scope="public">
<tag>out=""</tag>
<item><ruleref uri="#alphanumeric"/><tag>out += rules.alphanumeric.alphanum;</tag></item>
<item repeat="0-1"><ruleref uri="#alphabets"/><tag>out += rules.alphabets.letters;</tag></item>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out += rules.digits.numbers</tag></item>
</rule>
<rule id="text">
<item repeat="0-1"><ruleref uri="#hesitation"/></item>
<one-of>
<item repeat="0-1">account number is</item>
<item repeat="0-1">Account Number</item>
<item repeat="0-1">Here is my Account Number </item>
<item repeat="0-1">Yes, It is</item>
<item repeat="0-1">Yes It is</item>
<item repeat="0-1">Yes It's</item>
<item repeat="0-1">My account Id is</item>
<item repeat="0-1">This is the account Id</item>
<item repeat="0-1">account Id</item>
</one-of>
</rule>
<rule id="hesitation">
<one-of>
<item>Hmm</item>
<item>Mmm</item>
<item>My</item>
</one-of>
</rule>
<rule id="alphanumeric" scope="public">
<tag>out.alphanum=""</tag>
<item><ruleref uri="#alphabets"/><tag>out.alphanum += rules.alphabets.letters;</tag></item>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out.alphanum += rules.digits.numbers</tag></item>
</rule>
<rule id="alphabets">
<item repeat="0-1"><ruleref uri="#text"/></item>
<tag>out.letters=""</tag>
<tag>out.firstOccurence=""</tag>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out.firstOccurence += rules.digits.numbers; out.letters += out.firstOccurence;</tag></item>
<item repeat="1-">
<one-of>
<item>A<tag>out.letters+='A';</tag></item>
<item>B<tag>out.letters+='B';</tag></item>
<item>C<tag>out.letters+='C';</tag></item>
<item>D<tag>out.letters+='D';</tag></item>
<item>E<tag>out.letters+='E';</tag></item>
<item>F<tag>out.letters+='F';</tag></item>
<item>G<tag>out.letters+='G';</tag></item>
<item>H<tag>out.letters+='H';</tag></item>
<item>I<tag>out.letters+='I';</tag></item>
<item>J<tag>out.letters+='J';</tag></item>
<item>K<tag>out.letters+='K';</tag></item>
<item>L<tag>out.letters+='L';</tag></item>
<item>M<tag>out.letters+='M';</tag></item>
<item>N<tag>out.letters+='N';</tag></item>
<item>O<tag>out.letters+='O';</tag></item>
<item>P<tag>out.letters+='P';</tag></item>
<item>Q<tag>out.letters+='Q';</tag></item>
<item>R<tag>out.letters+='R';</tag></item>
<item>S<tag>out.letters+='S';</tag></item>
<item>T<tag>out.letters+='T';</tag></item>
<item>U<tag>out.letters+='U';</tag></item>
<item>V<tag>out.letters+='V';</tag></item>
<item>W<tag>out.letters+='W';</tag></item>
<item>X<tag>out.letters+='X';</tag></item>
<item>Y<tag>out.letters+='Y';</tag></item>
<item>Z<tag>out.letters+='Z';</tag></item>
</one-of>
</item>
</rule>
<rule id="digits">
<item repeat="0-1"><ruleref uri="#text"/></item>
<tag>out.numbers=""</tag>
<item repeat="1-10">
<one-of>
<item>0<tag>out.numbers+=0;</tag></item>
<item>1<tag>out.numbers+=1;</tag></item>
<item>2<tag>out.numbers+=2;</tag></item>
<item>3<tag>out.numbers+=3;</tag></item>
<item>4<tag>out.numbers+=4;</tag></item>
<item>5<tag>out.numbers+=5;</tag></item>
<item>6<tag>out.numbers+=6;</tag></item>
<item>7<tag>out.numbers+=7;</tag></item>
<item>8<tag>out.numbers+=8;</tag></item>
<item>9<tag>out.numbers+=9;</tag></item>
</one-of>
</item>
</rule>
</grammar>
Using the industry grammar for financial services
To create the sample bot and add the grammars, perform the following steps. This creates an Amazon Lex bot called Financialbot
and adds the grammars for financial services, which we store in Amazon Simple Storage Service (Amazon S3):
- Download the Amazon Lex bot definition.
- On the Amazon Lex console, choose Actions and then choose Import.
- Choose the
Financialbot.zip
file that you downloaded, and choose Import.
- Copy the grammar XML files for financial services, listed in the preceding section.
- On the Amazon S3 console, upload the XML files.
- Navigate to the slot types on the Amazon Lex console and choose the
accountID
slot type so you can associate the fin_accountNumber.grxml
file.
- In the slot type, enter the Amazon S3 link for the XML file and the object key.
- Choose Save slot type.
The AWS Identity and Access Management (IAM) role used to create the bot must have permission to read files from the S3 bucket.
- Repeat steps 6–8 for the
transferFunds
slot type with fin_transferAmount.grxml
.
- After you save the grammars, choose Build.
- Download the financial services contact flow to integrate it with the Amazon Lex bot via Amazon Connect.
- On the Amazon Connect console, choose Contact flows.
- 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.
- Test the IVR flow by calling in to the phone number.
Insurance
You can use Amazon Lex in the insurance domain to automate customer service interactions such as claims processing, policy management, and premium payments. During these interactions, the IVR flow needs to collect several details, including policy ID, license plate, and premium amount, to fulfill the policy holder’s request. We use the insurance industry grammars in the following sample conversation:
Agent: Welcome to ACME insurance company. To get started, can I get your policy ID?
Caller: Yes, it’s AB1234567.
IVR: Got it. How can I help you?
Caller: I’d like to file a claim.
IVR: Sure. Is this claim regarding your auto policy or home owners’ policy?
Caller: Auto
IVR: What’s the license plate on the vehicle?
Caller: ABCD1234
IVR: Thank you. And how much is the claim for?
Caller: $900
IVR: What was the date and time of the accident?
Caller: March 1st 2:30pm.
IVR: Thank you. I’ve got that started for you. Someone from our office should be in touch with you shortly. Your claim ID is 12345.
The following grammars are supported for the insurance domain: policy ID, driver’s license, social security number, license plate, claim number, and renewal date.
Let’s review the sample claimDateTime grammar. You can refer to the other grammars in the documentation.
<?xml version="1.0" encoding="UTF-8" ?>
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="en-US" version="1.0"
root="main"
mode="voice"
tag-format="semantics/1.0">
<!-- Test Cases
Grammar will support the following inputs:
Scenario 1:
Input: The accident occured at july three at five am
Output: july 3 5am
Scenario 2:
Input: Damage was reported at july three at five am
Output: july 3 5am
Scenario 3:
Input: Schedule virtual inspection for july three at five am
Output: july 3 5am
-->
<rule id="main" scope="public">
<tag>out=""</tag>
<item repeat="1-10">
<item><ruleref uri="#months"/><tag>out = out + rules.months + " ";</tag></item>
<one-of>
<item><ruleref uri="#digits"/><tag>out += rules.digits + " ";</tag></item>
<item><ruleref uri="#teens"/><tag>out += rules.teens+ " ";</tag></item>
<item><ruleref uri="#above_twenty"/><tag>out += rules.above_twenty+ " ";</tag></item>
</one-of>
<item><ruleref uri="#at"/><tag>out += rules.at.new;</tag></item>
<item repeat="0-1"><ruleref uri="#mins"/><tag>out +=":" + rules.mins.min;</tag></item>
<item><ruleref uri="#ampm"/><tag>out += rules.ampm;</tag></item>
</item>
<item repeat="0-1"><ruleref uri="#thanks"/></item>
</rule>
<rule id="text">
<one-of>
<item repeat="0-1">The accident occured at</item>
<item repeat="0-1">Time of accident is</item>
<item repeat="0-1">Damage was reported at</item>
<item repeat="0-1">Schedule virtual inspection for</item>
</one-of>
</rule>
<rule id="thanks">
<one-of>
<item>Thanks</item>
<item>I think</item>
</one-of>
</rule>
<rule id="months">
<item repeat="0-1"><ruleref uri="#text"/></item>
<one-of>
<item>january<tag>out="january";</tag></item>
<item>february<tag>out="february";</tag></item>
<item>march<tag>out="march";</tag></item>
<item>april<tag>out="april";</tag></item>
<item>may<tag>out="may";</tag></item>
<item>june<tag>out="june";</tag></item>
<item>july<tag>out="july";</tag></item>
<item>august<tag>out="august";</tag></item>
<item>september<tag>out="september";</tag></item>
<item>october<tag>out="october";</tag></item>
<item>november<tag>out="november";</tag></item>
<item>december<tag>out="december";</tag></item>
<item>jan<tag>out="january";</tag></item>
<item>feb<tag>out="february";</tag></item>
<item>aug<tag>out="august";</tag></item>
<item>sept<tag>out="september";</tag></item>
<item>oct<tag>out="october";</tag></item>
<item>nov<tag>out="november";</tag></item>
<item>dec<tag>out="december";</tag></item>
</one-of>
</rule>
<rule id="digits">
<one-of>
<item>0<tag>out=0;</tag></item>
<item>1<tag>out=1;</tag></item>
<item>2<tag>out=2;</tag></item>
<item>3<tag>out=3;</tag></item>
<item>4<tag>out=4;</tag></item>
<item>5<tag>out=5;</tag></item>
<item>6<tag>out=6;</tag></item>
<item>7<tag>out=7;</tag></item>
<item>8<tag>out=8;</tag></item>
<item>9<tag>out=9;</tag></item>
<item>first<tag>out=1;</tag></item>
<item>second<tag>out=2;</tag></item>
<item>third<tag>out=3;</tag></item>
<item>fourth<tag>out=4;</tag></item>
<item>fifth<tag>out=5;</tag></item>
<item>sixth<tag>out=6;</tag></item>
<item>seventh<tag>out=7;</tag></item>
<item>eighth<tag>out=8;</tag></item>
<item>ninth<tag>out=9;</tag></item>
<item>one<tag>out=1;</tag></item>
<item>two<tag>out=2;</tag></item>
<item>three<tag>out=3;</tag></item>
<item>four<tag>out=4;</tag></item>
<item>five<tag>out=5;</tag></item>
<item>six<tag>out=6;</tag></item>
<item>seven<tag>out=7;</tag></item>
<item>eight<tag>out=8;</tag></item>
<item>nine<tag>out=9;</tag></item>
</one-of>
</rule>
<rule id="at">
<tag>out.new=""</tag>
<item>at</item>
<one-of>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out.new+= rules.digits</tag></item>
<item repeat="0-1"><ruleref uri="#teens"/><tag>out.new+= rules.teens</tag></item>
</one-of>
</rule>
<rule id="mins">
<tag>out.min=""</tag>
<item repeat="0-1">:</item>
<item repeat="0-1">and</item>
<one-of>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out.min+= rules.digits</tag></item>
<item repeat="0-1"><ruleref uri="#teens"/><tag>out.min+= rules.teens</tag></item>
<item repeat="0-1"><ruleref uri="#above_twenty"/><tag>out.min+= rules.above_twenty</tag></item>
</one-of>
</rule>
<rule id="ampm">
<tag>out=""</tag>
<one-of>
<item>AM<tag>out="am";</tag></item>
<item>PM<tag>out="pm";</tag></item>
<item>am<tag>out="am";</tag></item>
<item>pm<tag>out="pm";</tag></item>
</one-of>
</rule>
<rule id="teens">
<one-of>
<item>ten<tag>out=10;</tag></item>
<item>tenth<tag>out=10;</tag></item>
<item>eleven<tag>out=11;</tag></item>
<item>twelve<tag>out=12;</tag></item>
<item>thirteen<tag>out=13;</tag></item>
<item>fourteen<tag>out=14;</tag></item>
<item>fifteen<tag>out=15;</tag></item>
<item>sixteen<tag>out=16;</tag></item>
<item>seventeen<tag>out=17;</tag></item>
<item>eighteen<tag>out=18;</tag></item>
<item>nineteen<tag>out=19;</tag></item>
<item>tenth<tag>out=10;</tag></item>
<item>eleventh<tag>out=11;</tag></item>
<item>twelveth<tag>out=12;</tag></item>
<item>thirteenth<tag>out=13;</tag></item>
<item>fourteenth<tag>out=14;</tag></item>
<item>fifteenth<tag>out=15;</tag></item>
<item>sixteenth<tag>out=16;</tag></item>
<item>seventeenth<tag>out=17;</tag></item>
<item>eighteenth<tag>out=18;</tag></item>
<item>nineteenth<tag>out=19;</tag></item>
</one-of>
</rule>
<rule id="above_twenty">
<one-of>
<item>twenty<tag>out=20;</tag></item>
<item>thirty<tag>out=30;</tag></item>
</one-of>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out += rules.digits;</tag></item>
</rule>
</grammar>
Using the industry grammar for insurance
To create the sample bot and add the grammars, perform the following steps. This creates an Amazon Lex bot called InsuranceBot
and adds the grammars for the insurance domain:
- Download the Amazon Lex bot definition.
- On the Amazon Lex console, choose Actions, then choose Import.
- Choose the
InsuranceBot.zip file
that you downloaded, and choose Import.
- Copy the grammar XML files for insurance, listed in the preceding section.
- On the Amazon S3 console, upload the XML files.
- Navigate to the slot types on the Amazon Lex console and select the
policyID
slot type so you can associate the ins_policyNumber.grxml
grammar file.
- In the slot type, enter the Amazon S3 link for the XML file and the object key.
- Choose Save slot type.
The IAM role used to create the bot must have permission to read files from the S3 bucket.
- Repeat steps 6–8 for the
licensePlate
slot type (ins_NJ_licensePlateNumber.grxml
) and dateTime
slot type (ins_claimDateTime.grxml
).
- After you save the grammars, choose Build.
- Download the insurance contact flow to integrate with the Amazon Lex bot.
- On the Amazon Connect console, choose Contact flows.
- In the Amazon Lex section, and select your Lex bot and make it available for use in the Amazon Connect contact flows.
- Select the contact flow to load it into the application.
- Test the IVR flow by calling in to the phone number.
Telecom
You can use Amazon Lex in the telecom domain to automate customer service interactions such as activating service, paying bills, and managing device installations. During these interactions, the IVR flow needs to collect several details, including SIM number, zip code, and the service start date, to fulfill the user’s request. We use the financial services industry grammars in the following sample conversation:
Agent: Welcome to ACME cellular. To get started, can I have the telephone number associated with your account?
User: Yes, it’s 123 456 7890.
IVR: Thanks. How can I help you?
User: I am calling to activate my service.
IVR: Sure. What’s the SIM number on the device?
IVR: 12345ABC
IVR: Ok. And can I have the zip code?
User: 12345
IVR: Great, thank you. The device has been activated.
The following grammars are supported for telecom: SIM number, device serial number, zip code, phone number, service start date, and ordinals.
Let’s review the sample SIM number grammar. You can refer to the other grammars in the documentation.
<?xml version="1.0" encoding="UTF-8" ?>
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="en-US" version="1.0"
root="main"
mode="voice"
tag-format="semantics/1.0">
<!-- Test Cases
Grammar will support the following inputs:
Scenario 1:
Input: My SIM number is A B C 1 2 3 4
Output: ABC1234
Scenario 2:
Input: My SIM number is 1 2 3 4 A B C
Output: 1234ABC
Scenario 3:
Input: My SIM number is 1 2 3 4 A B C 1
Output: 123ABC1
-->
<rule id="main" scope="public">
<tag>out=""</tag>
<item><ruleref uri="#alphanumeric"/><tag>out += rules.alphanumeric.alphanum;</tag></item>
<item repeat="0-1"><ruleref uri="#alphabets"/><tag>out += rules.alphabets.letters;</tag></item>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out += rules.digits.numbers</tag></item>
</rule>
<rule id="text">
<item repeat="0-1"><ruleref uri="#hesitation"/></item>
<one-of>
<item repeat="0-1">My SIM number is</item>
<item repeat="0-1">SIM number is</item>
</one-of>
</rule>
<rule id="hesitation">
<one-of>
<item>Hmm</item>
<item>Mmm</item>
<item>My</item>
</one-of>
</rule>
<rule id="alphanumeric" scope="public">
<tag>out.alphanum=""</tag>
<item><ruleref uri="#alphabets"/><tag>out.alphanum += rules.alphabets.letters;</tag></item>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out.alphanum += rules.digits.numbers</tag></item>
</rule>
<rule id="alphabets">
<item repeat="0-1"><ruleref uri="#text"/></item>
<tag>out.letters=""</tag>
<tag>out.firstOccurence=""</tag>
<item repeat="0-1"><ruleref uri="#digits"/><tag>out.firstOccurence += rules.digits.numbers; out.letters += out.firstOccurence;</tag></item>
<item repeat="1-">
<one-of>
<item>A<tag>out.letters+='A';</tag></item>
<item>B<tag>out.letters+='B';</tag></item>
<item>C<tag>out.letters+='C';</tag></item>
<item>D<tag>out.letters+='D';</tag></item>
<item>E<tag>out.letters+='E';</tag></item>
<item>F<tag>out.letters+='F';</tag></item>
<item>G<tag>out.letters+='G';</tag></item>
<item>H<tag>out.letters+='H';</tag></item>
<item>I<tag>out.letters+='I';</tag></item>
<item>J<tag>out.letters+='J';</tag></item>
<item>K<tag>out.letters+='K';</tag></item>
<item>L<tag>out.letters+='L';</tag></item>
<item>M<tag>out.letters+='M';</tag></item>
<item>N<tag>out.letters+='N';</tag></item>
<item>O<tag>out.letters+='O';</tag></item>
<item>P<tag>out.letters+='P';</tag></item>
<item>Q<tag>out.letters+='Q';</tag></item>
<item>R<tag>out.letters+='R';</tag></item>
<item>S<tag>out.letters+='S';</tag></item>
<item>T<tag>out.letters+='T';</tag></item>
<item>U<tag>out.letters+='U';</tag></item>
<item>V<tag>out.letters+='V';</tag></item>
<item>W<tag>out.letters+='W';</tag></item>
<item>X<tag>out.letters+='X';</tag></item>
<item>Y<tag>out.letters+='Y';</tag></item>
<item>Z<tag>out.letters+='Z';</tag></item>
</one-of>
</item>
</rule>
<rule id="digits">
<item repeat="0-1"><ruleref uri="#text"/></item>
<tag>out.numbers=""</tag>
<item repeat="1-10">
<one-of>
<item>0<tag>out.numbers+=0;</tag></item>
<item>1<tag>out.numbers+=1;</tag></item>
<item>2<tag>out.numbers+=2;</tag></item>
<item>3<tag>out.numbers+=3;</tag></item>
<item>4<tag>out.numbers+=4;</tag></item>
<item>5<tag>out.numbers+=5;</tag></item>
<item>6<tag>out.numbers+=6;</tag></item>
<item>7<tag>out.numbers+=7;</tag></item>
<item>8<tag>out.numbers+=8;</tag></item>
<item>9<tag>out.numbers+=9;</tag></item>
</one-of>
</item>
</rule>
</grammar>
Using the industry grammar for telecom
To create the sample bot and add the grammars, perform the following steps. This creates an Amazon Lex bot called TelecomBot
and adds the grammars for telecom:
- Download the Amazon Lex bot definition.
- On the Amazon Lex console, choose Actions, then choose Import.
- Choose the
TelecomBot.zip
file that you downloaded, and choose Import.
- Copy the grammar XML files for the telecom domain, listed in the preceding section.
- On the Amazon S3 console, upload the XML files.
- Navigate to the slot types on the Amazon Lex console and select
phoneNumber
so you can associate the tel_phoneNumber.grxml
grammar.
- In the slot type, enter the Amazon S3 link for the XML file and the object key.
- Choose Save slot type.
The IAM role used to create the bot must have permission to read files from the S3 bucket.
- Repeat steps 6–8 for the slot types
SIM number
(tel_simNumber.grxml
) and zipcode
(tel_usZipcode.grxml
).
- After you save the grammars, choose Build.
- Download the insurance contact flow to integrate with the Amazon Lex bot.
- On the Amazon Connect console, choose Contact flows.
- In the Amazon Lex section, and 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.
- Test the IVR flow by calling in to the phone number.
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 or text.
Conclusion
Industry grammars provide a set of pre-built XML files that you can use to quickly create IVR flows. You can select grammars to enable customer service conversations for use cases across financial services, insurance, and telecom. The grammars are available as a grammar slot type and can be used in an Amazon Lex bot configuration. You can download the grammars and enable these via the Amazon Lex V2 console or 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.
About the Authors
John Heater has over 15 years of experience in AI and automation. As the SVP of the Contact Center Practice at NeuraFlash, he leads the implementation of the latest AI and automation techniques for a portfolio of products and customer solutions.
Sandeep Srinivasan is a Product Manager on the Amazon Lex team. As a keen observer of human behavior, he is passionate about customer experience. He spends his waking hours at the intersection of people, technology, and the future.