UPDATE 04/01/2021: I found a great workshop resource, created by AWS, which shows the same I wanted to show in these tutorials, so I won’t continue this series. Have a look at the Amazon Connect Bootcamp.

Welcome back! In this next installment of this series we will continue the build of our Pizza Ordering service. We begin with some contact flows and create a simple Lambda function that will fetch some customer data from our backend system. With that data we can greet our customers with a customized welcome message.

Building our first contact flow

In this post I will show you how to create some basic contact flows. In essence contact flows allow you to control how the calls will flow through your contact center. Each flow consists of content blocks that each represent a certain action. For example, it allows you to play a message while a caller is waiting or request input from the caller. Contact flows are modular and allow you to create flows that can be reused across you contact center. We will start by creating the following 3 flows.

Overview

Unicorn Pizza Main Flow This is where our caller enters the contact center. We will use this flow to configure some basics such as a logging and the voice used in our contact center. We will also invoke a Lambda function that queries our backend DynamoDB table to determine if the caller is a returning customer or not. We then play a welcome message to our customer, set the working queue to which the customer needs to be transferred and finally invoke the next contact flow that will perform the actual transfer.

Unicorn Pizza Transfer to Queue In this flow we will check if the call is made within the hours of operation of our Pizza shop, and when it does we will transfer the caller to the queue set by the Main Flow. If not, we will play the user message and disconnect the call.

Unicorn Pizza Default Customer Queue This flow is activated once the caller is in the queue and will allow us to play some waiting music or messages to our customers while they are waiting.

Default Customer Queue

Now the fun part begins! We will start with the Default Customer Queue, as we need to call this flow from our other contact flows.

  1. On the Dashboard page select Contact Flows from the Routing menu on the left.

Amazon Connect

  1. On the Contact Flows page, click the small arrow next Create contact flow and select Customer Queue Flow.

Amazon Connect

As you see there are multiple other flow types available:

  • Contact Flows is the main flow type in Amazon Connect. You can this to guide your caller through your contact center interactively, by for example prompting the user for input, playing messages and setting the right agent queue based on their inputs.
  • Customer Queue Flows is flow type that is used while your caller is waiting in the queue. Yes, this is where you can play the customer the same boring elevator-type music.
  • Customer Hold Flows are comparable to Customer Queue Flows but can be activated when an agent puts the caller on-hold.
  • Customer Whisper Flows are where you can announce to the caller that they are about to be connected to an agent.
  • Outbound Whisper Flows are when an agent makes and outbound call to a customer. It can for example be used to play the customer a message before being connected to the agent.
  • Agent Hold Flows are used when the agent is put on hold.
  • Agent Whisper Flows are used to send a message to the agent just before the caller is connected. It can be used to send some details about the caller to the agent before the caller is connected.
  • Transfer to agent flows are used to announce to the caller they are about to be transferred to an agent.
  • Transfer to queue flows are used to announce to the caller they are about to be transferred to a queue.
  1. You have now entered the Amazon Connect Flow designer, a drag-and-drop interface where you can create flows by selecting actions from the menu on the left. After dragging an action on to the workflow you can connect the different block together to design the flow. Start by setting the name of the flow to Unicorn Pizza - Default Customer Queue.
  2. From Interact section on the left menu, drag the Loop prompts action on to the workflow and connect it to the Entry point.
  3. Next, from the Terminate / Transfer section add the End flow / Resume action and link the block to the Error branch of the Loop prompts block. Your flow should now look like this.

Amazon Connect

  1. We now need to configure the properties of the Loop prompts block. To open the properties click the header of block. A configuration pane will open on the right side of the screen. Click Add another prompt to the loop, select Text to Speech and enter a message you want to played to the caller while waiting in the queue, for example something like Thank you for calling Unicorn Pizza. All our agents are currently busy. Please hold, and we will answer your call as soon as possible.. Next click, Add another prompt to the loop again but now select Audio Recording and pick one of the options prefixed with Music. Click Save. Note: I’ve added some nice Italian folk music, to make it match our Pizza shop branding. If you want to do the same, you can do so by selecting the Prompts option from the Routing menu in the left navigation bar.

