Empowering Your Business with an IVR System: A Step-by-Step Guide to Amazon Lex and Amazon Connect Integration (Part 1/3)

Dream AI
17 min readMay 19, 2023

--

IVR, or Interactive Voice Response, is an automated phone system that allows callers to interact with a computer-controlled system and perform tasks such as obtaining information, routing calls to the appropriate department, or completing transactions. It is commonly used in industries such as healthcare, banking, telecommunications, and e-commerce, to improve customer service and streamline business operations. IVR can conduct surveys, collect feedback, and provide automated technical support, making it an efficient and cost-effective tool to enhance the customer experience.

In this blog we will be creating an Interactive Voice Response (IVR) system for hospitals, focused on providing COVID-related functionalities. This system will benefit both patients and hospitals by reducing the risk of Covid infections for patients, and easing the burden on hospitals from non-Covid patients. With the IVR, patients can interact with the hospital system from the safety of their homes and perform tasks such as scheduling appointments, checking test results, or obtaining medical advice. This will not only reduce the number of unnecessary visits to the hospital but also improve the overall efficiency of the hospital’s operations. By leveraging technology to provide essential services, hospitals can ensure the safety of their patients and staff while maintaining the highest level of patient care. This blog is inspired by the following set of videos (Chapter 1. Introduction and Call flow | AWS Connect Tutorial | Read The Manual)

In these blog posts, we will discuss how an Interactive Voice Response (IVR) system can provide three essential functionalities for hospitals in managing Covid patients.

  1. The first functionality allows patients to book a Covid RT-PCR test at a date and time convenient to them by providing their social security information. This blog will cover this functionality (Booking flow).
  2. The second functionality enables patients to check the Covid status in the US, providing up-to-date information to help them make informed decisions. Preceding blog will cover this functionality (US-Covid flow).
  3. The third functionality allows patients to check the hospital’s hours of operation, ensuring they can receive medical attention when needed. By utilizing IVR, hospitals can streamline their processes, reduce wait times, and improve the overall experience for patients while ensuring their safety during the pandemic.” Last blog will cover the third functionality (Talk to agent flow).

Booking a COVID RT-PCR Test

Booking Flow

This flow is used to book a Covid RTPC test on the date and time provided by the user respective to their social security number. For this we would need to get user input for date and time. And display the information in a play prompt. The prerequisite needed for this are as follows:

  • Create an AWS account for the functionality needed to build the IVR and chat.
  • Create an Amazon connect instance for the IVR and chat.
  • Create Two Amazon Lex bot needed for this flow. One Amazon Lex bot is needed to choose from the different Flows. The flows are named as “Booking”,”US-covid” and “Talk to agent”. The second Amazon Lex bot is needed to get the date and time for the covid RTPC test from the user.
  • Add slots to the Amazon Lex bot for getting the input. For the first Amazon Lex bot need slot “Social-Security-Number” and for the Second Amazon Lex bot need slots “GetDate” and “GetTime”. (Note: Here we are using SSN as a sample test. Driving License number or other ID can also be used)

Amazon Connect

Amazon Connect is a cloud-based contact center service provided by Amazon Web Services (AWS) that allows businesses to interact with their customers through various channels, including voice, chat, and email. It provides a scalable and cost-effective solution for customer service that can be customized to meet the unique needs of any organization.

With Amazon Connect, businesses can quickly set up and manage their contact center operations without the need for any on-premises hardware or software. They can also easily scale up or down to meet changing business demands, pay only for what they use, and benefit from AWS’s global infrastructure to provide reliable service to customers around the world.

Here are the prerequisites needed for this Amazon Connect project:

  1. Python
  2. Amazon Lambda
  3. Amazon Lex

The project we will be making is a Hospital IVR system to quickly access the information they need. It provides three options:

  1. Book an RTPC COVID test, allowing callers to schedule a test quickly and easily.
  2. Update on the current status of COVID-19 in the US.
  3. Provide information about the hospital’s office hours, allowing callers to plan their visit accordingly.

This is part one of a three-part series. In part one we will go through the prerequisites, create our IVR system, and add functionality of getting the COVID-19 status.

Create an AWS account

