toSwaig

View as MarkdownOpen in Claude

Convert this function to a SWAIG-compatible object for inclusion in a SWML document. Called internally during SWML rendering.

Parameters

baseUrl
stringRequired

Base URL for the webhook endpoint.

token
string

Session token for secure function URL construction.

callId
string

Call ID for secure function URL construction.

Returns

Record<string, unknown> — Object with "function", "description", "parameters", "web_hook_url", and optional "fillers", "wait_file", "wait_file_loops" keys, plus any extraFields.

Example

1import { SwaigFunction, FunctionResult } from '@signalwire/sdk';
2
3const func = new SwaigFunction({
4 name: "check_order",
5 handler: async (args) => new FunctionResult("ok"),
6 description: "Check order status",
7 parameters: {
8 type: "object",
9 properties: {
10 order_id: { type: "string", description: "Order ID" },
11 },
12 required: ["order_id"],
13 },
14});
15
16const swaigDef = func.toSwaig(
17 "https://myapp.example.com",
18 "abc123",
19 "call-12345",
20);
21
22console.log(swaigDef);
23// {
24// function: "check_order",
25// description: "Check order status",
26// parameters: { type: "object", properties: {...}, required: [...] },
27// web_hook_url: "https://myapp.example.com/swaig?token=abc123&call_id=call-12345"
28// }