How do I prevent agents in my Amazon Connect contact center from making outbound calls to specific phone numbers?

Last updated: 2021-12-16

I don't want agents in my Amazon Connect contact center to call certain countries or premium rate phone numbers. How do I prevent those calls?

Short description

In an outbound whisper flow contact flow, invoke an AWS Lambda function that checks whether a dialed phone number is allowed. If the phone number isn't allowed, then stop the contact using the Amazon Connect StopContact API.

Note: The solution in this article has the following limitations:

  • It can't block queued callbacks. When an agent initiates a callback, the contact ID that's passed through the outbound whisper flow isn't the actual contact ID.
  • It can't block calls if the Lambda function fails to invoke. If the function fails, the contact follows the error branch of the contact flow and the call isn't stopped.
  • It's a basic example. For your production environment, customize your setup for your use case and the agents' dialing permissions.

Resolution

Create a Lambda function

1.    Using the runtime of your choice, create a Lambda function. Include function logic that checks an incoming JSON request from Amazon Connect for the following:

  • Agent user name (under "Attributes")
  • Current contact ID ("ContactId")
  • Dialed phone number (under "CustomerEndpoint")
  • Initial contact ID ("InitialContactId")
  • The contact center's Amazon Resource Name (ARN) ("InstanceARN")

For more information, see the List of available contact attributes and their JSONPath reference. For an example JSON request to a Lambda function, see Invoke a Lambda function from a contact flow.

Tip: Add specific logic to your function code according to your use case. For example, you can check contact attributes against an internal database of agent dialing permissions. For more information, see Lambda functions and attributes.

2.    Make sure that your function also includes a call to the Amazon Connect StopContact API. In the API call, specify the "ContactId" and "InstanceId" of the contacts that you want to stop.

Important: You must attach an AWS Identity and Access Management (IAM) policy to the function's execution role with sufficient permissions to call the StopContact API. The following example JSON policy document includes the basic permissions to call the API:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "StopContactPermission",
            "Effect": "Allow",
            "Action": "connect:StopContact",
            "Resource": "*"
        }
    ]
}

Example Python (Boto3) function code

Note: This example code includes the condition to identify which number to block. If that number is a requested callback number, the function handles the API error and passthrough.

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0

import boto3
from botocore.exceptions import ClientError
connect = boto3.client('connect')

def lambda_handler(event, context):
    response = {
            'phoneNumberBlockerMessage': 'Passing through AmazonConnectPhoneNumberBlocker. No contact is blocked.'
    }

    try:
            if event['Details']['ContactData']['CustomerEndpoint']['Address'] == '<telephone-number-condition>':
                # Stop contact here

                connect.stop_contact(
                    ContactId = event['Details']['ContactData']['InitialContactId'],
                    InstanceId = event['Details']['ContactData']['InstanceARN'].split('/')[1]
                )
                response = {
                    'phoneNumberBlockerMessage': 'Call is blocked.'
                }
    except ClientError as e:
            if e.response['Error']['Code'] == 'ContactNotFoundException':
                response = {
                    'phoneNumberBlockerMessage': 'This is either a callback contact or contact ID does not exist, contact pass through.'
                }
            else:
                # Handle other error
                pass
    return response

Add the Lambda function to your instance

Create an outbound whisper contact flow

Important: To create and edit contact flows, you must log in to your Amazon Connect instance as a user with sufficient permissions in their security profile.

1.    Log in to your Amazon Connect instance using your access URL (https://alias.awsapps.com/connect/login -or- https://alias.awsapps.com/connect/login).
Important: Replace alias with your instance's alias.

2.    In the left navigation pane, hover over Routing, and then choose Contact flows.

3.    On the Contact flows page, choose the arrow icon next to Create contact flow, and then choose Create outbound whisper flow.

4.    In the contact flow designer, for Enter a name, enter a name for the contact flow. For example: Outbound whisper (Stop).

5.    Choose Save.

For more information, see Create a new contact flow.

Add a Set contact attributes block

Configure this block to get the agent's user name, which you send to Lambda to parse.

1.    In the contact flow designer, expand Set.

2.    Drag and drop a Set contact attributes block onto the canvas.

3.    Choose the block title (Set contact attributes). The block's settings menu opens.

4.    Under Attribute to save, choose Use attribute. Then, do the following:
For Destination key, enter a key name. For example, agent_username.
For Type, choose Agent.
For Attribute, choose User name.

5.    Choose Save.

Add an Invoke AWS Lambda function block

1.    In the contact flow designer, expand Integrate.

2.    Drag and drop an Invoke AWS Lambda function block onto the canvas.

3.    Choose the block title (Invoke AWS Lambda function). The block's settings menu opens.

4.    Under Function ARN, choose Select a function. Then, choose the Lambda function that you added to your instance.

5.    (Optional) For Timeout (max 8 seconds), enter the number of seconds Amazon Connect will wait to get a response from Lambda before timing out.

6.    Choose Save.

For more information, see Invoke a Lambda function from a contact flow.

Finish the Outbound whisper flow

1.    Add and connect more contact blocks to your outbound whisper flow as needed for your use case.
Note: For example use cases, see sample contact flows.

2.    Connect all the connectors in your contact flow to a block. Be sure to connect the Success node of the Set contact attributes block to the Invoke AWS Lambda function block. You must use at least the following blocks:
Entry point > Set contact attributes > Invoke AWS Lambda function > End flow / Resume

3.    Choose Save to save a draft of the contact flow.

4.    Choose Publish to activate the contact flow.

Configure a queue with the outbound whisper flow

In the routing profile that your agents are assigned to, identify the default outbound queue. For more information, see Create a routing profile.

To edit the queue, do the following:

1.    In your Amazon Connect instance, in the left navigation pane, hover over Routing, and then choose Queues.

2.    On the Queues page, choose the name of the queue that you identified as the default outbound queue.

3.    On the Edit queue page, select the outbound whisper flow that you created from the Outbound whisper flow (optional) menu.

4.    Choose Save.