Extend Amazon Connect capabilities with Lambda and LexV2
Published: 2024-03-14 09:46:32


Amazon Connect comes with a reach set of features, from call recordings to live sentiment analysis or the ability to prompt agents with step-by-step guides to solve customer requests.

But no product has all features built-in. The beautiful thing about Connect is it is fully integrable with other AWS services that will help you customize your customer experience.

In this post, I show how I extended Connect’s capabilities with Lambda and Lex to add some features a customer requested: the ability to reach a person directly using a phone extension and to look up a name in the company directory.

![](https://cdn-images-1.medium.com/max/2560/1*5CgyrOZ-e_HfD3tVNUDEIA.jpeg)

## What is Amazon Connect?

Amazon Connect is AWS’ Contact-Center-as-a-Service (CCaaS) product. It means you can run a call center with no telecom skills, without the burden of managing IPBX or SBG infrastructure.

Following Amazon Web Services “pay-as-you-go” approach to product pricing, there is no licence or fixed fee. This means you pay only $0,018/minute.

AWS made huge investment in the product. In my [blog post about last re:Invent](https://www.terracloud.fr/en/blog/2022/12/05/aws-reinvent-2022-notre-bilan/), I stressed that, apart from EC2 silicon, it was in 2002 AWS’ first service in terms of new features announcements (and it has kept on since).

In the public references, you’ll find big names, such as the Accor hospitality group or the Sixt car rental company, and much smaller companies such as Margaritas, a family-owned restaurant in Texas.

![Amazon Connect Flow Designer makes it easy to customize the customer experience](https://cdn-images-1.medium.com/max/2000/1*AuVfJ5j09cb_adr_396liw.png)

## Adding support for phone extensions with AWS Lambda

Given Amazon Connect primary use case (run a contact center, not a telephone switchboard), there is no built-in feature to assign each agent an extension number for direct contact. (You can still natively direct a call to a specific agent, for instance one that is assigned on the customer case, or one that is the customer single point of contact)

Fortunately, Amazon Connect (i) comes with a complete API, (ii) support adding agent custom information using Tags and (iii) can trigger a Lambda function.

AWS Lambda is a service where you basically put code and AWS takes care about all the underlying infrastructure (from machine to runtime). Invocations cost $0,0000133334 per Gb.second (which means my function that runs on a 128Mb Lambda for 130ms can run about 5 million times before it costs me one single dollar).

![Demonstrated architecture](https://cdn-images-1.medium.com/max/3292/1*PT5C0xcsWcIABWD5KjOOgg.png)

First, let’s hear how it sounds like!
{% embed https://soundcloud.com/paul-santus-44431746/amazonconnect-transfer-based-1 %}

Here is how I did it:

First, I assigned a custom tag called “Extension” to every agent in the directory.

I then designed a flow that first requests customer to dial the Extension (this prompt is interruptible, so customers can save a contact +12345678910#777 in their phone). Here is what is looks like:

![](https://cdn-images-1.medium.com/max/2400/1*GtJ6cnvs5PFEYjdz6DecQg.png)

The second box persists user input in the contact session. The third box checks whether customer entered an extension. If they didn’t, then we’ll skip to the Directory part of this post.

The Lambda is invoked with an event that contains information on the call and uses the [Amazon Connect SearchUsers API](https://docs.aws.amazon.com/connect/latest/APIReference/API_SearchUsers.html#API_SearchUsers_SeeAlso) to find the agent associated with the extension number.
{% gist https://gist.github.com/psantus/52f7cefb874b19b4f8a0ec68d2a66f32.js %}
Et voilà !

We now have in the Amazon Connect session all the information we need to forward the call to the agents personal queue.

## Adding Support for Interactive Directory Look Up using Lex

Maybe the customer doesn’t know the agent’s extension number.. but only their name. And you can’t dial a name, can you? Here comes Lex!

Amazon Lex is a chat bot; unlike ChatGPT, its role is not to make lengthy conversations but to elicit a user’s intent (among a number of predetermined intents) and collect information (called “slots”) in order to fulfill that intent. 
Lex can work as a standalone service and is also able, at any point during the conversation, invoke a Lambda in order to perform some processing and decide on the next step.

Here we’ll make it possible to reach sales and support teams, as well as mention we’d like to talk to a specific person.

![](https://cdn-images-1.medium.com/max/2000/1*WmPknfCb6EtL5HTrGma29g.png)

First, let’s hear how it sounds like!
{% embed https://soundcloud.com/paul-santus-44431746/amazonconnect-transfer-based %}

In the first part of the conversation, Lex determines that the customer want to perform a Directory look-up. To do that I only had to give Lex some phrases customer would utter, such as “Find someone by name”, or “Speak to a specific person”. When I provided 8 of them, the bot was quite able to interpret any request that comes close.

Then Lex tries to elicit the callee’s family name. Since my name is not a usual English one, the first Directory search fails (it tries to find “Santos” instead of “Santus” — yes I could make it more clever).

I wrote my Lambda code so that Lambda asks Lex to re-elicit the name, this time using spelling instead of just natural language.

    {
        "sessionState": {
            "dialogAction": {
                "type": "ElicitSlot",
                "slotToElicit": "Name",
                "slotElicitationStyle": "SpellByWord"
            },
            "sessionAttributes": {
                "attemptNumber": 2
            },
            "intent": {
                "name": "SpeakToSpecificPerson"
            }
        },
        "messages": [
            {
                "contentType": "PlainText",
                "content": "Sorry, we did not find any contact with this family name. Could you please spell it for me?"
            }
        ]
    }

As you can see, even with my Frenchie accent, Lex can then capture the right name, then Directory lookup returns the same data as previously, enabling us to transfer the call to the agent and also gracefully provided the Extension number to make the customer’s life simpler next time.

## Need some help?

In this post, I demonstrated how I integrated Amazon Connect, Lambda and Lex to create a powerful customer experience. With these features, you can turn add the telephone switchboard features Amazon Connect needs to address the needs of some smaller companies.

Like always, if you need help to get started on AWS cloud services or help you boost your customer experience using Amazon Connect, please get in touch on [https://www.terracloud.fr](https://www.terracloud.fr) or follow me [on LinkedIn](https://www.linkedin.com/company/terracloud/)!

![](https://cdn-images-1.medium.com/max/3358/1*I1eGawFBHvbF2QRZcAbeXA.jpeg)