Twilio TaskRouter API

List Resources

class Services_Twilio_ListResource

Abstraction of a list resource from the Twilio API.

The list resource implements the IteratorAggregate and the Countable interfaces.

get($sid)

Gets a resource from this list.

Parameters:
  • $sid (string) – The resource SID
Returns:

The resource

Return type:

InstanceResource

getObjectFromJson($params, $idParam = sid)

Construct an InstanceResource with the specified params.

Parameters:
  • $params (array) – usually a JSON HTTP response from the API
Returns:

An instance with properties initialized to the values in the params array.

Return type:

InstanceResource

delete($sid, $params = array())

Deletes a resource from this list.

Parameters:
  • $sid (string) – The resource SID
Return type:

null

getPage($page, $size = 50, $filters = array(), $deep_paging_uri = null)

Returns a page of InstanceResources from this list.

Parameters:
  • $page (int) – The start page
  • $size (int) – Number of items per page
  • $filters (array) – Optional filters
  • $deep_paging_uri (string) – if provided, the $page and $size parameters will be ignored and this URI will be requested directly.
Returns:

A page of resources

Return type:

Services_Twilio_Page

getIterator($page, $size = 50, $filters = array())

Returns an iterable list of instance resources.

Parameters:
  • $page (int) – The start page
  • $size (int) – Number of items per page
  • $filters (array) –

    Optional filters. The filter array can accept full datetimes when StartTime or DateCreated are used. Inequalities should be within the key portion of the array and multiple filter parameters can be combined for more specific searches.

    array('DateCreated>' => '2011-07-05 08:00:00', 'DateCreated<' => '2011-08-01')
    
    array('StartTime<' => '2011-07-05 08:00:00')
    
Returns:

An iterator

Return type:

Services_Twilio_AutoPagingIterator

getPageGenerator($page, $size, $filters = array(), $deep_paging_uri = null)

Retrieve a new page of API results, and update iterator parameters. This function is called by the paging iterator to retrieve a new page and shouldn’t be called directly.

All of the below classes inherit from the ListResource.

Workspaces

class Services_Twilio_Rest_TaskRouter_Workspaces

For more information, see the Workspaces API Resource https://www.twilio.com/docs/taskrouter/workspaces

create($friendlyName, array $params = array())

Make a workspace

Parameters:
  • $friendlyName (string) – String representing a user-friendly name for the Workspace
  • $params (array) – An array of optional parameters for this call

The $params array can contain the following keys:

EventCallbackUrl
If provided, the Workspace will publish events to this URL. You can use this to gather data for reporting.
Template
One of the available template names. Will pre-configure this Workspace with the Workflow and Activities specified in the template. “NONE” will create a Workspace with a set of default activities and nothing else. “FIFO” will configure TaskRouter with a set of default activities and a single task queue for first-in, first-out distribution, useful if you want to see a simple TaskRouter configuration when getting started.

Workflows

class Services_Twilio_Rest_TaskRouter_Workflows

For more information, see the Workflows API Resource https://www.twilio.com/docs/taskrouter/workflows

create($friendlyName, $configuration, $assignmentCallbackUrl, array $params = array())

Make a workflow

Parameters:
  • $friendlyName (string) – String representing a user-friendly name for the Workflow
  • $configuration (string) – JSON document configuring the rules for this Workflow
  • $assignmentCallbackUrl (string) – A valid URL for the application that will process task assignment events
  • $params (array) – An array of optional parameters for this call

The $params array must contain a TaskReservationTimeout, but FallbackAssignmentCallbackUrl is optional.

FallbackAssignmentCallbackUrl
If the request to the AssignmentCallbackUrl fails, the assignment callback will be made to this URL
TaskReservationTimeout
An integer value controlling how long in seconds TaskRouter will wait for a confirmation response from your application after assigning a Task to a worker

Workers

class Services_Twilio_Rest_TaskRouter_Workers

For more information, see the Workers API Resource https://www.twilio.com/docs/taskrouter/workers

create($friendlyName, array $params = array())

Make a worker

Parameters:
  • $friendlyName (string) – String representing a user-friendly name for the Worker
  • $params (array) – An array of optional parameters for this call

The $params array can contain the following keys:

ActivitySid
A valid Activity describing the worker’s initial state
Attributes
JSON object describing this worker

TaskQueues

class Services_Twilio_Rest_TaskRouter_TaskQueues

For more information, see the TaskQueues API Resource https://www.twilio.com/docs/taskrouter/taskqueues

create($friendlyName, $assignmentActivitySid, $reservationActivitySid, array $params = array())

Make a task queue

