DEV Community

Cover image for Extend Amazon Connect capabilities with Lambda and LexV2
Paul SANTUS for AWS Community Builders

Posted on • Updated on

Extend Amazon Connect capabilities with Lambda and LexV2

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.

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, 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

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

First, let’s hear how it sounds like!

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:

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 to find the agent associated with the extension number.


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.

First, let’s hear how it sounds like!

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?"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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 or follow me on LinkedIn!

Top comments (0)