execute

View as MarkdownOpen in Claude

Execute the function with the given arguments. Calls the handler and normalizes the return value into a serialized result dictionary.

Parameters

args
Record<string, unknown>Required

Parsed arguments for the function, matching the parameter schema.

rawData
Record<string, unknown>

Full raw request data including global_data, call_id, caller_id_number, meta_data, and ai_session_id.

Returns

Promise<Record<string, unknown>> — The function result as a dictionary (from FunctionResult.toDict()). If the handler throws an exception, returns a generic error message rather than exposing internal details.

The handler can return a FunctionResult, an object with a "response" key, or a plain string. All formats are normalized to a result dictionary.

Example

1import { SwaigFunction, FunctionResult } from '@signalwire/sdk';
2
3const func = new SwaigFunction({
4 name: "lookup_account",
5 handler: async (args, rawData) => {
6 const accountId = (args.account_id as string) ?? "";
7 return new FunctionResult(`Account ${accountId} is active.`);
8 },
9 description: "Look up account status",
10 parameters: {
11 type: "object",
12 properties: {
13 account_id: { type: "string", description: "Account ID" },
14 },
15 required: ["account_id"],
16 },
17});
18
19const result = await func.execute({ account_id: "12345" });
20console.log(result);
21// { response: "Account 12345 is active.", action: [] }