Parameters:
  • $friendlyName (string) – String representing a user-friendly name for the Task Queue
  • $assignmentActivitySid (string) – The activity to assign a worker when they accept a Task from this TaskQueue; defaults to ‘Busy’
  • $reservationActivitySid (string) – The Activity to assign a Worker when they are reserved for a Task from this TaskQueue; defaults to ‘Reserved’
  • $params (array) – An array of optional parameters for this call

The $params array can contain the following keys:

TargetWorkers
A string describing the Worker selection criteria for any Tasks that enter this TaskQueue
MaxReservedWorkers
The maximum amount of workers to create reservations for the assignment of a task while in this queue; default = 1, max = 50

Tasks

class Services_Twilio_Rest_TaskRouter_Tasks

For more information, see the Tasks API Resource https://www.twilio.com/docs/taskrouter/tasks

create($attributes, $workflowSid, array $params = array())

Make a task

Parameters:
  • $attributes (string) – The user-defined JSON string describing the custom attributes of this work
  • $workflowSid (string) – The ID of the Workflow responsible for routing this Task
  • $params (array) – An array of optional parameters for this call

The $params array can contain the following keys:

Timeout
The amount of time in seconds the task is allowed to live; default = 24 hours
Priority
Override priority for the Task

Activities

class Services_Twilio_Rest_TaskRouter_Activities

For more information, see the Activities API Resource https://www.twilio.com/docs/taskrouter/activities documentation

create($friendlyName, $available)

Make an activity

Parameters:
  • $friendlyName (string) – String representing a user-friendly name for the Activity
  • $available (string) – Boolean value indicating whether the worker should be eligible to receive a Task when they occupy this Activity

Events

class Services_Twilio_Rest_TaskRouter_Events

For more information, see the Events API Resource https://www.twilio.com/docs/taskrouter/events documentation

Reservations

class Services_Twilio_Rest_TaskRouter_Reservations

For more information, see the Task Reservation Instance Subresource section on https://www.twilio.com/docs/taskrouter/tasks documentation

Workers Statistics

class Services_Twilio_Rest_TaskRouter_WorkersStatistics

For more information, see the Worker Statistics API Resource https://www.twilio.com/docs/taskrouter/worker-statistics documentation

TaskQueue Statistics

class Services_Twilio_Rest_TaskRouter_TaskQueuesStatistics

For more information, see the TaskQueue Statistics API Resource https://www.twilio.com/docs/taskrouter/taskqueue-statistics documentation

Instance Resources

class Services_Twilio_InstanceResource

Abstraction of an instance resource from the Twilio API.

update($params, $value = null)

Make a request to the API to update an instance resource

Parameters:
  • $params (mixed) – An array of updates, or a property name
  • $value (mixed) – A value with which to update the resource
Return type:

null

Throws:

a RestException if the update fails.

updateAttributes($params)

Add all properties from an associative array (the JSON response body) as properties on this instance resource, except the URI

Parameters:
  • $params (stdClass) – An object containing all of the parameters of this instance
Returns:

Nothing, this is purely side effecting

Return type:

null

synchronize()

Force an HTTP request to the API and update the instance based off the response. This method will perform the HTTP Request even if the instance has already been loaded, any changed attributes will be refreshed from the API.

Returns:Nothing, updates internal state
Return type:null
__get($key)

Get the value of a property on this resource.

Instead of defining all of the properties of an object directly, we rely on the API to tell us which properties an object has. This method will query the API to retrieve a property for an object, if it is not already set on the object.

If the call is to a subresource, eg $client->account->messages, no request is made.

To help with lazy HTTP requests, we don’t actually retrieve an object from the API unless you really need it. Hence, this function may make API requests even if the property you’re requesting isn’t available on the resource.

Parameters:
  • $key (string) – The property name
Return mixed:

Could be anything.

Throws:

a RestException if the update fails.

Below you will find a list of objects created by interacting with the Twilio API, and the methods and properties that can be called on them. These are derived from the ListResource and InstanceResource above.

Workspace

class Services_Twilio_Rest_TaskRouter_Workspace
property sid

The unique ID of the Workspace

property account_sid

The ID of the account that owns this Workflow

property friendly_name

Human readable description of this workspace (for example “Sales Call Center” or “Customer Support Team”)

property default_activity_sid

The ID of the Activity that will be used when new Workers are created in this Workspace.

property default_activity_name

The human readable name of the default activity. Read only.

property timeout_activity_sid

The ID of the Activity that will be assigned to a Worker when a Task reservation times out without a response.

property timeout_activity_name

The human readable name of the timeout activity. Read only.

property event_callback_url

An optional URL where the Workspace will publish events. You can use this to gather data for reporting. See Workspace Events for more information. Optional.

property date_created

The time the Workspace was created, given as GMT in ISO 8601 format.