Amazon Connect

  1. Hit Save to save your flow and Publish to active it.

Transfer to Queue

In this flow we will check if the call is made within the hours of operation of our Pizza shop, and when it does we will transfer the caller to the queue set by the Main Flow. If not, we will play the user message and disconnect the call.

  1. On the Dashboard page select Contact Flows from the Routing menu on the left.

Amazon Connect

  1. On the Contact Flows page, click the Create connect flow button.
  2. Build out the following flow by dragging the required actions from menu on left.

Amazon Connect

  1. Set the following properties.
  • On the Set recording and analytics behaviour block set Call recording to On for both the Agent and Customer. This will record all calls and save them to the S3 bucket that was created during the initial set-up of Amazon Connect.
  • On the Play prompt block that is linked to the Error branch of the Check hours of operation and Transfer to queue block, set the Text-to-speech or chat text message to something like Unicorn Pizza is not able to take your call at this time, please try again later.
  • On the Play prompt block that is linked to the Out of Hours branch of the Check hours of operation block, set the Text-to-speech or chat text message to something like Unicorn Pizza is currently closed. We are ready to serve you from Tuesday to Sunday from 11:30 AM to 11:00 PM. The connection will now be closed. Arrivederci!
  1. Hit Save and Publish.

Main flow preparations

Before we tie everything together in our main flow, we first need to deploy a simple Lambda function and DynamoDB table that will hold our customer contact information. Once a Lambda function is called from a contact flow it will receive an event similar to the one below. We can use this event to identify our caller by phone number.

{
    "Details": {
        "ContactData": {
            "Attributes": {},
            "Channel": "VOICE",
            "ContactId": "236c21ad-5404-4d92-bfee-2a2d18364c6d",
            "CustomerEndpoint": {
                "Address": "+316xxxxxxx",
                "Type": "TELEPHONE_NUMBER"
            },
            "CustomerId": null,
            "Description": null,
            "InitialContactId": "236c21ad-5404-4d92-bfee-2a2d18364c6d",
            "InitiationMethod": "INBOUND",
            "InstanceARN": "arn:aws:connect:eu-central-1:xxxxxxxxxxxx:instance/b36844db-328d-46b4-a344-35cc245cf3d2",
            "LanguageCode": "en-US",
            "MediaStreams": {
                "Customer": {
                    "Audio": null
                }
            },
            "Name": null,
            "PreviousContactId": "236c21ad-5404-4d92-bfee-2a2d18364c6d",
            "Queue": null,
            "References": {},
            "SystemEndpoint": {
                "Address": "+3185xxxxxxxx",
                "Type": "TELEPHONE_NUMBER"
            }
        },
        "Parameters": {}
    },
    "Name": "ContactFlowEvent"
}

In our Lambda function we can then make a simple query to our DynamoDB table to lookup the customer information and if available return it to Amazon Connect. If not, the Lambda will report back that the customer is unknown.

import boto3
import os
from boto3.dynamodb.conditions import Key

tablename = os.environ.get('TABLENAME')
dynamodb = boto3.resource('dynamodb')

def lambda_handler(event, context):
    phonenumber = event['Details']['ContactData']['CustomerEndpoint']['Address']
    table = dynamodb.Table(tablename) 
    response = table.query(
        IndexName='phoneNumber',
        KeyConditionExpression=Key('phoneNumber').eq(phonenumber)
    )
    

    if response['Count'] > 0:
        first_name = response['Items'][0]['firstName']
        last_name = response['Items'][0]['lastName']
        return {
            'customer': 'returning',
            'firstName': first_name,
            'lastName': last_name
        }
    else:
        return { 
            'customer': 'unknown'
        }

To deploy the Lambda function, the DynamoDB table and related resources I created CloudFormation template that you can find here. I’ve used a global secondary index on the DynamoDB table, as I expect that our returning customers have already registered through our website before and have validated their phone number there. And no, this is not production ready code.

  1. Download the CloudFormation template here and navigate to the CloudFormation console in the region in which you deployed your Amazon Connect instance. Deploy the provided template.

Amazon Connect

  1. Once the deployment of the template is complete navigate to the DynamoDB console and select Items from the menu on the left. Select the the table we just created and click Create Item.

Amazon Connect

  1. On the Create item page, create an item with the following properties.

Amazon Connect

Alternatively, select JSON on the top right and paste in the following item:

{
  "emailAddress": {
    "S": "<your e-mail here>"
  },
  "phoneNumber": {
    "S": "<your phone number here>"
  },
  "firstName": {
    "S": "<your first name>"
  },
  "lastName": {
    "S": "<your last name>"
  }
}

Make sure to enter your mobile phone number according to the E.164 International Standard for Phone Number Format: [+][country code][subscriber number including area code].

  1. Once the item is created go the Amazon Connect console and select your instance.

Amazon Connect

  1. On the left menu, click Contact flows and scroll down to Lambda functions.
  2. Select the UnicornPizza-CustomerLookup Lambda function and click + Add Lambda Function. By adding the Lambda function, you are granting Amazon Connect permission to invoke it.

Amazon Connect

Main flow

  1. Navigate back to your Amazon Connect Dashboard browsing to your instance url (https://your-instance-name.my.connect.aws).
  2. On the Dashboard page select Contact Flows from the Routing menu on the left.

Amazon Connect

  1. On the Contact Flows page, click the Create Contact flow button.
  2. Build out the following flow by dragging the required actions from menu on left.

Amazon Connect

  1. Set the following properties.
  • On the Set voice block, select your preferred voice. I picked Sally.
  • On the first Play prompt block, play a welcome sound. I’ve added a very short version of the music file used in the default customer queue.
  • On the Invoke AWS Lambda Function block, select the function we created earlier.
  • On the Set contact attributes block, create two attributes, one for firstName, one for lastName.

Amazon Connect

  • On the Play prompt block connected to the Success branch of the Set contact attributes block, set the Text-to-speech or chat text option to Hi $.Attributes.firstName. Welcome back to Unicorn Pizza.
  • On the Play prompt block connected to the Error branch of the Set contact attributes block, set the Text-to-speech or chat text option to Welcome to Unicorn Pizza!
  • On the top Set working queue block, set the working queue to Unicorn Pizza - Returning Customers.
  • On the bottom Set working queue block on, set the working queue to Unicorn Pizza - Unknown Customers.
  • On the Set customer queue flow block, select the Unicorn Pizza - Default Customer Queue we created before.
  • On the Transfer to flow block, select the Unicorn Pizza - Transfer to Queue flow.
  • On the Play prompt block below the Set customer queue flow, set the message to We are experiencing technical difficulties. Please try again later.
  1. Hit Save and Publish.

Activating the main flow

The last thing we need to do is connecting our main flow to the phone number we configured in the previous post.

  1. From the Routing section in the menu on the left, select Phone numbers.
  2. Click on the number in Phone Number column.

Amazon Connect

  1. For Contac flow / IVR select the Unicorn Pizza - Main Flow

Amazon Connect

  1. Click Save.

Testing

We can now dial our phone number to validate the flows. You can try various things by editing the Hours of operations, to simulate a call outside of those hours. To simulate an unkown caller you remove your contact details from the DynamoDB table. If you followed the steps correctly (and I didn’t miss anything), the flow should roughly sound like this:

Example 1: call from returning customer, within hours of operation

Example 2: call from returning customer, outside of hours of operation

Wrap-up

This wraps up my second post on Amazon Connect. In this post you’ve learned the basics of contact flow creation and how fetch data from an external source. In the next post I want to integrate Amazon Lex to allow our customers to order Pizza using via a chat bot.

comments powered by Disqus