SWMLService
SWMLService is a lightweight HTTP service for serving non-AI SWML documents.
Unlike AgentBase (which always produces an AI block), SWMLService
generates pure SWML call-flow documents: IVR menus, voicemail, call recording, etc.
It uses a SwmlBuilder internally for verb construction and
Hono for HTTP serving.
SWMLService generates and serves SWML documents over HTTP. See the SWML reference for the full document specification.
Constructor
opts
Configuration object.
opts.name
Service display name used in logging and startup messages. Required to
match the Python SDK, where name is a positional required parameter.
opts.route
HTTP route path where the service is accessible.
opts.host
Host the HTTP server binds to.
opts.port
Port the HTTP server binds to. Defaults to the PORT environment variable,
falling back to 3000.
opts.basicAuth
Basic auth credentials as [username, password]. Unlike AgentBase,
SWMLService does not fall back to environment variables — credentials
must be provided explicitly.
opts.schemaPath
Path to a JSON Schema file for verb validation.
opts.configFile
Path to a security configuration file for SSL, CORS, and host allowlist settings.
opts.schemaValidation
Enable schema validation. Can also be disabled via the
SWML_SKIP_SCHEMA_VALIDATION=true environment variable.
Properties
name
Service display name.
route
HTTP route path where this service is accessible.
host
Host address the HTTP server binds to.
port
Port the HTTP server binds to.
log
Structured logger bound to this service name. Exposed for subclass access.
security
Unified security configuration loaded from environment variables and optional config file. Controls SSL, CORS, and host allowlist settings.
sslEnabled
Whether SSL/HTTPS is enabled. Mirrors security.sslEnabled.
sslCertPath
Path to the SSL certificate file.
sslKeyPath
Path to the SSL private key file.
domain
Domain name for SSL certificates.
schemaUtils
Schema validation utilities for SWML documents.
verbRegistry
Registry of custom verb handlers for specialized SWML verb processing.
Methods
Add a SWML verb to the document.
Add a new named section to the document.
Add a verb to a specific named section.
Reset the document to an empty state.
Render the SWML document as an object.
Get the SWML document as an object (Python-compat alias).
Render the SWML document as a JSON string.
Set a per-request callback for dynamic SWML generation.
Subclass override hook for per-request SWML.
Register a custom verb handler.
Register a routing callback at a given path.
Extract the username from a SIP URI (static).
Retrieve HTTP Basic Auth credentials.
Manually set the proxy URL for webhook generation.
Get the Hono app for mounting or testing.
Get the Hono app (Python-compat alias for getApp).
Get the underlying SwmlBuilder instance.
Start the HTTP server.
Start the HTTP server (Python-compat alias for run).
Stop the HTTP server.