SWMLBuilder
SWMLBuilder provides a fluent interface for constructing SWML documents by chaining
method calls. It wraps a SWMLService
instance and delegates all document operations to it, while returning self from every
verb method to enable chaining. 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 schema (e.g., connect(), record(), denoise(),
goto()). These dynamic methods accept keyword arguments matching the verb’s SWML
parameters and return self for chaining.
SWMLBuilder constructs SWML documents programmatically. See the SWML reference for the full specification of all supported verbs.
Properties
service
The SWMLService instance that
handles actual document storage, validation, and rendering. The builder delegates
all operations to this service.
Dynamic Verb Methods
SWMLBuilder auto-generates chaining methods for every verb defined in the SWML schema
that does not already have an explicit method. These dynamic methods accept keyword
arguments matching the verb’s SWML parameters and return Self.
Examples of dynamic verbs: connect(), record(), record_call(), denoise(),
transfer(), goto(), cond(), execute(), tap(), and many more.
The sleep verb is a special case — it accepts a positional duration argument
(milliseconds) instead of keyword arguments:
If a verb name is not found in the SWML schema, calling it raises an AttributeError.
Methods
Add a new named section to the SWML document.
Add an AI verb to start an AI-powered conversation.
Add an answer verb to the SWML document.
Build and return the complete SWML document as a dictionary.
Add a hangup verb to end the current call.
Add a play verb to play audio or text-to-speech.
Build and render the complete SWML document as a JSON string.
Reset the SWML document to an empty state.
Add text-to-speech playback to the SWML document.