Resolve QueueARN by Queue Name Dynamically for Amazon Connect

Frequently when architecting and constructing a call experience for Amazon Connect, there are complexities to maintaining a unified experience while arriving at a specific Queue to ensure prompt service for the caller's need. To solve this multiplicity dynamically, our team of experts walks you through how we can derive the individual segments or components of the Queue name through the call experience associating the corresponding Queue by resolved ARN for the caller.
Industry
Products
Abstract
Results
Resolve QueueARN by Queue Name Dynamically for Amazon Connect

Overview

Frequently when architecting and constructing a call experience for Amazon Connect, there are complexities to maintaining a unified experience while arriving at a specific Queue to ensure prompt service for the caller's need. These situations often arise based on Country, Region, Dialed Number, Call Type, Intent, and Service.

Prerequisites:

  1. AWS Account with Console access
  2. Access to Amazon Connect & Lambda services
  3. Connect ARN

Solution overview

To solve this multiplicity dynamically we can derive the individual segments or components of the Queue name through the call experience associating the corresponding Queue by resolved ARN for the caller. For example, based on the number dialed, we can store a user-defined session attribute in Connect such as {Country: US}. Then as the Caller makes a selection in the voice call flows, assign an Intent such as {Intent: Billing}. Invoking a Lambda using AWS JavaScript Software Development Kit (SDK), the ARN of the Queue to associate the caller to may be resolved based on the criteria derived. Such as “$.Attributes.Country _ $.Attributes.Intent” will dynamically resolve to “US_Billing” for the example caller’s Queue.

Create the function.

You create a Node.js Lambda function using the Lambda console. Lambda automatically creates the default code for the function.

To create a Lambda function with the console

  1. Open the Functions page of the Lambda console.
  2. Choose to Create function.
  3. Select the Author from Scratch option (Default).
  4. Under Basic information, do the following:
  5. For the Function name, enter GetQueueARNByName.
  6. For Runtime, confirm that Node.js 16.x is selected.
  7. Choose to Create function.

Paste the Lambda code below and select Deploy.


const AWS = require("aws-sdk");
const connect = new AWS.Connect({region: process.env.AWS_REGION});
exports.handler = async (event) => {
    let params = {
      InstanceId: event.Details.Parameters.connectARN, /* required */
      MaxResults: 100,
      QueueTypes: [ 'STANDARD' ]
    };
    const queueName = event.Details.Parameters.queueName.replace(/ /g, '');
    const response = { queueARN: '', status: 'NotFound'};
    try{
      const queues = await connect.listQueues(params).promise();
      let queueFound = queues.QueueSummaryList.find(queue => queue.Name === queueName);
      if(queueFound){
        response.queueARN = queueFound.Arn.substring(queueFound.Arn.lastIndexOf('/') + 1);
        response.status = 'Success';
      }
      return response;
    } catch (error) {
        console.log(`getQueueName: ${error.toString()}`);
        return { status: 'Error', message: error.message };
    }
};
 

Grant Lambda Permissions

  1. Select the Configuration tab.
  2. Select the Role Name link.
  3. Within the new IAM service tab select Add Permissions dropdown, then select Create inline policy.
  4. Click Service and type Connect in the search box.
  5. Click Action and type listQueues in the search box and select listQueues.
  6. Click Resources and determine the resource to be allowed, updating the: Region, AccountId, and Connect Instance ARN.
    arn:aws:connect:us-west-2:740923######:instance/805a42e0-c859-468b-b8d6-#####*#*####/queue/*
  7. Select Review policy.
  8. Enter a name for the policy then select Create policy.

Testing the Lambda

Invoke your Lambda function using the sample event data provided in the console.

To invoke a function

  1. After selecting your function, choose the Test button.
  2. In the Test event section, choose New event. Enter a Name for this test and paste the following sample event template:


{
  "Name": "ConnectLambdaEvent",
  "Details": {
    "Parameters": {
      "connectARN": "805a42e0-c859-468b-b8d6-60007*#*####",
      "queueName": "BasicQueue"
    }
  }
}

    3. Choose Save changes, and then choose Test. The function handler receives and then processes the sample event. Upon successful completion, view the results in the console:


{
  "queueARN": “11816a48-f41f-4d24-8f74-**##*###*###",
  "status": "Success"
}

Add the Lambda function to your Amazon Connect instance

Before you can use a Lambda function in a flow, you need to add it to your Amazon Connect instance.

Add a Lambda function to your instance

  1. Open the Amazon Connect console at: https://console.aws.amazon.com/connect/.
  2. On the instances page, choose your instance name in the Instance Alias column. 
  3. In the navigation pane on the left, choose Contact Flows.
  4. In the AWS Lambda section, use the Function drop-down box to select the GetQueueARNByName function to add to your instance.
  5. Choose Add Lambda Function.

Invoke a Lambda function from a flow

  1. Open or create a flow.
  2. Add an Invoke AWS Lambda function block (in the Integrate group) to the grid. Connect the branches to and from the block.
  3. Choose the title of the Invoke AWS Lambda function block to open its properties page.
  4. Under Select a function, choose the GetQueueARNByName function you've added to your instance.
  5. Under Function input parameters, choose to Add a parameter. Specify key-value pairs as queueName and connectARN. queueName may be dynamically referenced based on user-defined session attributes as detailed below.

  1. In Timeout (max 8 seconds), specify how long to wait for Lambda to time out. After this time, the contact routes down the Error branch.
Note: The queueName will have the spaces removed in the Lambda function, the queue names should be named appropriately within the Connect instance to ensure accuracy in resolving by queue name.

Conclusion

The solution provided is a simple and effective way to dynamically resolve queues based on some simple conventions that can handle a fair bit of complexity in requirements. It does have some limitations. It scans all the queues for every match. It can’t handle a resolution that might depend on something else, like a CRM lookup (gold, silver, bronze) or hours of operation. That said, it's easy to imagine ways in which the concept can be extended further. By adding a table driven approach to the lookup it would be possible to avoid hitting the Connect API every time, and would be easy to incorporate additional fields that might be dependent on more complex scenarios. Taking such an approach would also allow for some simple management functions to allow call center managers to make changes without having to modify contact flows.

For help configuring dynamic Queues for your business or organization, contact us today!

Quick Facts
Industry
Products
Abstract
Results
The Best Outcomes
Back to Blog
Contact Us
View all Customer Stories
Contact Us
You may also like
Growing Insurance Company Enhances Customer Experiences with NeuraFlash, Salesforce & Amazon
Venture Capital and Financial Technology Company Innovates Faster Using Amazon Connect
Manufacturing Company Gains Asset Visibility with Salesforce Field Service