Capturing and validating alphanumeric identifiers in Amazon Lex
Enterprises often rely on unique identifiers to look up information on accounts or events. For example, airlines use confirmation codes to locate itineraries, and insurance companies use policy IDs to retrieve policy details. In customer support, these identifiers are the first level of information necessary to address customer requests. Identifiers are typically a combination of letters and numbers and have a specific pattern. It is likely a fixed length with specific positions of letters and numbers. Previously, you had to create a custom slot type with a broad range of applicable values. As of this writing, you can use AMAZON.AlphaNumeric
slot type in Amazon Lex to capture such inputs in your bot. This slot type can capture combinations of letters and numbers. You can extend this slot type by applying a validation check to create a custom slot type. You can apply these validation checks by specifying a regular expression (regex) on the AMAZON.AlphaNumeric
slot type. This post demonstrates how to use the AMAZON.AlphaNumeric
slot type to capture alphanumeric information and restrict such input to a specific pattern.
Building a bot
This post uses the following conversation to model a bot:
User: I want to reschedule my flight.
Agent: Sure. Can you provide the confirmation code?
User: ABC12D
Agent: Thank you. I see you are on the 6 AM flight to Seattle tomorrow. What would you like to change to?
User: I want to change to next Monday.
Agent: What time would you prefer to travel?
User: 8 AM.
Agent: Sure. Let me make that change. For authentication purposes, can I get the last four digits of the credit card number?
User: Yes, it’s 1234.
Agent: Excellent. I have rescheduled you for the flight departing on February 10 at 8 AM. Anything else I can help you with?
User: No.
Agent: Thank you. Have a great day!
First, build an Amazon Lex bot (FlightReservationBot
) with the following intents:
- MakeReservation – Elicits the travel date, source, and destination cities to process a reservation and return a booking confirmation code.
- ModifyReservation – Elicits the confirmation code and last four digits of the user’s credit card number to modify the reservation.
- CancelReservation – Elicits the confirmation code to cancel the reservation.
You can create the built-in slot type AMAZON.AlphaNumeric
. Such a design helps capture alphanumeric information but doesn’t validate it. To validate, use a regular expression. Create a new slot type ConfirmationCode
by extending AMAZON.AlphaNumeric
. The confirmation code has a fixed format of six characters: [letter] [letter][letter][number][number][letter]. For example, ABC12D
is a confirmation code.
To capture the confirmation code and enforce the necessary validation checks, complete the following steps:
- On the Amazon Lex console, choose FlightReservationBot.
- Next to Slot types, choose the plus sign.
- Choose Extend slot type.
- For Slot type name, enter
ConfirmationCode
. - For Description, enter a description of your slot type.
- For Regular expression, restrict the slot type to the six-character fixed format as specified previously by entering the expression
[A-D]{1}[A-Z]{2}[0-9]{2}[A-Z]{1}
. - Choose Save slot type.
You can now use the ConfirmationCode
slot type to design the ModifyReservation
and CancelReservation
intents for your bot and make sure that the user input contains a valid confirmation code.
To add the ConfirmationCode
slot type to the ModifyReservation
intent, complete the following steps:
- On the Amazon Lex console, choose FlightReservationBot.
- Under Intents, choose
- Under Slots, add a new slot
BookingConfirmationCode
with Slot typeConfirmationCode
with an appropriate prompt. - Design the rest of the bot as per your use-case.
- Choose Save Intent, Build, and Publish.
Your bot is now ready to use. You can test it by providing a confirmation code such as ABCDE that does not match the pattern specified by the regular expression.
Conclusion
This post demonstrated how to capture alphanumeric values using the AMAZON.AlphaNumeric slot type. You can further restrict the slot values captured to a fixed format by providing a regular expression. For more information please refer to the Amazon Lex documentation. Try out the AlphaNumeric slot type in your bot today!
About the author
Anubhav Mishra is a Product Manager with AWS. He spends his time understanding customers and designing product experiences to address their business challenges.
Tags: Archive
Leave a Reply