Task
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.
import { Task } from "@signalwire/realtime-api";
const client = new Task.Client({
project: "<project-id>",
token: "<api-token>",
topics: ["office"],
});
client.on("task.received", (payload) => {
console.log("Task Received", payload);
// Do something with the payload...
});
From a different process, even on a different machine, you can then send tasks:
import { Task } from "@signalwire/realtime-api";
await Task.send({
project: "<project-id>",
token: "<api-token>",
topic: "office",
message: { hello: ["world", true] }
});
Classes
Functions
send
▸ Const
send(params
): Promise<void>
Send a job to your Task Client in a specific topic.
Parameters
Name | Type | Description |
---|---|---|
params | Object | - |
params.topic | string | Topic to send the task to. Previously known as "context" . |
params.message | Record<string, unknown> | Message to send. |
params.project | string | SignalWire project id, e.g. a10d8a9f-2166-4e82-56ff-118bc3a4840f . |
params.token | string | SignalWire 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.
const message = {
'action': 'call',
'from': '+18881112222',
'to': '+18881113333'
}
await Task.send({
project: "<project-id>",
token: "<api-token>",
topic: 'office',
message: message
})