Twilio can't redirect whatsapp chat to Flex using taskrouter

25 views Asked by At

I'm developing a WhatsApp chatbot utilizing Twilio and have structured my setup to integrate with AWS Lambda for dynamic task management. Here's an overview of my current workflow:

  • Incoming Message Handling:

    A Twilio number is configured with a webhook to trigger an AWS Lambda function (Python) whenever a new WhatsApp message is received.

  • Task Creation Logic:

    Based on certain conditions evaluated by the Lambda function, a task is programmatically created for handling within Twilio Flex.

  • Task Observation:

    The tasks are successfully created with the specified attributes, and I can observe these tasks within my Twilio TaskRouter tool. Furthermore, these tasks appear in the Twilio Flex dashboard as expected.

  • Issue Encountered:

    However, upon reaching Twilio Flex, these tasks do not facilitate a reply mechanism to engage in a conversation with the customer. The only available actions are to accept or decline the task. Once accepted, the sole option is to close the task, with no capability to reply to the message.

I am looking for assistance in enabling reply functionality for these programmatically created tasks so that agents can directly communicate with customers through Twilio Flex. The goal is to transition from an accepted task to an active conversation window where messages can be exchanged.

Questions:

  • Are there specific attributes or settings required when creating a task programmatically to enable reply functionality in Twilio Flex?
  • Is there a step I might be missing in my workflow that's crucial for enabling conversational interactions for these tasks?

Follows how I am creating the task in my Lambda function:

from twilio.rest import Client

def create_flex_task(phone_number): 
    account_sid = os.environ['TWILIO_ACCOUNT_SID'] 
    auth_token = os.environ['TWILIO_AUTH_TOKEN']
    workspace_sid = os.environ['TWILIO_WORKSPACE_SID']
    workflow_sid = os.environ['TWILIO_WORKFLOW_SID'] 
    twilio_number = os.environ['TWILIO_NUMBER']

    client = Client(account_sid, auth_token)
    
    try:
        task_attributes = json.dumps({
            'type': 'chat',
            'channel': 'whatsapp',
            'from': f'whatsapp:{phone_number}',
            'to': f'whatsapp:{twilio_number}',
            'name': 'John Doe', 
        })
    
        task = client.taskrouter.workspaces(workspace_sid).tasks.create(
                                                                    workflow_sid=workflow_sid,
                                                                    attributes=task_attributes,
                                                                    priority=1
                                                                )
        
        print(f"Task created with SID: {task.sid}")
        return task.sid
    
    except Exception as e:
        print(f"Failed to create task: {e}")
        return None

This is what I get in Twilio Flex:

Image of task in Twilio Flex before acceptance.

Image of task in Twilio Flex after acceptance.

I appreciate any insights or guidance on enabling reply functionality for these tasks in Twilio Flex. Thank you!

I experimented with modifying various attribute values during the task creation process, anticipating that the type attribute would play a crucial role in how Twilio Flex interprets and manages the task. Unfortunately, these adjustments did not resolve the issue as I had hoped.

0

There are 0 answers