How to initiate task from IVR in Amazon Connect

UPDATE from 2021/11/20:

Amazon Connect now allows creating tasks from Contact Flow using a new contact block.

It means that you do not need to use Lambda functions to do that.

The New Create task block is quite intuitive. Now you can also specify if you want to create a task right away or schedule task creation in the future. 

More documentation is available here:


Lambda function that is mentioned below could be still useful if you want to trigger task creation, not from IVR. But for example from another Amazon AWS service.


Not long time ago Amazon introduced a new type of contacts available in Amazon Connect -  tasks.

In my article, I will show you an example of how to initiate a task from IVR.

How it could be useful?

For example, a client calls your IVR and requests a certain type of service that cannot be fully automated. In that case, you might profit from the ability to automatically create a task that will be then sent to an agent for processing.

Here is a sample scenario:

1) Client calls an IVR of  home internet provider company

2) IVR asks the client to enter the account number for identification

3) After that you ask the client what he wants to do with his current contract

  • option 1- upgrade
  • option 2 - renewal
  • option 3 - cancellation
4) For example client selects renewal 

5) Now we will initiate a task that will be sent to a queue that is responsible for contract renewals.

6) When an agent receives the task he would be able to see: account number, request type, and phone number of the person. 

Here is how it can be done in Amazon Connect:

Step 1.

The first step is to create a simple contact flow that will be used to send tasks to the required queue.

 What it does:
* Set working queue - to define Queue that will be used to receive tasks
* Transfer to queue - to send a task to the queue

Once you created the contact flow click on "Show additional flow information". You will see a long string of Contact Flow ARN. You need to copy the last 36 characters of it starting after contact-flow/. This is your ContactFlowId. You will need it in the next step.

Step 2.

I created Lambda function using Python 3.9 which is called initiateTask.

What it does:

1) Collects the following attributes from the call
* account number
* request type
* caller number
* InstanceARN - it is required to be able to get InstanceID, it is required to initiate task using Amazon Connect API

2) Using Amazon Connect API I initiate a task.

Important: you need to specify Contact Flow Id that will be used to send tasks to the queue.
This is Contact Flow that was created in the previous step.

3) You can also specify the URL that will be displayed in your task description.
It could be link to your CRM system or any other website.

Here is the full text of my Lambda function:

import json
import boto3

def lambda_handler(event, context):
    InstanceId = InstanceARN[-36:]

    client = boto3.client('connect')
    Description="Request type ="+requestType+". AccountNumber="+ accountNumber+". Caller number="+CLID
    response = client.start_task_contact(
            'URL': {
                'Value': URL,
                'Type': 'URL'
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('OK')

Step 3.

Now I will create another Contact flow that initiates the task.

This is how it works

1) Client calls the contact center

2) In the IVR I play the following message 
"Hello. Welcome to Internet on Demand. 
Please enter your 5-digit account number."

3) Client enters an account number

4) I save this information as User Defined attribute accountNumber

5) Now I play another message to the client

"How can we help you?
To request an upgrade press 1. 
To request a renewal without upgrade press 2. 
To cancel account press 3"

6) Depending on what the client selects I save the choice in User-defined attribute requestType

Example: when the client selects option 1 - upgrade

7) After that I invoke my Lambda function

8) At the end I play the following message
"Thank you. Your request was sent for processing. You can expect results in 24 hours."

Step 4.

Here is what the agent will see when the task arrives

No comments:

Post a Comment