For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
        • execute
        • toSwaig
        • validateArgs
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsSwaigFunction

toSwaig

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

validateArgs

Next
Built with

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// }