property date_updated

The time the Workspace was last updated, given as GMT in ISO 8601 format.

Workflow

class Services_Twilio_Rest_TaskRouter_Workflow
property sid

The unique ID of the Workflow

property account_sid

The ID of the account that owns this Workflow

property workspace_sid

The ID of the Workspace that contains this Workflow

property friendly_name

Human readable description of this Workflow (for example “Customer Support” or “2014 Election Campaign”)

property assignment_callback_url

The URL that will be called whenever a task managed by this Workflow is assigned to a Worker.

property fallback_assignment_callback_url

If the request to the AssignmentCallbackUrl fails, the assignment callback will be made to this URL.

property configuration

JSON document configuring the rules for this Workflow. See Configuring Workflows for more information.

property task_reservation_timeout

Determines how long TaskRouter will wait for a confirmation response from your application after assigning a Task to a worker. Defaults to 120 seconds.

property date_created

The date this workflow was created.

property date_updated

The date this workflow was updated.

Worker

class Services_Twilio_Rest_TaskRouter_Worker
property friendly_name

Filter by a worker’s friendly name

property task_queue_sid

Filter by workers that are eligible for a TaskQueue by SID

property task_queue_name

Filter by workers that are eligible for a TaskQueue by Friendly Name

property activity_sid

Filter by workers that are in a particular Activity by SID

property activity_name

Filter by workers that are in a particular Activity by Friendly Name

property available

Filter by workers that are available or unavailable. (Note: This can be ‘true’, ‘1’’ or ‘yes’ to indicate a true value. All other values will represent false)

property target_workers_expression

Filter by workers that would match an expression on a TaskQueue. This is helpful for debugging which workers would match a potential queue.

TaskQueue

class Services_Twilio_Rest_TaskRouter_TaskQueue
property sid

The unique ID of the TaskQueue

property account_sid

The ID of the Account that owns this TaskQueue

property workspace_sid

The ID of the Workspace that owns this TaskQueue

property friendly_name

Human readable description of the TaskQueue (for example “Customer Support” or “Sales”)

property target_workers

The worker selection expressions associated with this TaskQueue.

property reservation_activity_sid

The Activity to assign a Worker when they are reserved for a Task from this TaskQueue. Defaults to ‘Reserved for Task’

property assignment_activity_sid

The Activity to assign a Worker when they accept a Task from this TaskQueue. Defaults to ‘Unavailable for Assignment’.

property max_reserved_workers

The maximum amount of workers to create reservations for the assignment of a task while in this queue.

Task

class Services_Twilio_Rest_TaskRouter_Task
property sid

The unique ID of the Task

property account_sid

The ID of the account that owns this Task

property workspace_sid

The ID of the Workspace that holds this Task

property workflow_sid

The ID of the Workflow responsible for routing this Task

property attributes

The user-defined JSON string describing the custom attributes of this work.

property age

The number of seconds since this task was created.

property priority

The current priority score of the task, as assigned by the workflow. Tasks with higher values will be assigned before tasks with lower values.

property task_queue_sid

The current TaskQueue occupied, controlled by the Workflow’s Workflow.

property assignment_status

A string representing the Assignment State of the task. May be pending, reserved, assigned or canceled. See the table of Task Assignment Status values below for more information.

property reason

The reason the task was canceled (if applicable)

property date_created

Date this task was created, given as ISO 8601 format.

property date_updated

Date this task was updated, given as ISO 8601 format.

property timeout

The amount of time in seconds the task is allowed to live

Activity

class Services_Twilio_Rest_TaskRouter_Activity
property sid

The unique ID for this Activity.

property account_sid

The unique ID of the Account that owns this Activity.

property workspace_sid

The unique ID of the Workspace that this Activity belongs to.

property friendly_name

A human-readable name for the Activity, such as ‘on-call’, ‘break’, ‘email’, etc. These names will be used to calculate and expose statistics about workers, and give you visibility into the state of each of your workers.

property available

Boolean value indicating whether the worker should be eligible to receive a Task when they occupy this Activity. For example, in an activity called ‘On Call’, the worker would be unavailable to receive additional Task assignments.

property date_created

The date this Activity was created.

property date_updated

The date this Activity was updated.

Event

class Services_Twilio_Rest_TaskRouter_Event
property event_type

An identifier for this event

property account_sid

The account owning this event

property description

A description of the event

property resource_type

The type of object this event is most relevant to (Task, Reservation, Worker)

property resource_sid

The sid of the object this event is most relevant to (TaskSid, ReservationSid, WorkerSid)

property event_date

The time this event was sent

property event_data

Data about this specific event

Reservation

class Services_Twilio_Rest_TaskRouter_Reservation
property sid

The unique ID of this Reservation

