Task

View as Markdown

Access the Task API. You can instantiate a Task.Client to receive tasks from a different application. Please check Task Events for the full list of events that a Task.Client can subscribe to.

Example

The following example listens for incoming tasks.

1import { Task } from "@signalwire/realtime-api";
2
3const client = new Task.Client({
4 project: "<project-id>",
5 token: "<api-token>",
6 topics: ["office"],
7});
8
9client.on("task.received", (payload) => {
10 console.log("Task Received", payload);
11 // Do something with the payload...
12});

From a different process, even on a different machine, you can then send tasks:

1import { Task } from "@signalwire/realtime-api";
2
3await Task.send({
4 project: "<project-id>",
5 token: "<api-token>",
6 topic: "office",
7 message: { hello: ["world", true] }
8});

Classes

Functions

send

  • Const send(params): Promise<void>

Send a job to your Task Client in a specific topic.

Parameters

NameTypeDescription
paramsObject-
params.topicstringTopic to send the task to. Previously known as "context".
params.messageRecord<string, unknown>Message to send.
params.projectstringSignalWire project id, e.g. a10d8a9f-2166-4e82-56ff-118bc3a4840f.
params.tokenstringSignalWire project token, e.g. PT9e5660c101...a360079c9.

Returns

Promise<void>

Example

Sending a task with a message to then make an outbound Call. Please note that the call is not performed automatically: your Task.Client gives you back your payload, which you should interpret by your own custom logic.

1const message = {
2 'action': 'call',
3 'from': '+18881112222',
4 'to': '+18881113333'
5}
6
7await Task.send({
8 project: "<project-id>",
9 token: "<api-token>",
10 topic: 'office',
11 message: message
12})