Building voice menus and call routing with the Amazon Chime SDK
In November 2020, we launched the SIP media applications (SMA) feature in the US and certain other countries to make it easier for builders to enable Amazon Chime SDK meeting attendees to join via a landline or mobile phone. With SMA, builders can add phone numbers and customized voice menus to Amazon Chime SDK meetings using a simple AWS Lambda function. Today, we launched a new capability in SMA, called CallAndBridge that enables you to transfer incoming calls to the public switched telephone network (PSTN) or to an on-premises phone system without the need to create an Amazon Chime SDK meeting. That means you can now use SMA to implement additional telephony use cases like interactive voice response (IVR) systems, remote call forwarding, sequential ringing, and outbound voice notifications.
Note: Deploying this demo and receiving traffic from the demo created in this post can incur AWS charges.
This solution will help you build a voice menu system using Amazon Chime SDK SIP media applications, Amazon DynamoDB, AWS Lambda, and Amazon Simple Storage Service (S3), and Amazon Polly.
- node/npm installed
- AWS Command Line Interface (AWS CLI) installed
- Latest version of AWS Cloud Development Kit (AWS CDK) installed
- AWS CDK bootstrapped
- Ability to create an Amazon Chime SDK SIP media applications and add Phone Numbers (ensure your Service Quota for Phone Numbers has not been reached)
This solution uses three AWS Lambda functions to implement the voice menus and emulate the on-premises phone systems to which phone calls will be routed. The first Lambda function, inboundSMA, will handle incoming phone calls. The second Lambda function, createWav uses Amazon Polly to create .wav files and store them in an Amazon S3 bucket. The third AWS Lambda function, emulatorSMA, simulates an on-premises phone system that answers the transferred call and plays a confirmation message.
During solution setup, three new phone numbers will be automatically purchased from Amazon Chime and associated with the Lambda functions as follows:
- inboundSMA – inboundPhoneNumber
- emulatorSMA – salesPhoneNumber
- emulatorSMA – supportPhoneNumber
Since the exact phone number is not be known until after purchase, these are represented as inboundPhoneNumber, salesPhoneNumber, and supportPhoneNumber accordingly in the description.
To make the association between phone numbers and the Lambda function, the solution setup process provisions SIP rules and SIP media application instances.
Once configured, when a caller places a call to the inboundPhoneNumber, inboundSMA Lambda performs the following steps:
- Answers the call and plays a welcome prompt
- Uses the
From:parameter (Caller ID) in the
NEW_INBOUND_CALLpayload to fetch the associated account ID from a DynamoDB table.
- If the Caller ID has an associated account, it plays a prompt and requests the caller to key in ‘1’ for sales or ‘2’ for support.
- If the Caller ID has no associated account ID, the caller will be asked to enter their account ID using their keypad.
- The entered account ID will be stored in DynamoDB.
- The DynamoDB update then triggers the createWav Lambda function to create a wav file of the account ID using the Amazon Polly text to speech service. The resulting .wav file is stored in an S3 bucket that will be accessed by the emulatorSMA Lambda function.
- The incoming call is then transferred to the phone number corresponding to the caller’s selection (‘1’ – salesPhoneNumber or ‘2’ – supportPhoneNumber. The Calling Number of the call to the emulator is the original calling number.
When the transferred call arrives on a phone number associated with the emulatorSMA, it will perform the following steps:
- Using the
From:parameter (Caller ID) in the
NEW_INBOUND_CALLpayload, fetch the associated account ID.
- Play the account number back to the caller from the S3 bucket and hang-up.
This step assumes you have completed all the prerequisites, and you have access to Amazon Chime service.
- Clone this repo:
git clone https://github.com/aws-samples/amazon-chime-sma-bridging
chmod +x deploy.sh
Test the solution
- From a normal phone, place a call to the inboundPhoneNumber.
- When prompted, enter your fictitious account number.
- When promoted, enter ‘1’ for sales
- You should then hear your account ID spoken back to you.
To clean up this demo, please use the
cdk destroy command or delete the stack in AWS CloudFormation. Additionally, phone numbers and SIP media application should be removed from the Amazon Chime console manually. After doing this, you will no longer incur charges.
This example shows how you can easily build voice menus and call routing using the CallAndBridge feature. While this was a simple example, the same primitives can be used to implement more advanced telephony features that enterprise customers use in their day-to-day business processes. That means customers can now begin to migrate on-premises telephony workloads to the cloud to help reduce operational costs, create scalability, and enhance disaster recovery.
Please see our github repo for the example code: https://github.com/aws-samples/amazon-chime-sma-bridging