property account_sid

The ID of the Account that owns this Task

property workspace_sid

The ID of the Workspace that this task is contained within

property task_sid

The ID of the reserved Task

property worker_name

Human readable description of the Worker that is reserved

property reservation_status

The current status of the reservation

Workspace Statistics

class Services_Twilio_Rest_TaskRouter_WorkspaceStatistics
property longest_task_waiting_sid

The ID of the longest waiting Task

property longest_task_waiting_age

The age of the longest waiting Task

property total_tasks

The total number of Tasks

property total_workers

The total number of Workers in the workspace

property tasks_by_status

The Tasks broken down by status (for example: pending: 1, reserved = 3, assigned = 2)

property activity_statistics

A breakdown of Workers by Activity (for example: Idle : 0, Busy: 5, Reserved = 0, Offline = 2)

property tasks_created

The total number of Tasks created

property tasks_canceled

The total number of Tasks that were canceled

property tasks_deleted

The total number of Tasks that were deleted

property tasks_moved

The total number of Tasks that were moved from one queue to another

property tasks_timed_out_in_workflow

The total number of Tasks that were timed out of their Workflows (and deleted)

property avg_task_acceptance_time

The average time (in seconds) from Task creation to acceptance

property reservations_created

The total number of Reservations that were created for Workers

property reservations_accepted

The total number of Reservations accepted by Workers

property reservations_rejected

The total number of Reservations that were rejected

property reservations_timed_out

The total number of Reservations that were timed out

property reservations_canceled

The total number of Reservations that were canceled

property reservations_rescinded

The total number of Reservations that were rescinded

Workflow Statistics

class Services_Twilio_Rest_TaskRouter_WorkflowStatistics
property longest_task_waiting_sid

The ID of the longest waiting Task

property longest_task_waiting_age

The age of the longest waiting Task

property total_tasks

The total number of Tasks

property tasks_by_status

The Tasks broken down by status (for example: pending: 1, reserved = 3, assigned = 2)

property tasks_entered

The total number of Tasks that entered this Workflow

property tasks_canceled

The total number of Tasks that were canceled

property tasks_deleted

The total number of Tasks that were deleted

property tasks_moved

The total number of Tasks that were moved from one queue to another

property tasks_timed_out_in_workflow

The total number of Tasks that were timed out of their Workflows (and deleted)

property avg_task_acceptance_time

The average time (in seconds) from Task creation to acceptance

property reservations_created

The total number of Reservations that were created for Workers

property reservations_accepted

The total number of Reservations accepted by Workers

property reservations_rejected

The total number of Reservations that were rejected

property reservations_timed_out

The total number of Reservations that were timed out

property reservations_canceled

The total number of Reservations that were canceled

property reservations_rescinded

The total number of Reservations that were rescinded

Worker Statistics

class Services_Twilio_Rest_TaskRouter_WorkerStatistics
property reservations_created

The total number of Reservations that were created

property reservations_accepted

The total number of Reservations accepted

property reservations_rejected

The total number of Reservations that were rejected

property reservations_timed_out

The total number of Reservations that were timed out

property reservations_canceled

The total number of Reservations that were canceled

property activity_duration

The minimum, average, maximum and total time (in seconds) this Worker spent in each Activity

TaskQueue Statistics

class Services_Twilio_Rest_TaskRouter_TaskQueueStatistics
property longest_task_waiting_sid

The ID of the longest waiting Task

property longest_task_waiting_age

The age of the longest waiting Task

property total_tasks

The total number of Tasks

property tasks_by_status

The Tasks broken down by status (for example: pending: 1, reserved = 3, assigned = 2)

property activity_statistics

The current Worker status count breakdown by Activity

property total_eligible_workers

The total number of Workers eligible for Tasks in this TaskQueue

property total_available_workers

The total number of Workers available for Tasks in this TaskQueue

property tasks_entered

The total number of Tasks entered into this TaskQueue

property tasks_canceled

The total number of Tasks canceled while in this TaskQueue

property tasks_deleted

The total number of Tasks that were deleted while in this TaskQueue

property tasks_moved

The total number of Tasks moved to another TaskQueue from this TaskQueue

property avg_task_acceptance_time

The average time (in seconds) from Task creation to acceptance while in this TaskQueue

property reservations_accepted

The total number of Reservations that were accepted for Tasks while in this TaskQueue

property reservations_rejected

The total number of Reservations that were rejected for Tasks while in this TaskQueue

property reservations_timed_out

The total number of Reservations that were tiemd out for Tasks while in this TaskQueue

property reservations_canceled

The total number of Reservations that were canceled for Tasks while in this TaskQueue

property reservations_rescinded

The total number of Reservations that were rescinded