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

Auth token to include in the webhook URL.

call_id
str

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

1from signalwire import SWAIGFunction
2from signalwire import FunctionResult
3
4func = SWAIGFunction(
5 name="check_order",
6 handler=lambda args, raw_data: FunctionResult("ok"),
7 description="Check order status",
8 parameters={
9 "type": "object",
10 "properties": {
11 "order_id": {"type": "string", "description": "Order ID"}
12 },
13 "required": ["order_id"]
14 }
15)
16
17swaig_dict = func.to_swaig(
18 base_url="https://myapp.example.com",
19 token="abc123",
20 call_id="call-12345"
21)
22
23print(swaig_dict)
24# {
25# "function": "check_order",
26# "description": "Check order status",
27# "parameters": {...},
28# "web_hook_url": "https://myapp.example.com/swaig?token=abc123&call_id=call-12345"
29# }