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:

  1. The user interacts with Alexa device by speaking their intent.
  2. The Alexa Skills invokes the AWS Lambda endpoint to process the intent:
    1. 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.
    2. 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.
  3. The user is connected to a contact center agent:
    1. 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.
    2. 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:

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

  1. Download the two contact flows, CreateCallBackFlow and ChatCustomerQueue from the following GitHub link.
  2. Sign into your Amazon Connect instance.
  3. Navigate to the Routing tab, select Contact flows and click on Create contact flow.
  4. Click on the drop-down menu (arrow) next to Save and select Import flow (beta).
  5. Click on Select and choose the CreateCallBackFlow file downloaded from step 1.
  6. Click on Save and Publish.
  7. Repeat steps 3 through 6 for ChatCustomerQueue.

Create custom chat widget

  1. 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

  1. Clone code repository:
    git clone https://github.com/aws-samples/amazon-connect-alexa-skill-integration.git
  2. Install node libraries in the main cdk project directory:
    cd amazon-connect-alexa-skill-integration & npm install
  3. Install node libraries for “ask-sdk-cre” lambda layer:
    cd src/layers/ask-sdk-core/nodejs & npm install
  4. Change directory to project root:
    cd ../../../../
  5. Install node libraries for “aws-sdk” lambda layer:
    cd src/layers/aws-sdk/nodejs & npm install
  6. 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.
  1. Note down the Alexa developer Vendor ID.
  2. Sign into your Alexa developer Login with Amazon (LWA) console and create a LWA Security Profile.
  3. 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.
  4. 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.
  5. 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:
  6. 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.

  7. Click Allow.
  8. Close this browser tab and go back to your terminal. Note the value of the refresh token displayed in the terminal.
  9. 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

  1. Update the website URL in the ChatWithTrainerIntentHandler section in /src/lambda/skill-backend/index.js file with your website URL.
  2. Update your AWS account and region information in /bin/alexa-cdk.ts file.
  3. Update the Amazon Connect attributes in /lib/alexa-cdk-stack.ts file under the Lambda Function for the Skill Backend section:
    1. ContactFlowID: this is the ID for the CreateCallbackFlow contact flow.
    2. DestinationPhoneNumber: this is your Claimed Phone Number in E.164 format.
    3. InstanceID: this is your Amazon Connect instance ID.
    4. 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:

  1. Bootstrap your AWS account for CDK:
    npx cdk bootstrap
  2. Synthesize your project:
    npx cdk synth
  3. Deploy your project:
    npx cdk deploy
  4. 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.

  1. Log into the Amazon Connect Control Panel (CCP) and change your agent status to Available.
  2. Sign into the Alexa developer console.
  3. In the Skills tab, you should see your deployed skill. Click on the skill. This will take you to the Build tab.
  4. In the Build tab, select Endpoint. You will see the deployed Lambda in the Default Region box.
  5. 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.
  6. 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.
  7. 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.

  1. 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";
      }
  2. 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);
          });
       
        }
  3. 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";
      }
  4. 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:

  1. Delete the deployed resources by executing the following command in the project root directory amazon-connect-alexa-skill-integration from CLI:
    npx cdk destroy
  2. Undeploy the website, if you have deployed one for this blog.
  3. 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.