An AWS account is a user account used to access and manage Amazon Web Services (AWS) cloud computing resources. It provides a unique identity for a user or organization to interact with AWS services and manage their usage and billing. To create an AWS account, follow these steps:

  1. Go to the AWS website and click on “Create an AWS Account” button.
  2. Enter your email address and choose a password.
  3. Enter your personal or business information, including your name, address, and phone number.
  4. Enter your payment information. AWS requires a valid credit or debit card to verify your identity and prevent fraud.
  5. Choose a support plan. AWS offers several options, including Basic, Developer, Business, and Enterprise. I have chosen an Enterprise account but you can choose any account type and complete this project.
  6. Review and accept the AWS Customer Agreement and click the “Create Account and Continue” button.
  7. AWS will send a verification code to the email address you provided. Enter the code on the next screen.
  8. Choose your language preference and click the “Continue” button.
  9. AWS will then ask you to select a service plan, but you can skip this step if you prefer.
  10. Your AWS account is now created and ready to use. You can start exploring the AWS Management Console and the various services it offers.

Creating an Amazon Connect Instance

An Amazon Connect instance is a virtual contact center that provides a cloud-based solution for handling customer interactions across multiple channels, including voice, chat, and email. It includes tools for managing agents, routing calls, and analyzing performance metrics. To create an Amazon Connect instance, follow these steps:

  1. Log in to your AWS Management Console.
  2. Go to the Amazon Connect dashboard.
  3. Click on the “Create instance” button.
  4. Enter the required information for your instance, such as the name, description, and preferred region.
  5. Select the type of Amazon Connect instance you want to create: Standard or Amazon Connect with Voice ID. I have chosen the standard connect instance.
  6. Choose your phone number options. You can use your existing phone numbers, purchase new numbers, or transfer your existing numbers.
  7. Configure your Amazon Connect settings, including your hours of operation, routing options, and language preferences.
  8. Choose your storage options for call recordings and chat transcripts.
  9. Review and accept the Amazon Connect terms and conditions.
  10. Click on the “Create instance” button.

Your Amazon Connect instance will now be created, and you can start using it to create contact flows, configure routing, and manage your contact center operations.

Amazon Lex Bot

Creating an Amazon lex bot for the next part of the “Get Customer Input” flow block.

Amazon Connect Amazon Lex is an integration between Amazon Connect and Amazon Lex that allows for natural language understanding and speech recognition to automate customer interactions through chatbots and voice assistants. Here are the steps for creating the Amazon Lex Bot:

  • Open the Amazon Lex console.
  • Click on “Create” to create a new bot.
  • Choose a bot template or start with a blank bot. We will chose the blank bot
  • Enter the Bot name “MainMenu_hospital”. You can enter a Description for the bot but it’s optional so we won’t bother with it.
  • We are building the first bot so we will choose “Create a role with basic Amazon Lex permissions” in IAM permissions configuration.
  • As this is a test project and the subject does not concern children interaction with bot, so choose “No” in “Children’s Online Privacy Protection Act (COPPA)” configuration.
  • Leave default configuration as it is. Such as Select Language,voice and idle session timeout. Now click the “create” button.
  • Now as the bot is created, create the four intents named “Booking”,”Get-Social-Security-Number” and “fallback”
  • Add sample utterances for all the intents as following:
    - For “fallback” we add “whatever”, “none”, “nano” and “blha” in sample utterances.
  • - For “Booking” add “need to book covid test”,”booking of rtpc” and “booking” in sample utterances.
  • - For “Get-Social-Security-Number” add “My Social_Security_Number is {Social_Security_Number}”,”its {Social_Security_Number}” and “{Social_Security_Number}” in sample utterances.

Add Slots to Bot

Amazon Lex slots are data fields that capture specific information from user inputs during a conversation with a chatbot or voice assistant. They are used to gather and store information such as dates, names, and other important details required to fulfill a customer’s request. Using the following steps to add slot to Amazon Lex bot.

  • Click on the “Get-Social-Security-Number” intent.
  • Click on the “Add Slot Type” button in the “Slots” section of the intent.
  • In the “Create a custom slot type” dialog box, give your new slot type a name “Social_Security_Number” and select “Extended” as the type.
  • In the “Values” section, Enter value “[0–9]{9}”. This tells the slot to allow only numerical values up to 9 characters.
  • Click on the “Save” button to create the new slot type.
  • Now you can add the new slot type to one or more slots in the intent by selecting it from the drop-down list of slot types for each slot.
  • In the prompt section add value “Sorry,I didn’t get that,what is your Social Security Number?”

Add bot to contact flow

Using the following steps to add lex bot to the contact flow.

  • After entering the sample utterances we click the “Build” button.
  • Test the bot using the built-in chat interface or a test client.
  • Add the Amazon Lex bot to the Amazon connect contact flow: In the contact flow, add the Amazon Lex bot as a module. You can configure the module by specifying the bot’s name and alias.
  • Now back to contact flow canvas and click on the “Get Customer Input” and click on the Amazon Lex option which prompts us with “Select a Lex bot” and “Enter an ARN”.Choose the “Select a Lex bot” and choose the bot we already added to our current Amazon connect instance.
  • In the intent options add the following intents: “Booking” and “fallback”.

