registerSwaigFunction

View as MarkdownOpen in Claude

Register a pre-built SwaigFunction instance or a raw function descriptor (e.g., from a DataMap) on a SWMLService. Unlike defineTool(), this method accepts pre-built objects rather than taking a handler callback.

Parameters

fn
SwaigFunction | Record<string, unknown>Required

A SwaigFunction instance or a plain object with a "function" key. Typically generated by DataMap.toSwaigFunction().

Returns

SWMLService — Returns this for method chaining.

Example

1import { SWMLService, DataMap, FunctionResult } from '@signalwire/sdk';
2
3const service = new SWMLService({ name: 'swaig-host', route: '/' });
4
5const plantTool = new DataMap('get_plant_info')
6 .description('Get care information for a plant')
7 .parameter('plantId', 'string', 'Plant ID', { required: true })
8 .webhook('GET', 'https://api.plants.example.com/plants/${args.plantId}')
9 .output(new FunctionResult(
10 'The plant ${args.plantId} needs ${response.water_schedule} watering.',
11 ));
12
13service.registerSwaigFunction(plantTool.toSwaigFunction());