Class: Worker

Worker

Create a Worker client representing a TaskRouter Worker


new Twilio.TaskRouter.Worker(token [, options])

Parameters:
Name Type Argument Description
token string

The string token

options Worker.Options <optional>
Properties:
Name Type Description
accountSid string

The sid of the Twilio account

activities Map.<string, Activity>

The list of possible states a Worker can be

activity Activity

The current Activity of the Worker

activitySid string

The sid of the Activity the Worker is currently in

activityName string

The current Activity name the Worker is currently in

attributes Object

A JSON representation of the Worker's attributes

available boolean

Whether or not the Worker is available to take on Tasks

channels Map.<string, Channel>

The list of available Channels

connectActivitySid string

The Activity to set the Worker as on connect

dateCreated Date

The date this Worker was created

dateStatusChanged Date

The date this Worker's activity was last changed

dateUpdated Date

The date this Worker was last updated

name string

The friendly name of the Worker

reservations Map.<string, Reservation>

A list of pending Reservations for the Worker

sid string

The sid of the Worker

workspaceSid string

The sid of the Workspace owning this Worker

workerSid string

The sid of the Worker, duplicates sid field for backwards compatibility

workerActivitySid string

The sid of the Activity the Worker is currently in, duplicates activitySid field for backwards compatibility

dateActivityChanged Date

The date when the Worker's state was last changed, duplicates dateStatusChanged field for backwards compatibility

friendlyName string

The friendly name of the Worker, duplicates name field for backwards compatibility

version string

The version of this Worker

Fires:

Methods


createTask(to, from, workflowSid, taskQueueSid [, options])

Create a Task

Parameters:
Name Type Argument Description
to string

The contact uri of the customer. Stored in the Task's attributes as "outbound_to"

from string

The contact uri of the Worker. Stored in the Task's attributes as "from"

workflowSid string

The Sid of the Workflow this Task should belong to

taskQueueSid string

The Sid of the TaskQueue this Task should belong to, used for reporting purposes only

options Worker.TaskOptions <optional>
Returns:
  • Rejected if unable to create a Task on behalf of the Worker. Returns the TaskSid of the created Task.
Type
Promise.<String>

disconnect()

Gracefully disconnect the client.

Returns:
Type
void

fetchLatestVersion()

Fetch the last version of this Worker

Returns:
Type
Promise.<Worker>

setAttributes(attributes)

Update attributes

Parameters:
Name Type Description
attributes Object

A JSON describing the Worker's attributes

Returns:
  • Rejected if the attributes cannot be set
Type
Promise.<this>

updateToken(newToken)

Update token

Parameters:
Name Type Description
newToken string

The new token that should be used for authentication

Returns:
  • Emits error if unable to update token
Type
void

Type Definitions


Options

Type:
  • Object
Properties:
Name Type Argument Default Description
connectActivitySid string <optional>
''

The Activity state of the Worker upon connect

closeExistingSessions boolean <optional>
false
  • Whether other open sessions of this Worker should be terminated
logLevel string <optional>
'error'

The level of logging to enable ['error', 'warn', 'info', 'debug', 'trace', 'silent']

region string

the realm for connections (ex. "stage-us1")

edge string

the ingress for connections (ex. "sydney")


TaskOptions

Type:
  • Object
Properties:
Name Type Argument Default Description
attributes object <optional>
null

Additional attributes for the Task

taskChannelUniqueName string <optional>
null

The friendly name of the Channel this Task belongs to. If not provided, defaults to 'default' channel.

taskChannelSid string <optional>
null

The Sid of the Channel this Task belongs to. If not provided, defaults to 'default' channel.

Events


activityUpdated

Worker activity has updated

Parameters:
Name Type Description
worker Worker

The updated Worker


attributesUpdated

Worker attributes have updated

Parameters:
Name Type Description
worker Worker

The updated Worker


disconnected

The signaling layer has lost the websocket connection

Parameters:
Name Type Description
reason Object

The reason the Worker websocket disconnected


error

An error has occurred

Parameters:
Name Type Description
error Error

The Error that occurred


ready

Worker is ready to listen for events and take action


reservationCreated

A Reservation has been created for the Worker

Parameters:
Name Type Description
reservation Reservation

The created Reservation


reservationFailed

Worker was unable to receive a Reservation for the Task it created

Parameters:
Name Type Description
task Object

The raw Task-like payload that failed to generate a Reservation


tokenExpired

The Worker token has expired


tokenUpdated

The Worker token has successfully updated