Second Amazon Lex bot

Creating another Amazon Lex bot so that it can easily categorize the amazon lex bot with different use cases. Will be using the second Amazon Lex bot to get date and time for the booking for the covid RTPC test. Using the following steps to create another Amazon Lex Bot:

  • Create another Amazon Lex bot as in (Amazon Lex bot). Change some attributes and options but for everything else you can revisit (Amazon Lex bot).
  • Choose the Bot name “DateandTime”,then two intents “GetDate” and “GetTime”. And create slots “DateValue” with built-in slot type “AMAZON.DATE” and “TimeValue” with built-in slot type “AMAZON.TIME” for the above mentioned intents respectively.
  • Add sample utterance for all the intents as following:
    - For “GetTime” add “at {TimeValue}”,”{TimeValue}”and “this {TimeValue}” in sample utterances.
  • - For “GetDate” add “coming {DateValue}”,”{DateValue}” and “at {DateValue}” in sample utterances.
  • Add the Amazon Lex bot to the Amazon connect contact flow: In the contact flow, add the Amazon Lex bot as a module. You can configure the module by specifying the bot’s name (DateandTIme) and alias.

Deploy loop in contact flow

Using loop flow block so that if the user enters the wrong input respective to the question we circle the user back to the same question again. Using the following steps to create a loop in the contact flow canvas:

  • Now on the canvas drag “Loop”,”Disconnect” and two “Play prompt” flow blocks.Connect “Get customer Input” three “fallback”,”Default” and “Error” flow to the “Loop”.
  • Don’t change the “Loop” block configuration as it is set to the number of loop two.
  • Connect the “looping” flow back to “Get customer input” block.
  • Connect the “Complete” flow to the first “Play prompt” with the “Text-to-speech or chat test” option in which enter “Sorry I didn’t get that,you can US Covid status. Book an RTPCR appointment.Speak with Covid specialist.”
  • Connect the first “Play prompt” block to the second “Play prompt” block with the “Text-to-speech or chat test” option in which we enter “Sorry, let me connect you with an agent.”
  • Connect the second “Play prompt” to “Disconnect” block which ends the call or chat.

Creating a Contact Flow

Amazon Connect contact flow is a visual representation of the customer experience, which includes a set of instructions for Amazon Connect to follow when interacting with customers on various channels, such as phone or chat, to efficiently route, queue, and handle their requests.

After the amazon connect instance is created, log into the created instance and move to contact flow and flow modules. To create a contact flow, follow these steps:

  • Give the new contact flow a name and go to canvas which will only have the “Start” flow block.
  • Drag and drop the “Set logging behavior” and “Set voice” flow blocks from the left-hand side.
  • “Set logging behavior” flow block is used to send data from all the other blocks to Amazon cloudwatch.
  • Amazon CloudWatch is an AWS service that provides monitoring, logging, and observability for AWS resources.
  • “Set voice” flow block is the select type of voice for your amazon connect instance. There are numerous options including both male and female to choose from.
  • Connect the “Start” flow block to “Set logging behavior” which is connected to the “Set voice” flow block.
  • Drag the “Set contact attributes” flow block to the canvas, this is used to assign custom data to a contact, which can be used to personalize the customer experience and optimize contact routing.
  • Add two attributes in the “Set contact attributes” block: Welcome and PolicyNumber. Set the destination type to “User defined” and set the Welcome text value to “Welcome to US covid hospital “ and the PolicyNumber to “123456” respectively.
  • Connect “Set voice” to “Set contact attributes”.
  • Drag the “play prompt” flow block to the canvas. In the block select option “Text-to-speech or chat text”. Put ‘<speak>$.Attributes.Welcome in the text option and set the policy number as <say-as interpret-as=”digits”>$.Attributes.PolicyNumber”</say-as></speak>
  • Connect “Set contact attributes” to “Play prompt”.

The Flow

