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

attributes Object

A JSON representation of the Worker's attributes

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

Fires:

Methods


disconnect()

Gracefully disconnect the client.

Returns:
Type
void

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 <optional>

the ingress region for connections (ex. "ie1-ix")

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


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


tokenExpired

The Worker token has expired


tokenUpdated

The Worker token has successfully updated