SwmlBuilder
SwmlBuilder provides a fluent interface for constructing SWML documents by chaining
verb method calls. It produces documents of the form
{ version: "1.0.0", sections: { main: [...verbs] } }. Use SwmlBuilder when you
want concise, readable document construction in a single expression.
In addition to the explicitly defined methods below, SwmlBuilder automatically generates
methods for every SWML verb in the bundled schema (e.g., connect(), record(),
denoise(), goto()). These dynamic methods accept an optional
config?: Record<string, unknown> parameter and return this for chaining.
SwmlBuilder constructs SWML documents programmatically. See the SWML reference for the full specification of all supported verbs.
Constructor
The constructor takes no parameters. It initializes an empty SWML document and installs dynamic verb methods from the bundled schema.
Dynamic Verb Methods
SwmlBuilder auto-generates chaining methods for every verb defined in the SWML schema.
These dynamic methods accept an optional config object matching the verb’s SWML
parameters and return this for chaining.
Examples of dynamic verbs: connect(), record(), recordCall(), denoise(),
transfer(), goto(), cond(), execute(), tap(), and many more.
The sleep verb is a special case — it accepts either a number (duration) directly
or a config object:
Methods
Append a verb to the main section.
Append a verb to a named section.
Add an AI verb to start an AI-powered conversation.
Add an answer verb to the SWML document.
Return the raw SWML document object.
Get the shared SchemaUtils singleton (static).
Add a hangup verb to end the current call.
Add a play verb to play audio or text-to-speech.
Serialize the SWML document to a JSON string.
Reset the SWML document to an empty state.