September 21, 2020

AWS Connect: Announce the estimated wait time...

Create a Node.js 12.x runtime lambda function:

exports.handler = (event, context, callback) => {

let input = event.Details.Parameters.timeInQueue.substr(1);

(input > 60) ? callback(null, { "time":Math.floor(parseInt(input) / 60)}) : callback(null, { "time": 0 });


In the portal, browse to Services > Amazon Connect > Instance > Contact flows. Add the lambda function to grant it access to that telephony instance.

In your contact flow, add the Get Queue Metric flow block.

Add the Invoke AWS Lambda function flow block. In this flow block, specify the lambda function created earlier. For the function input parameters, select Use attribute. For Destination key, specify timeInQueue. For type, from the dropdown, select User defined. For attribute, type $.Metrics.Queue.OldestContactAge.

The value of $.Metrics.Queue.OldestContactAge in seconds is retrieved from the queue metric and assigned to the timeInQueue key. This key is passed to the function and rounded to the largest integer less than or equal to the calculated value.

Add the Check contact attributes block. Set type to External & attribute to time. Set the condition to check as Equal to 0. This means that if the wait time is less than 1 minute, since it is flooring the calculation, the value will be 0.

If the result is 0, let the call flow proceed as normal, that is, do not announce anything to the caller (you can change this if desired), otherwise, if there's no match (that is, estimated wait time is greater than 1 minute), send the output to the play prompt.

Add the Play prompt block. Select the text-to-speech option and then select the enter text option. In the text box, type in your announcement, for example:

<speak><amazon:domain name="conversational"> We hope to get to you quicker, however, our expected wait time is **$.External.time** minutes. Please continue to hold. </amazon:domain>

Set the prompt interpret-as to SSML.

The $.External.time retrieves the value of time calculated previously.

After the prompt is played, you can set up the logic required as the business dictates.