Workflows control how tasks will be prioritized and routed into Queues, and how Tasks should escalate in priority or move across queues over time. Workflows are described in a simple JSON format and can be modified through the REST API or through the account portal.

Creating a Workflow

require 'Services/Twilio.php';

$accountSid = 'YOUR_ACCOUNT_SID';
$authToken = 'YOUR_AUTH_TOKEN';
$workspaceSid = 'YOUR_WORKSPACE_SID';

// instantiate a Twilio TaskRouter Client
$taskrouterClient = new TaskRouter_Services_Twilio($accountSid, $authToken, $workspaceSid);

// set workflow parameters
$friendlyName = 'Example Workflow';
$configuration = '{"task_routing":{"default_filter":{"task_queue_sid":"YOUR_TASK_QUEUE_SID"}}}';
$assignmentCallbackUrl = '';
$fallbackAssignmentCallbackUrl = '';
$taskReservationTimeout = 50;

// create a Workflow
$workflow = $taskrouterClient->workspace->workflows->create(
                'FallbackAssignmentCallbackUrl' => $fallbackAssignmentCallbackUrl,
                'TaskReservationTimeout' => $taskReservationTimeout

// confirm workflow created
echo 'Created Workflow: '.$workflow->sid;

Updating a Workflow

This example updates the above workflow’s configuration and task reservation timeout.

$workflowSid = 'YOUR_WORKFLOW_SID';

// updated workflow parameters
$updatedConfiguration = '{"task_routing":{"default_filter":{"task_queue_sid" : "YOUR_UPDATED_TASK_QUEUE_SID"}}}';
$updatedFallbackAssignmentUrl = '';
$updatedTaskReservationTimeout = 150;

// update workflow
                'Configuration' => $updatedConfiguration,
                'TaskReservationTimeout' => $updatedTaskReservationTimeout

echo 'Updated Workflow: '.$workflowSid;

Deleting a Workflow

$workflowSid = 'YOUR_WORKFLOW_SID';
echo 'Deleted Workflow: '.$workflowSid;

Get a List of all Workflows

foreach($taskrouterClient->workspace->workflows as $workflow)
        echo $workflow->sid;