Current section
Files
Jump to
Current section
Files
lib/twilio/taskrouter/v1/workspace/worker_service.ex
# File generated from Twilio's OpenAPI spec — do not edit manually
defmodule Twilio.Taskrouter.V1.Workspace.WorkerService do
@moduledoc """
Service for Worker API operations.
Operations: `list`, `create`, `fetch`, `update`, `delete`
"""
alias Twilio.Client
alias Twilio.Deserializer
@doc """
Operation: `ListWorker` | Tags: TaskrouterV1Worker
## Query Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| `ActivityName` | string | The `activity_name` of the Worker resources to read. |
| `ActivitySid` | string | The `activity_sid` of the Worker resources to read. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `Available` | string | Whether to return only Worker resources that are available or unavailable. Can be `true`, `1`, or `yes` to return Worker resources that are available, and `false`, or any value returns the Worker resources that are not available. |
| `FriendlyName` | string | The `friendly_name` of the Worker resources to read. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `TargetWorkersExpression` | string | Filter by Workers that would match an expression. In addition to fields in the workers' attributes, the expression can include the following worker fields: `sid`, `friendly_name`, `activity_sid`, or `activity_name` |
| `TaskQueueName` | string | The `friendly_name` of the TaskQueue that the Workers to read are eligible for. |
| `TaskQueueSid` | string | The SID of the TaskQueue that the Workers to read are eligible for. |
| `Ordering` | string | Sorting parameter for Workers |
"""
@spec list(Client.t(), String.t(), map(), keyword()) ::
{:ok, Twilio.Page.t()} | {:ok, map(), map()} | :ok | {:error, Twilio.Error.t()}
def list(client, workspace_sid, params \\ %{}, opts \\ []) do
case Client.request(client, :get, "/v1/Workspaces/#{workspace_sid}/Workers",
params: params,
opts: opts,
base_url: "https://taskrouter.twilio.com"
) do
{:ok, data} ->
page = Twilio.Page.from_response(data, "workers")
{:ok,
%{
page
| items:
Deserializer.deserialize_list(
page.items,
Twilio.Resources.Taskrouter.V1.Workspace.Worker
)
}}
error ->
error
end
end
@doc "Stream: (lazy auto-pagination)."
@spec stream(Client.t(), String.t(), map(), keyword()) :: Enumerable.t()
def stream(client, workspace_sid, params \\ %{}, opts \\ []) do
Twilio.Page.stream(
fn page_opts ->
list(client, workspace_sid, Map.merge(params, page_opts), opts)
end,
"workers"
)
end
@doc """
Operation: `CreateWorker` | Tags: TaskrouterV1Worker
## Required Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `FriendlyName` | string | A descriptive string that you create to describe the new Worker. It can be up to 64 characters long. |
## Optional Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `ActivitySid` | string | The SID of a valid Activity that will describe the new Worker's initial state. See [Activities](https://www.twilio.com/docs/taskrouter/api/activity) for more information. If not provided, the new Worker's initial state is the `default_activity_sid` configured on the Workspace. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `Attributes` | string | A valid JSON string that describes the new Worker. For example: `{ "email": "Bob@example.com", "phone": "+5095551234" }`. This data is passed to the `assignment_callback_url` when TaskRouter assigns a Task to the Worker. Defaults to {}. |
"""
@spec create(Client.t(), String.t(), map(), keyword()) ::
{:ok, Twilio.Resources.Taskrouter.V1.Workspace.Worker.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def create(client, workspace_sid, params \\ %{}, opts \\ []) do
with {:ok, data} <-
Client.request(client, :post, "/v1/Workspaces/#{workspace_sid}/Workers",
params: params,
opts: opts,
base_url: "https://taskrouter.twilio.com",
content_type: :form
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Taskrouter.V1.Workspace.Worker)}
end
end
@doc """
Operation: `FetchWorker` | Tags: TaskrouterV1Worker
"""
@spec fetch(Client.t(), String.t(), String.t(), keyword()) ::
{:ok, Twilio.Resources.Taskrouter.V1.Workspace.Worker.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def fetch(client, workspace_sid, sid, opts \\ []) do
with {:ok, data} <-
Client.request(client, :get, "/v1/Workspaces/#{workspace_sid}/Workers/#{sid}",
opts: opts,
base_url: "https://taskrouter.twilio.com"
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Taskrouter.V1.Workspace.Worker)}
end
end
@doc """
Operation: `UpdateWorker` | Tags: TaskrouterV1Worker
## Optional Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `ActivitySid` | string | The SID of a valid Activity that will describe the Worker's initial state. See [Activities](https://www.twilio.com/docs/taskrouter/api/activity) for more information. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `Attributes` | string | The JSON string that describes the Worker. For example: `{ "email": "Bob@example.com", "phone": "+5095551234" }`. This data is passed to the `assignment_callback_url` when TaskRouter assigns a Task to the Worker. Defaults to {}. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `FriendlyName` | string | A descriptive string that you create to describe the Worker. It can be up to 64 characters long. |
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
| `RejectPendingReservations` | boolean | Whether to reject the Worker's pending reservations. This option is only valid if the Worker's new [Activity](https://www.twilio.com/docs/taskrouter/api/activity) resource has its `availability` property set to `False`. |
"""
@spec update(Client.t(), String.t(), String.t(), map(), keyword()) ::
{:ok, Twilio.Resources.Taskrouter.V1.Workspace.Worker.t()}
| {:ok, map(), map()}
| :ok
| {:error, Twilio.Error.t()}
def update(client, workspace_sid, sid, params \\ %{}, opts \\ []) do
with {:ok, data} <-
Client.request(client, :post, "/v1/Workspaces/#{workspace_sid}/Workers/#{sid}",
params: params,
opts: opts,
base_url: "https://taskrouter.twilio.com",
content_type: :form
) do
{:ok, Deserializer.deserialize(data, Twilio.Resources.Taskrouter.V1.Workspace.Worker)}
end
end
@doc """
Operation: `DeleteWorker` | Tags: TaskrouterV1Worker
"""
@spec delete(Client.t(), String.t(), String.t(), keyword()) ::
{:ok, map()} | {:ok, map(), map()} | :ok | {:error, Twilio.Error.t()}
def delete(client, workspace_sid, sid, opts \\ []) do
Client.request(client, :delete, "/v1/Workspaces/#{workspace_sid}/Workers/#{sid}",
opts: opts,
base_url: "https://taskrouter.twilio.com"
)
end
end