to_swaig

View as MarkdownOpen in Claude

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

Parameters

base_url
strRequired

Base URL for the webhook endpoint.

token
str | NoneDefaults to None

Auth token to include in the webhook URL.

call_id
str | NoneDefaults to None

Call ID for session tracking.

include_auth
boolDefaults to true

Whether to include auth credentials in the webhook URL.

Returns

dict[str, Any] — Dictionary with "function", "description", "parameters", "web_hook_url", and optional "fillers" keys.

Example

from signalwire import SWAIGFunction
from signalwire import FunctionResult
func = SWAIGFunction(
name="check_order",
handler=lambda args, raw_data: FunctionResult("ok"),
description="Check order status",
parameters={
"type": "object",
"properties": {
"order_id": {"type": "string", "description": "Order ID"}
},
"required": ["order_id"]
}
)
swaig_dict = func.to_swaig(
base_url="https://myapp.example.com",
token="abc123",
call_id="call-12345"
)
print(swaig_dict)
# {
# "function": "check_order",
# "description": "Check order status",
# "parameters": {...},
# "web_hook_url": "https://myapp.example.com/swaig?token=abc123&call_id=call-12345"
# }