swaig-test
The swaig-test command loads an agent file and lets you render its SWML, list
its SWAIG functions, call a function, and simulate serverless environments, all
without deploying. It supports webhook functions, DataMap
functions, and functions that point at an external webhook URL.
swaig-test sends its requests through the agent’s own HTTP app, the way
SignalWire would. It fetches the agent’s SWML with a simulated call, so basic
auth, signature checks, the dynamic configuration callback, and function tokens
all run as they do on a server. The callback runs once for --dump-swml.
--exec reads the function from that SWML and calls it at the web_hook_url
the SWML gives it. A DataMap function runs in a local DataMap simulator, and a
function whose URL points elsewhere is called at that URL.
The agent file can be .ts, .js, .mjs, or .mts. The command picks the
agent to test in this order:
- The export named by
--agent-class, either an instance or a class to instantiate. - With
--route, the service whose route matches. - The export named
agent, then the default export, then any exported instance, then any exported class. - An agent the file creates without exporting it, as in the quickstart.
One action flag is required. A target with no action exits with
Error: one of --dump-swml, --list-tools, or --exec is required. The one
exception is --simulate-serverless, which renders SWML for the platform on
its own. Running swaig-test with no arguments prints the help text.
Options accept both --name value and --name=value. For -h, --help,
--help-platforms, --help-examples, and --parse-only, see
Help and validation.
Actions
Choose one action per invocation:
--list-tools
List the agent’s SWAIG functions with their parameters. Each function is
labeled LOCAL webhook or EXTERNAL webhook (with its URL); a DataMap
function carries no label. With --raw or --format-json, prints a
JSON array of name, description, parameters, and type, plus
web_hook_url for an external function.
--list-agents
List the agents and services exported from the file, with each instance’s
name and route. Useful for multi-agent files. Exits 1 when the file has
none. With --raw or --format-json, prints JSON, an empty array when the
file has none, and exits 0.
--dump-swml
Print the SWML document the agent serves, as indented JSON. Combine with
--raw for compact JSON that suppresses logs.
--exec NAME
Call a SWAIG function by name. Everything after the function name belongs to
the function, so put swaig-test’s own options before --exec. Pass
arguments as --name value (see Function arguments).
--exec with no function name, or followed directly by another -- option,
exits with --exec requires a function name.
Common options
--raw
Output raw JSON only, suppressing all logs. Designed for piping to jq.
-v, --verbose
Enable verbose output with debug information: the request being sent, the
function’s arguments, and, for --list-tools, each function’s full
configuration.
--format-json
Print the result as indented JSON.
--agent-class
Name of the exported agent class or instance to use. Cannot be combined with
--route.
--route
Use the service with this route, such as /sales. Cannot be combined with
--agent-class.
Function arguments
After --exec <function>, pass each argument as --name value. swaig-test
types the value by the function’s parameter schema and converts dashes in the
name to underscores.
--arg name=value also works: the value is parsed as JSON, and falls back to a
string. An argument the function doesn’t declare is still passed to the
function, with a warning. A swaig-test option placed after --exec, such as
--verbose, is read as a function argument; put it before --exec.
Function execution options
--minimal
Send the smallest function request: the call ID and the arguments.
--fake-full-data
Send a request with every key SignalWire may send. This is the default.
--custom-data
A JSON object merged into the function request. For a DataMap function, it
supplies the call data the simulator reads, such as global_data. Without a
global_data key, the simulator uses the global_data in the agent’s SWML.
Call and request options
These apply to --dump-swml, --list-tools, and --exec.
--call-type
Simulated call type: sip or webrtc.
--call-direction
Simulated call direction: inbound or outbound.
--call-state
Call state, set as call.state.
--call-id
The call_id the simulated request carries.
--project-id
Sets call.project_id.
--space-id
Sets call.space_id.
--from-number
Sets call.from, the caller’s address.
--to-extension
Sets call.to, the destination.
--user-vars
A JSON object set as vars.userVariables.
--query-params
A JSON object of query parameters for the SWML request. They are also added
to vars.userVariables. Use this to test a dynamic configuration callback
that reads the query string.
--header NAME=VALUE
A request header. Repeatable.
--method
Method of the SWML request: POST or GET. A GET request carries the call
ID and query parameters in the query string.
--body
A JSON object of extra fields merged into the SWML request body.
--override PATH=VALUE
Set a value in the simulated request by dotted path, such as
call.state=answered. The value is read as null, true, false, a
number, JSON, or a string, in that order. Repeatable. A path the simulated
request doesn’t contain adds a key and prints a warning.
--override-json PATH=JSON
Like --override, but the value must be JSON. Repeatable.
Environment and serverless simulation
--simulate-serverless
Run with a serverless platform’s environment, so the SWML’s webhook URLs are
the platform’s. Valid values are lambda, cgi, gcf, and azure;
cloud_function and azure_function are accepted as aliases. Any other
value exits with an error naming the supported set. The simulated
environment replaces other platforms’ variables set in your shell, and your
shell’s variables are restored afterward.
--env KEY=VALUE
Set an environment variable. Repeatable. Applied after --env-file.
--env-file
Load environment variables from a file, one KEY=VALUE per line. Blank lines
and lines starting with # are skipped, and matching quotes around a value
are removed.
AWS Lambda
Use with --simulate-serverless lambda.
--aws-function-name
Function name (AWS_LAMBDA_FUNCTION_NAME).
--aws-function-url
Function URL (AWS_LAMBDA_FUNCTION_URL).
--aws-region
Region (AWS_REGION).
--aws-api-gateway-id
Serve at an API Gateway URL, https://ID.execute-api.REGION.amazonaws.com/STAGE.
Ignored, with a warning, when --aws-function-url is set.
--aws-stage
API Gateway stage. Applies only with --aws-api-gateway-id.
CGI
Use with --simulate-serverless cgi.
--cgi-host
Server host name. Required with --simulate-serverless cgi.
--cgi-script-name
Script path (SCRIPT_NAME).
--cgi-https
Serve over HTTPS.
--cgi-path-info
PATH_INFO.
Google Cloud Functions
Use with --simulate-serverless gcf.
--gcp-project
Project (GOOGLE_CLOUD_PROJECT).
--gcp-function-url
Function URL (FUNCTION_URL).
--gcp-region
Region (GOOGLE_CLOUD_REGION).
--gcp-service
Service name (K_SERVICE).
Azure Functions
Use with --simulate-serverless azure.
--azure-env
Environment (AZURE_FUNCTIONS_ENVIRONMENT).
--azure-function-url
Function URL (AZURE_FUNCTION_URL).
Help and validation
--parse-only
Validate the command-line arguments, print parse OK, and exit without
loading the agent file, touching the filesystem, or making network requests.
--dry-run is an alias. Accepted anywhere on the command line, including
after --exec.
-h, --help
Print the help text. It ends with a pointer to sw-tsdocs.
--help-platforms
Print the serverless platform options.
--help-examples
Print usage examples.
Examples
The examples below run against this agent: