Provide live agent assistance for your chatbot users with Amazon Lex and Talkdesk cloud contact center

Amazon Lex provides advanced conversational artificial intelligence (AI) capabilities to enable self-service support for your organization’s contact center. With Amazon Lex, you can implement an omnichannel strategy where customers engage via phone, websites, and messaging platforms. The bots can answer FAQs, provide self-service experiences, or triage customer requests before transferring to a human agent. Amazon Lex integrates with state-of-the-art contact centers including Amazon Connect, Genesys Cloud, and Amazon Chime SDK to facilitate a seamless omnichannel experience.

This is the second post of a two-part series. The integration of Amazon Lex with Talkdesk cloud contact center is inspired by WaFd Bank (WaFd)’s digital innovation journey to enhance customer experience. In our previous post, we described how Amazon Lex integrates with the Talkdesk cloud contact center for the voice channel. In this post, we are focusing on the chat channel to show how to use Amazon Lex and the Amazon Lex Web UI to enable live agents to interact with your customers in real time. For example, the following figure shows screenshots of a chatbot transitioning a customer to a live agent chat (courtesy of WaFd Bank).

Solution overview

The following diagram illustrates the solution architecture.

In the preceding architecture, the following sequence of steps takes place in a live customer/agent conversation:

Using the Amazon Lex Web UI, a customer asks to be connected to an agent. The associated Amazon Lex chatbot is configured with an escalation intent to process the incoming agent assistance request.
The Amazon Lex fulfillment AWS Lambda function retrieves the Talkdesk touchpoint ID and Talkdesk OAuth secrets from AWS Secrets Manager and initiates a request to Talkdesk Digital Connect using the Start a Conversation API. In the payload, the function includes information that may be useful to an agent, such as the customer sentiment or the history of previously traversed intents.
If the request to the Talkdesk API is successful, a Talkdesk conversation ID is returned to Amazon Lex.
The Amazon Lex fulfillment Lambda function stores the conversation ID in Amazon Lex session attributes, thus making the conversation ID accessible to the Amazon Lex Web UI.
The Amazon Lex Web UI opens a communication session with agents on the Talkdesk contact center through a WebSocket API in Amazon API Gateway.
The Lambda associated with the WebSocket API first stores the Talkdesk conversation ID to WebSocket client ID mappings in Amazon DynamoDB. Then, through the Talkdesk Send a Message API, the Lambda function sends the customer’s message to the agent on Talkdesk contact center.
Your agent responds to the customer with a message sent through the callback Rest API in API Gateway. The payload includes the conversation ID of the active conversation.
The callback Rest API is configured to support the agents’ incoming messages as well as the agent’s closing of the conversation. In order to send the agent’s message to the customer, the supporting Lambda function reads the WebSocket client ID associated to the conversation ID from the DynamoDB table. This makes sure the agent’s message is delivered to the appropriate WebSocket client ID.
The agent’s response is displayed through the Amazon Lex Web UI and the customer responds or closes the chat as appropriate. Steps 6–9 are repeated as long as the conversation remains active. If the agent ends the conversation, the customer is notified and the WebSocket connection is closed.

In the following sections, we walk you through the steps to build the solution architecture. Dependencies among each step are cross-referenced.

Prerequisites

To implement the solution presented in this post, you should first familiarize yourself with the following AWS services and features:

Amazon API Gateway

WebSocket API operations
Rest API operations

Amazon CloudWatch
Amazon DynamoDB
AWS Identity and Access Management (IAM)
AWS Lambda
Amazon Lex

Amazon Lex Web UI

AWS Secrets Manager

Additionally, you should be familiar with the following Talkdesk services:

Talkdesk cloud contact center account
Talkdesk Digital Engagement with chat channel for agents
Talkdesk Digital Connect API – To send messages to the agent, use the following Talkdesk Digital Connect API components:

Start a Conversation – Create an identifier used to interact with an agent
Send a Message – Send a message to the agent

Prepare your Talkdesk instance for the Amazon Lex Web UI chat with an agent

This section outlines the basic steps required to configure the Talkdesk chat with agent experience using the Talkdesk Digital Connect channel. Review Talkdesk APIs for further details for any additional tasks that may be required as part of your specific implementation.

Complete the following steps:

Enable Talkdesk Digital Connect on your Talkdesk instance.
Configure your agents’ accounts and assign them to the agents’ queues.
Build a Talkdesk Studio flow.

This will be used to send chat users to an inbox for agents to assign. A sample is provided with this solution.

To create an integration for your Amazon Lex Web UI instance, in the Talkdesk Builder navigation pane, select Integrations.
On the Actions tab, configure three actions using the input and output schemas provided through the following links:

conversation_ended
conversation_started
message_created

Create a Talkdesk Digital Connect Touchpoint.
Name the Touchpoint Lex Web UI Chat and record the Touchpoint ID.

This will be stored in Secrets Manager as dev/talkdesk/touchpoint/ids.

In Talkdesk Builder, choose OAuth Clients in the navigation pane to set up OAuth credentials.
Select Grant type for Client credentials and set Scope to digital-connect:write.
Record the client ID and secret key from the Keys tab.

These will be stored in Secrets Manager as dev/talkdesk/client/keys and used to authenticate and communicate with the Talkdesk API.

In your AWS account, store the two secrets in Secrets Manager.

The following screenshot shows the details of the Touchpoint ID as a Secrets Manager secret.

The following screenshot shows the details of the client ID as a Secrets Manager secret.

Deploy the Talkdesk Amazon Lex CloudFormation template

The following AWS CloudFormation template creates all the resources of the solution architecture. This includes all necessary IAM roles to invoke API operations, run associated Lambda functions, access secrets on Secrets Manager, and store and retrieve conversation ID and WebSocket client ID pairs from DynamoDB.

