AWS Contact Center
Use Alexa devices to initiate customer service with Amazon Connect
Introduction
Customers expect multiple channel options when contacting customer service departments. Amazon Alexa smart speakers have become increasingly popular in households globally. Contact center innovators can exceed customer expectations by enabling Alexa as an additional channel with Amazon Connect. Adding Alexa as a channel will provide customers with additional choice and convenience, resulting in a better customer experience.
For example, if a customer encounters a technical issue when using Alexa to control their smart home thermostat, traditionally, the customer would have to call the thermostat company’s customer service number. A better customer experience would be to provide an option for self-service help or connect with a customer service agent, via voice or chat, directly from their Alexa device.
Utilizing Amazon Connect in conjunction with Alexa will enhance customer experience using intuitive voice for self-service. The solution also provides the option to connect with an agent when self-service is not sufficient to resolve customer inquiries.
This blog post shows how to use Amazon Connect and Alexa Skills Kit to enable Alexa users to perform self-service and to request to speak or chat with a contact center agent.
Overview
In the above architecture:
- The user interacts with Alexa device by speaking their intent.
- The Alexa Skills invokes the AWS Lambda endpoint to process the intent:
- Voice interaction (the intent is to speak to an agent): the Lambda invokes the Amazon Connect startOutboundVoiceContact API which calls the CreateCallBackFlow contact flow to queue a call to the callback queue.
- Chat interaction (the intent is to chat with an agent): the Lambda invokes Amazon Simple Notification Service to send a text with a link to a webpage with an embedded Amazon Connect custom chat widget.
- The user is connected to a contact center agent:
- Voice interaction: when an agent picks up the call from the callback queue, Amazon Connect calls the user and connects the user with the agent.
- Chat interaction: the user clicks on the chat widget. The chat widget invokes the ChatCustomerQueue contact flow which connects the user with a chat agent.
Prerequisites
Here are the prerequisites for this blog post:
- An AWS Account with access to:
- An existing Amazon Connect instance with a Claimed phone number and a configured agent linked to the Basic routing profile.
- Procure a toll-free number in Amazon Pinpoint for SMS and Voice (follow these instructions) to programmatically send text messages via Amazon SNS.
- Create AWS Lambda functions.
- AWS Identity and Access Management (IAM) to create roles.
- AWS Systems Manager parameter store and AWS Secrets Manager to store credentials.
- Amazon CloudWatch to create log group and to troubleshoot.
- An Alexa developer account and Alexa Skills Kit Command Line Interface (ASK CLI).
- A website to embed an Amazon Connect custom chat widget (you can refer to this README for instructions on how to create a website to host an Amazon Connect custom widget).
- Support tools for AWS Cloud Development Kit (CDK):
- AWS Command Line Interface (CLI) used by AWS CDK to deploy resources to your AWS account.
- Node.js to run the AWS CDK toolset.
You must select an AWS Region that supports all required services in this post. We have validated this solution for the AWS us-east-1 and us-west-2 regions. Please refer to AWS Regional Services for more details on AWS Services availability per AWS Region.
Walkthrough
In the Amazon Connect console, you will create two inbound contact flows and a custom chat widget. The first contact flow, CreateCallBackFlow, transfers an incoming call to a callback queue. The second contact flow, ChatCustomerQueue, transfers an incoming chat to a queue. You will also use AWS CDK to build and deploy an Alexa custom skill, the associated AWS Lambda service endpoint and required AWS IAM role. The Alexa custom skill enables customers to interact with Alexa to perform self-service and to request to speak or chat with a contact center agent.
Deployment steps
The following instructions assume a working knowledge of Amazon Connect, Alexa Skills Kit and AWS CDK. Please refer to the following links for more details on these topics:
Import contact flows into your Amazon Connect Instance
- Download the two contact flows, CreateCallBackFlow and ChatCustomerQueue from the following GitHub link.
- Sign into your Amazon Connect instance.
- Navigate to the Routing tab, select Contact flows and click on Create contact flow.
- Click on the drop-down menu (arrow) next to Save and select Import flow (beta).
- Click on Select and choose the CreateCallBackFlow file downloaded from step 1.
- Click on Save and Publish.
- Repeat steps 3 through 6 for ChatCustomerQueue.
Create custom chat widget
- Follow the Amazon Connect guide Add a chat user interface to your website to create your custom chat widget and embed it into your website. The inbound flow to select is ChatCustomerQueue.
Get code and dependencies using your preferred code editor by executing the following in your terminal
- Clone code repository:
git clone https://github.com/aws-samples/amazon-connect-alexa-skill-integration.git
- Install node libraries in the main cdk project directory:
cd amazon-connect-alexa-skill-integration & npm install
- Install node libraries for “ask-sdk-cre” lambda layer:
cd src/layers/ask-sdk-core/nodejs & npm install
- Change directory to project root:
cd ../../../../
- Install node libraries for “aws-sdk” lambda layer:
cd src/layers/aws-sdk/nodejs & npm install
- Change directory to project root:
cd ../../../../
Get Alexa developer credentials needed for AWS CDK
In this step, we will need to get the following credentials required by the AWS CDK skill construct to create the Alexa custom skill:
- Vendor ID: this represents the Alexa developer account.
- Client ID: this will be used for the client that needs to perform operations on the skill, in this case AWS CDK.
- Client Secret: secret value of the Client ID.
- Refresh Token: definition.
- Note down the Alexa developer Vendor ID.
- Sign into your Alexa developer Login with Amazon (LWA) console and create a LWA Security Profile.
- Fill in all required field and click Save. For this blog, you can enter https://example.com/privacy.html in the Consent Privacy Notice URL field.
- Configure the Return URLs and get the Client ID and Client Secret by hovering over the gear icon to the right of the created profile and click on Web Settings.
- Click on Edit, add http://127.0.0.1:9090/cb and https://s3.amazonaws.com/ask-cli/response_parser.html in the Allowed Return URLs field and make note of the Client ID and Client Secret:
- Generate a refresh token using ASK CLI. In your terminal, from the root of the project directory, type the following command:
npx ask util generate-lwa-tokens --client-id "<your Client ID>" --client-confirmation "<your Client Secret>" --scopes "alexa::ask:skills:readwrite alexa::ask:models:readwrite"
A browser window will open. Log in using your Alexa developer credentials.
- Click Allow.
- Close this browser tab and go back to your terminal. Note the value of the refresh token displayed in the terminal.
- Add the Vendor ID and Client ID into AWS Systems Managers parameter store. Add the Client Secret and Refresh Token into AWS Secrets Manager. This can be done by updating the provided shell script scripts/upload-credentials.sh with these values and running this script in the terminal.
Update Website URL, AWS account information and Amazon Connect attributes
- Update the website URL in the ChatWithTrainerIntentHandler section in /src/lambda/skill-backend/index.js file with your website URL.
- Update your AWS account and region information in /bin/alexa-cdk.ts file.
- Update the Amazon Connect attributes in /lib/alexa-cdk-stack.ts file under the Lambda Function for the Skill Backend section:
- ContactFlowID: this is the ID for the CreateCallbackFlow contact flow.
- DestinationPhoneNumber: this is your Claimed Phone Number in E.164 format.
- InstanceID: this is your Amazon Connect instance ID.
- QueueID: this is your BasicQueue ID.
Deploy using AWS CDK
In your terminal, make sure you are in the root directory of the project and execute the following:
- Bootstrap your AWS account for CDK:
npx cdk bootstrap
- Synthesize your project:
npx cdk synth
- Deploy your project:
npx cdk deploy
- Approve the IAM policies changes by entering y when prompted To Review and Approve…
Test the solution once the deployment completes successfully
Please note the solution deployed is for a fictional gym business. You can however apply this solution to any other business that offer Alexa as a channel of interaction to connect customers with their contact center agents.
- Log into the Amazon Connect Control Panel (CCP) and change your agent status to Available.
- Sign into the Alexa developer console.
- In the Skills tab, you should see your deployed skill. Click on the skill. This will take you to the Build tab.
- In the Build tab, select Endpoint. You will see the deployed Lambda in the Default Region box.
- Go to the Test tab to test the skill. Select to test the skill in Development. You can invoke your skill by typing open fitness geek. Alternately, you can speak this while holding down the microphone icon.
- Type or say, chat with a trainer, and provide your mobile number when prompted. You will receive a text message with the link to your website. Click on the website link, then click on the chat widget. You will now be connected via chat with the agent. Once you’re done chatting, put the agent back into Available status in the Amazon Connect CCP.
- Type or say, speak with a trainer, and provide your phone number when prompted. The agent will now receive a call into the Amazon Connect CCP. Once the agent answers the call, Amazon Connect will call the phone number that you have input as the customer phone number and connect the customer with the agent.
Code sample
Below section explains key code segment of the AWS Lambda src/lambda/skill-backend/index.js servicing the Alexa skill.
- Alexa Skill Kit Handler function for TrainerCallbackIntent triggered if the user intent is to speak with a trainer.
const TrainerCallbackIntentHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === "IntentRequest" && handlerInput.requestEnvelope.request.intent.name === "TrainerCallbackIntent"; }
- Call the Amazon Connect startOutboundVoiceContact API to request a callback.
var connect = new AWS.Connect(); var params = { DestinationPhoneNumber:process.env.DestinationPhoneNumber, ContactFlowId:process.env.ContactFlowId, InstanceId:process.env.InstanceId, QueueId:process.env.QueueId, Attributes:{ "CallbackNumber": cbPhoneNumber } }; try { connect.startOutboundVoiceContact(params, function(err, data) { if (err) { console.log("Error in adding call= "+err); console.log(err, err.stack) ; } else console.log(data); }); }
- Alexa Skill Kit Handler function for ChatWithTrainerIntent triggered if the user intent is to chat with a trainer.
const ChatWithTrainerIntentHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === "IntentRequest" && handlerInput.requestEnvelope.request.intent.name === "ChatWithTrainerIntent"; }
- Send the text message using Amazon SNS. The message contains the link to the website.
var params = { PhoneNumber:toPhoneNumber, Message: "Fitness Geek: please click on this link and chat widget: <YOUR WEBSITE URL HERE WITH CHAT WIDGET>", }; console.log("In Chat intent handler, params= "+JSON.stringify(params)) try{ var SNS = new AWS.SNS(); SNS.publish(params, function(err, data) { if (err){ console.log("Error in sending sms= "+err); console.log(err.err.stack); } }); }
Cleaning up
To avoid incurring future charges:
- Delete the deployed resources by executing the following command in the project root directory amazon-connect-alexa-skill-integration from CLI:
npx cdk destroy
- Undeploy the website, if you have deployed one for this blog.
- Contact flows imported for this blog can be deleted using the delete-contact-flow CLI command.
Conclusion
In this post, we have implemented a solution for Alexa device users to request to speak or chat with a contact center agent. The solution consists of Amazon Connect contact flows, Alexa custom skill and AWS Lambda endpoint. We used AWS CDK to deploy the Alexa custom skill and AWS Lambda endpoint.
If your use case requires connecting customers to specific agents based on their inquiries, you may consider adding intents to the Alexa skill and add additional routing logic to the Amazon Connect contact flows.
To learn more about Amazon connect, go to About Amazon Connect. To learn more about Alexa, go to About Alexa. Should you need help with setting this up, you can get assistance from AWS Professional Services or our Amazon Connect Partners.