How to get task status in Amazon connect

0

Hi How can you get task status programatically in amazon connect. Essentially i want to query the status of a task before sending another one to amazon connect . To see if it's expired or handled etc.. is this possible? I had look in api docs I couldn't find what I am after I would like to be able track the status of task so I can query them Please advise Cheers Codebug

CodeBug
asked a year ago405 views
2 Answers
1

we have an example please update accordingly

and before Please refer to the following documentation about GetContactAttributes

https://docs.aws.amazon.com/connect/latest/APIReference/API_GetContactAttributes.html

import boto3

connect_client = boto3.client('connect')

# Replace contact_id with the ID of your contact
response = connect_client.get_contact_attributes(
    InitialContactId='contact_id'
)

# Extract the status attribute from the response
status = response['Attributes']['status']

# Do something based on the status
if status == 'handled':
    # Handle the task
elif status == 'expired':
    # The task has expired

profile picture
EXPERT
answered a year ago
  • Thanks for the info . Essentially I have an external app wants to query the status of a a task that has been submitted in the past. The attribute status you have provided is not available for tasks . I can only see it available for cases? From where I cant get the proper status for tasks. then i can add it as an attribute

  • Sorry i have added another answer for this one

1

as a workaround

https://docs.aws.amazon.com/connect/latest/APIReference/API_StartTaskContact.html#API_StartTaskContact_RequestSyntax

When creating a task, you can set custom attributes for the task. Add an attribute (e.g., "status") to the task with an initial value (e.g., "pending"). This way, you will be able to track the status of the task.

response = connect_client.start_task_contact(
    InstanceId='your_instance_id',
    ContactFlowId='your_contact_flow_id',
    Name='your_task_name',
    Attributes={
        'status': 'pending'
    }
)

Inside the contact flow associated with the task, use a Lambda function or an Amazon Connect API to update the "status" attribute based on the task's progress (e.g., "in_progress", "completed", "failed", etc.).

To query the status of a task from your external application, you can use the get_contact_attributes API call as mentioned in my previous response. You can then use the "status" attribute value to determine the current status of the task.

profile picture
EXPERT
answered a year ago
  • I'm aware when a task expires we can trigger a contact flow, and set an attribute like you suggest

    From: https://docs.aws.amazon.com/connect/latest/adminguide/set-disconnect-flow.html

    A disconnect event is when:

    1. A chat, or task is disconnected.
    2. A task is disconnected as a result of a flow action.
    3. A task expires.

    I appreciate for (2) we could set an attribute saying it's a status = "disconnected due to something in the flow" but I cannot see how we'd discriminate between (1) and (3)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions