How to send SMS from IVR in Amazon Connect

One great thing about AWS is how easy it is to integrate different services. Here is one of the examples.

Let's say you want to build the following solution:

  • Clients are calling your contact center and when they press a certain option in the IVR you want to send them an SMS message. What this message contains depends on your requirements. In my case, I send an SMS with a link to instructions on how to install a new mobile application.
  • Before sending the message you want to verify if this is a valid client and not just a random person.

You can do that by integrating Amazon Connect with Amazon Simple Notification Service (SNS).

Here is how to do that:

Step 1.

I created DynamoDB table called Clients.

It contains phone numbers for each client and some other information about each client.

Phone numbers must be in E.164 format.

Step 2.

I created Lambda function sendSMS. I use Python 3.9

How it works:

1. I get the contact attribute Customer number to get the phone number of the caller.

2. I run a query and check if this phone number is in Clients tables.

3. If it is found - it means it is a valid client

4. After that I connect to SNS and use action publish to send SMS.

In my example message is hardcoded in my Lambda function but depending on your particular requirements you can make it dynamic.

Here is my Lambda function:

import json
import boto3
from botocore.exceptions import ClientError
from boto3.dynamodb.conditions import Key

def lambda_handler(event, context):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('Clients')
    message="Link on how to setup our new mobile application http://tinyurl.com/AmazonConnectSMS"

    response = table.query(
    for item in resp:

            if phoneNumber==CLID:            
                 # Create an SNS client
                client = boto3.client("sns",region_name="us-east-1")
                # Send SMS message
                return {
                    'statusCode': 200,
                    'body': json.dumps('OK')

Step 3.

Now I just need to add my lambda function to Amazon Connect IVR flow.

I created a simple call flow. 

It plays the following message:

"Hello. Welcome to IT Helpdesk. If you are calling from a mobile device about instructions on how to setup a new application please press 1 and we will send you instructions by SMS."

If the client presses 1 I invoke Lambda function sendSMS. Quite simple.

No comments:

Post a Comment