***

title: toSwaig
slug: /reference/typescript/agents/swaig-function/to-swaig
description: Convert the function to a SWAIG-compatible object for SWML.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

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

## **Parameters**

<ParamField path="baseUrl" type="string" required={true} toc={true}>
  Base URL for the webhook endpoint.
</ParamField>

<ParamField path="token" type="string" toc={true}>
  Session token for secure function URL construction.
</ParamField>

<ParamField path="callId" type="string" toc={true}>
  Call ID for secure function URL construction.
</ParamField>

## **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**

```typescript {17}
import { SwaigFunction, FunctionResult } from '@signalwire/sdk';

const func = new SwaigFunction({
  name: "check_order",
  handler: async (args) => new FunctionResult("ok"),
  description: "Check order status",
  parameters: {
    type: "object",
    properties: {
      order_id: { type: "string", description: "Order ID" },
    },
    required: ["order_id"],
  },
});

const swaigDef = func.toSwaig(
  "https://myapp.example.com",
  "abc123",
  "call-12345",
);

console.log(swaigDef);
// {
//   function: "check_order",
//   description: "Check order status",
//   parameters: { type: "object", properties: {...}, required: [...] },
//   web_hook_url: "https://myapp.example.com/swaig?token=abc123&call_id=call-12345"
// }
```