Skip to content

How to Limit Outbound Calls per Agent in Amazon Connect Contact Center?

0

I'm managing an Amazon Connect contact center and need to implement a system that prevents agents from making too many outbound calls within a specific time frame. Specifically, I want to limit agents to N calls within an M-minute window. What's the best way to implement this restriction using AWS services? I'm looking for a solution that's scalable, reliable, and integrates well with Amazon Connect.

AWS
EXPERT

asked 2 years ago395 views

1 Answer
0

To limit the number of outbound calls an agent can make in Amazon Connect within a specific time window, you can implement a solution using several AWS services. Here's a detailed approach to achieve this:

  1. Amazon DynamoDB Table: Create a DynamoDB table to store call records with the following attributes:

    • Agent ID (Partition Key)
    • Call Start Time (Sort Key)
    • Phone Number
    • Queue Name
    • Outbound Caller ID
  2. AWS Lambda Function: Develop a Lambda function that agents will invoke before making an outbound call. This function will: a) Insert a new call record into the DynamoDB table. b) Query the DynamoDB table to count calls made by the agent in the last M minutes. c) Compare the count against the limit N. d) Return a response indicating whether the call should be allowed or blocked.

  3. Amazon SNS Topic: Set up an SNS topic to send notifications when an agent exceeds the call limit.

  4. IAM Role for Lambda: Create an IAM role for the Lambda function with permissions to:

    • Read and write to the DynamoDB table
    • Publish to the SNS topic
    • Stop contacts in Amazon Connect
    • Create CloudWatch logs
  5. Outbound Whisper Flow: Create an outbound whisper flow in Amazon Connect that: a) Sets contact attributes to capture the agent's username. b) Invokes the Lambda function before placing the call. c) Uses the Lambda function's response to either proceed with the call or end it.

  6. Queue Configuration: Configure the outbound queue to use the new outbound whisper flow.

Here's a sample Python code for the Lambda function:

import os
import boto3
import logging
from datetime import datetime, timedelta
from botocore.exceptions import ClientError

# Initialize logging and AWS clients
logger = logging.getLogger()
logger.setLevel(logging.INFO)
dynamodb = boto3.resource('dynamodb')
sns = boto3.client('sns')
connect_client = boto3.client('connect')

# Environment variables
TABLE_NAME = 'outbound_calls'
SNS_TOPIC_ARN = os.environ['SNS_TOPIC_ARN']
CALL_LIMIT = int(os.environ['CALL_LIMIT'])
TIME_WINDOW_MINUTES = int(os.environ['TIME_WINDOW_MINUTES'])

def lambda_handler(event, context):
    try:
        # Extract details from the event
        details = event['Details']['ContactData']
        user_id = details['Attributes']['agent_username']
        queue_name = details['Queue']['Name']
        outbound_number = details['CustomerEndpoint']['Address']
        contact_id = details['ContactId']
        instance_id = event['Details']['ContactData']['InstanceARN'].split('/')[-1]

        current_time = datetime.now()
        
        # Insert call record
        insert_call_record(user_id, current_time, queue_name, outbound_number)
        
        # Check call count
        call_count = get_call_count(user_id, current_time)
        
        if call_count > CALL_LIMIT:
            send_notification(user_id, call_count)
            end_contact(contact_id, instance_id)
            return {"allowCall": False}
        
        return {"allowCall": True}

    except Exception as e:
        logger.error(f"Error: {str(e)}")
        raise

def insert_call_record(user_id, timestamp, queue_name, dial_number):
    table = dynamodb.Table(TABLE_NAME)
    table.put_item(Item={
        'UserId': user_id,
        'CallStartTime': timestamp.isoformat(),
        'QueueName': queue_name,
        'OutboundDialNumber': dial_number
    })

def get_call_count(user_id, current_time):
    table = dynamodb.Table(TABLE_NAME)
    time_window_start = current_time - timedelta(minutes=TIME_WINDOW_MINUTES)
    response = table.query(
        KeyConditionExpression=boto3.dynamodb.conditions.Key('UserId').eq(user_id) & 
                               boto3.dynamodb.conditions.Key('CallStartTime').between(time_window_start.isoformat(), current_time.isoformat())
    )
    return response['Count']

def send_notification(user_id, call_count):
    message = f"Agent {user_id} has exceeded the call limit with {call_count} calls in the last {TIME_WINDOW_MINUTES} minutes."
    sns.publish(TopicArn=SNS_TOPIC_ARN, Message=message)

def end_contact(contact_id, instance_id):
    connect_client.stop_contact(
        InstanceId=instance_id,
        ContactId=contact_id
    )

To implement this solution:

  1. Create the DynamoDB table and SNS topic.
  2. Deploy the Lambda function with the necessary environment variables and IAM role.
  3. Create the outbound whisper flow in Amazon Connect, invoking the Lambda function.
  4. Configure the outbound queue to use the new whisper flow.

This solution provides a scalable and reliable way to limit outbound calls per agent in Amazon Connect. It leverages DynamoDB for efficient data storage and retrieval, Lambda for serverless computation, and SNS for notifications. The system is flexible and can be easily adjusted by modifying the CALL_LIMIT and TIME_WINDOW_MINUTES variables.

Remember to implement a cleanup process for old DynamoDB records to manage table size and costs. You can use a scheduled Lambda function or AWS Glue job for this purpose.

AWS
EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.