How can we help you?

Amazon Connect - Caller Queue Position

by Daniel Jandey, DevOps Engineer
In this blog I will show you how to integrate Lambda Functions with your Amazon Connect instance and implement a 'Caller Queue Position' system.
What is Amazon Connect?

Amazon Connect is a cloud contact centre which is a service within Amazon Web Services. You create 'Contact Flows' to control how your callers interact with your contact centre.

Amazon Connect has plenty of inbuilt features to get started, but if you want to integrate with any of your external services you'll have to do this by using the 'Invoke Lambda Function' block. This allows you to run Lambda functions within the same AWS region and account.

How does the 'Invoke Lambda Function' Block work?

When using the Lambda block, an 'Event' from Amazon Connect is sent through. Events are unique to the individual caller, or in Connect terms the 'Contact'.

Each time a caller hits your first flow, they are assigned a Contact Id.

In some instances, transferring your contact between flows can change the Contact Id, but the Initial Contact Id will always remain the same.

The event will contain attributes about the contact such as their Contact Id, attributes set during the contact flow and in this case, parameters that can be sent to the Lambda function directly.

Example: Amazon Connect - Caller Queue Position   1.png

The Lambda function can return results after being invoked, which are returned as key-value pairs. You can access these results using the 'External' attribute set.

Note: Only results from the last invocation are stored. If you need to run an additional Lambda function and keep these results, store them as a 'User defined attribute' which will remain during the whole contact flow.

You can read more about the available attribute list here.

In the event above, we are calling the Lambda function, with the following value: Amazon connect 3.png

In which we send back the response to Amazon Connect: amazon connect 4.png

As mentioned above, you can access the attribute via , or save it as a 'User Defined' attribute for later reference. $.External.queue_position, or save it as a 'User Defined' attribute for later reference.

Queue Position Solution

The only thing you need to get started is an Amazon Connect Instance. The resources can be deployed using this CDK Stack. Example Contact Flows for this solution are also provided.

Essentially the solution will be to;

  • Add contacts to the DynamoDB table using the unique 'Initial Contact' Id as they enter the queue. (Customer Queue Flow)
  • Retrieve their position in the queue every x amount of seconds and play a message stating their position. (Customer Queue Flow)
  • Remove the contact from the DynamoDB table when the call is answered. (Customer Whisper Flow)
  • Remove the contact from the queue if they disconnect or leave the call before it has been answered. (Customer Disconnect Flow? Unfortunately it does not exist.)

We will need to keep track of the last time each individual contact retrieved their position and update that time in DynamoDB.

If a contact hasn't retrieved their position in over x amount of seconds, we can assume they have disconnected the call and remove them from DynamoDB. It's not a perfect solution.

Amazon Connect 5.png

Resources
  1. Lambda Function
    • amazon-connect-queue-position-lambda
  2. Lambda IAM Role and Policy
    • amazon-connect-queue-position-role
    • amazon-connect-queue-position-policy
  3. DynamoDB Table
    • amazon-connect-queue-position
Preparation
  1. Run the Stack

amazon connect 7.png

  1. Add the Lambda Function to Amazon Connect

Go into the Amazon Connect console and add the Lambda function to your Contact Flows:

Amazon connect 8.png

Contact Flows

Create the following flows in order, as the primary Contact Flow will be dependant on the 'Customer Whisper' and 'Customer Queue' Flows.

Customer Queue

When the contact gets placed in the queue, the Lambda function will run once with the 'add_to_queue' function.

After the 'Loop Prompt', every x amount of seconds the Lambda function will retrieve the queue position, output it as a Contact Attribute and play the following prompt:

"Thanks for staying on the line. You are currently the number x caller in the queue."

Customer Whisper

The Customer Whisper flow will run as soon as the caller is connected to the agent. For this example, we will have a single Lambda invoke block to remove the caller from the queue. amazon connect 11.png

Inbound Flow

The Inbound flow will be used to set the 'Customer Queue' and 'Customer Whisper' flows: amazon connect 14.png

Behind the Scenes

In this example, we can see 2 contacts currently in the queue. The position number is derived from the order of the 'queue_started_time' field.

amazon connect `5.png