To facilitate monitoring and debugging, a CloudWatch log group is created for each of the resources.

The CloudFormation template provides additional details for each of the resources.

Complete the following steps to deploy the template:

Sign in to the AWS Management Console.
Choose Launch Stack for your AWS Region to begin the CloudFormation stack creation process.

US East (N. Virginia)

US West (Oregon)

Asia Pacific (Singapore)

Asia Pacific (Sydney)

Asia Pacific (Tokyo)

Europe (Frankfurt)

Europe (Ireland)

Europe (London)

For Stack name, enter a name.
For TDAUTHHOST, enter the URL of your Talkdesk instance.
Leave the other parameters as default and choose Next

Select the acknowledgement check boxes and choose Create stack.

After the CloudFormation template is complete, record the values for the following keys on the Outputs tab to use in later steps:

APIGatewayApiKey
BotAliasId
BotId
CallbackRestAPI
WebSocketAPIEndpoint

Update the Talkdesk instance

Log in to your Talkdesk instance and complete the following steps to update your instance:

In Talkdesk Builder, select Integrations in the navigation pane.
On the Settings tab, locate Base path and enter the callback Rest API URL you recorded earlier.
Under Other settings, set x-api-key to the value of the API Gateway key.

Deploy the Amazon Lex Web UI

The solution outlined in this post uses the Amazon Lex Web UI, a full-featured web client to deploy your Amazon Lex chatbot on your website. With the Amazon Lex Web UI, you can quickly bring your chatbot-powered application to life while minimizing time-to-value.

Choose Launch Stack for the Region in which you will use your chatbot:

US East (N. Virginia)

US West (Oregon)

Asia Pacific (Singapore)

Asia Pacific (Sydney)

Asia Pacific (Tokyo)

Europe (Frankfurt)

Europe (Ireland)

Europe (London)

For LexV2BotId, enter the value for BotId.
For LexV2BotAliasId, enter the value for BotAliasId.

Launch the stack.
When deployment is complete, locate the Amazon Simple Storage Service (Amazon S3) URL for WebAppBucket.
Navigate to the S3 bucket on the Amazon S3 console and download the lex-web-ui-loader-config.json file.

Open the file and modify or add the following parameters:

In the connect configuration section, add the new parameter talkDeskWebsocketEndpoint and set its value to the WebSocket endpoint.
In the UI configuration section, set enableLiveChat to true.

Upload the modified lex-web-ui-loader-config.json file and overwrite the previous version of the file in the S3 bucket.
Return to the CloudFormation stack Outputs tab and find the WebAppDomainName link.

This will redirect you to a full-page version of the Amazon Lex Web UI. From here, you can test the Talkdesk integration and confirm that the bot is able to connect to Talkdesk using the WebSocket connection.

Test the solution

Now you’re ready to try the Amazon Lex and Talkdesk chat interaction:

Start your Banking Bot chat window using the WebAppUrl provided as output in the CloudFormation stack.
Log in to your Talkdesk Digital Connect channel and navigate to Conversations.
In the Banking Bot chat window, request to talk to an agent.
Watch the customer’s message being delivered to the Talkdesk Conversations Inbox.
The Talkdesk agent self-assigns the conversation and starts engaging with the customer.

The following video demonstrates the chat experience.

Clean up

To clean up your resources, complete the following steps:

On the AWS CloudFormation console, select Stacks in the navigation pane.
Select the LexTalkdesk stack (or the stack name you provided), and select Delete.
Delete the stack resources by selecting Delete stack.

Conclusion

Amazon Lex brings the power of conversational self-service to your customer preferred channels, such as phone, web chat, and messaging applications. In this post, we demonstrated a solution that provides live agent assistance on your website with Amazon Lex, Amazon Lex Web UI, and Talkdesk cloud contact center. We provided a CloudFormation stack that includes DynamoDB and Lambda resources, and a Rest API and WebSocket API in API Gateway to maintain a communication session with agents in the Talkdesk contact center.

This solution is meant to be a reference architecture or a quick implementation guide that can be tailored to suit your organization’s requirements. If you need help setting up this solution, AWS Professional Services and Talkdesk are available to help you and your team through the process of selecting the right technologies for your cloud contact center.

About the authors

Grazia Russo Lassner is a Senior Consultant with the AWS Professional Services Natural Language AI team. She specialises in designing and developing conversational AI solutions using AWS technologies for customers in various industries. Outside of work, she enjoys beach weekends, reading the latest fiction books, and family time.

Austin Johnson is a Solutions Architect, helping to maintain the Lex Web UI open source library.

Chris Brown is a Principal Natural Language AI consultant at AWS focused on digital customer experiences – including mobile apps, websites, marketing campaigns, and most recently conversational AI applications. Chris is an award-winning strategist and product manager – working with the Fortune 100 to deliver the best experiences for their customers. In his free time, Chris enjoys traveling, music, art, and experiencing new cultures.

Bruno Mateus is a Principal Engineer at Talkdesk. With over 20 years of experience in the software industry, he specialises in large-scale distributed systems. When not working, he enjoys spending time outside with his family, trekking, mountain bike riding, and motorcycle riding.

Jonathan Diedrich is a Principal Solutions Consultant at Talkdesk. He works on enterprise and strategic projects to ensure technical execution and adoption. Outside of work, he enjoys ice hockey and games with the family.

Crispim Tribuna is a Senior Software Engineer at Talkdesk currently focusing on the AI-based virtual agent project. He has over 17 years of experience in computer science, with a focus on telecommunications, IPTV, and fraud prevention. In his free time, he enjoys spending time with his family, running (he has completed three marathons), and riding motorcycles.

Resources