Business Productivity

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.

In this blog, we will teach you how to implement a simple voice menu system using SMA, the CallAndBridge feature, and a serverless AWS Lambda function. The Lambda functions in this solution are written in Javascript and Python.

Note: Deploying this demo and receiving traffic from the demo created in this post can incur AWS charges.

Overview

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.

Prerequisites

  • 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)

Walkthrough

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:

  1. inboundSMA – inboundPhoneNumber
  2. emulatorSMA – salesPhoneNumber
  3. 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:

  1. Answers the call and plays a welcome prompt
  2. Uses the From: parameter (Caller ID) in the NEW_INBOUND_CALL payload to fetch the associated account ID from a DynamoDB table.
  3. 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.
  4. If the Caller ID has no associated account ID, the caller will be asked to enter their account ID using their keypad.
  5. The entered account ID will be stored in DynamoDB.
  6. 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.
  7. 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:

  1. Using the From: parameter (Caller ID) in the NEW_INBOUND_CALL payload, fetch the associated account ID.
  2. Play the account number back to the caller from the S3 bucket and hang-up.

Solution setup

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
  • cd amazon-chime-sma-bridging
  • chmod +x deploy.sh
  • ./deploy.sh

Test the solution

  1. From a normal phone, place a call to the inboundPhoneNumber.
  2. When prompted, enter your fictitious account number.
  3. When promoted, enter ‘1’ for sales
  4. You should then hear your account ID spoken back to you.

Clean up

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.

Conclusion

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