Following “Booking” flow from the “Get customer Input” flow block. This flow is used to book an RTPC covid test on the date and time specified by the user, with respect to their Social Security number.Using the following steps to create US-covid flow.

  • Drag the “Get customer input” which is connected by the previous “Get customer Input” block in (Creating the Input branches) with the flow “Booking”.
  • In the “Get Customer Input” block we select option “Text-to-speech or chat text” and Enter text “Please provide 9 digits Social Security number?”
  • Now click on the Amazon Lex option which prompts us with “Select a Lex bot” and “Enter an ARN”. We choose the “Select a Lex bot” and choose the bot we already added to our current Amazon connect instance.
  • In the intent options we add the intent “Get-Social-Security-Number”.
  • Connect the “Get Customer input” flows “Intent” and “Error” to a Loop flow cycle exactly like the one we created in (Deploy loop in contact flow).
  • Drag the “Set contact attributes” which is connected by the “Get customer Input” block with the flow “Get-Social-Security-Number”.
  • Add attribute “Get-Social-Security-Number” in the “Set contact attributes” block:
    Set the destination type to “User defined” and set the option “Set Dynamically”. Set Namespace to “Lex”,set Value to “Slots” and set Slot Name to “Get-Social-Security-Number”.

Creating the Input branches

Creating the three flows:

  • Booking
  • US-covid
  • Talk to agent

Using the “Get Customer Input” flow block thus creating input branches. Here are the steps for creating different flows through input branches.

  • Drag the “Get Customer Input” flow block to the canvas.”Get Customer Input” is an Amazon Connect contact flow block that allows you to collect and process customer input during an interaction with your contact center.
  • Connect the “Play prompt” to the “Get Customer Input” block.
  • In the “Get Customer Input” block, select the option “Text-to-speech or chat text” and Enter text “how I can assist you?”.

Getting date for booking

These steps are followed to get the exact Date for the booking for the covid RTPC test.

  • Drag the “Get customer input” which is connected by the “Set Contact Attributes” block.
  • In the “Get Customer Input” block select option “Text-to-speech or chat text” and Enter text “Kindly provide the date you like to book the appointment.”
  • Now click on the Amazon Lex option which prompts us with “Select a Lex bot” and “Enter an ARN”. Choose the “Select a Lex bot” and choose the bot “DateandTime”.
  • In the intent options add the intent “GetDate”.
  • Connect the “Get Customer input” flows “Intent” and “Error” to a Loop flow cycle exactly like the one created in (Deploy loop in contact flow)
  • Drag the “Set contact attributes” which is connected by the “Get customer Input” block with the flow “GetDate”.
  • Add attribute “GetDate” in the “Set contact attributes” block:
    Set the destination type to “User defined” and set the option “Set Dynamically”. Now Set Namespace to “Lex”,set Value to “Slots” and set Slot Name to “GetDate”.

Getting time for booking

These steps are followed to get the exact time for the booking for the covid RTPC test

  • Repeat (Getting date for booking) with few changes.
  • Change Enter Text value for (Getting date for booking) line 2 to “Kindly provide the time you like to book the appointment.”
  • Change the intent value for (Getting date for booking) line 3,4,7 to “GetTime”.
  • Now connect the “Set Contact attributes” to the “Wait” block which holds the call or chat for the amount of time you specified.Specify it for 5 seconds to hold.
  • Connect “Wait” to “Play prompt” block and drag on to the canvas.In the block select option “Text-to-speech or chat text”. Put in the value “Your Social Security Number is $.Attributes.Get-Social-Security-Number. The booking has been confirmed for $.Attributes.DateValue and $.Attributes.TimeValue.Kindly keep your Social Security with you.”
  • Now connect the “Play prompt” block with the “Disconnect” block which terminates the call or chat.

Conclusion

Implementing an IVR system in your business can significantly empower your operations and enhance the customer experience. By integrating technologies like Amazon Lex and Amazon Connect, you can automate processes, provide self-service options, and improve efficiency in industries such as healthcare, banking, telecommunications, and e-commerce.

With an IVR system, you can enable customers to easily schedule appointments, check test results, or obtain medical advice, as demonstrated in the example of a COVID-related IVR system for hospitals. This not only reduces unnecessary visits but also ensures the safety of patients and staff during the pandemic.

By leveraging the power of IVR, businesses can streamline operations, reduce wait times, and collect valuable feedback from customers. The cost-effectiveness and scalability of cloud-based solutions like Amazon Connect make it an ideal choice for implementing an IVR system.

As technology continues to advance, the possibilities for IVR systems are endless. By staying updated on the latest advancements and integrating them into your business processes, you can stay ahead of the competition and deliver exceptional service to your customers.

So, embrace the potential of IVR systems and unlock a world of possibilities for your business. Empower your operations, enhance customer satisfaction, and drive growth with the transformative capabilities of an IVR system.

Stay tuned for the second and third blog in this series.

Author

Moeed Iftikhar
Data Engineer
DreamAI Software (Pvt) Ltd

--

--