add_verb

View as MarkdownOpen in Claude

Add a verb to the main section of the current SWML document. The verb is validated against the SWML schema (or a registered custom handler) before being appended. Raises SchemaValidationError if validation is enabled and the verb config is invalid.

For verbs with a registered handler, such as ai, the handler validates the verb’s shape and the top-level keys are then checked against the schema, so a misspelled or unknown top-level key raises. Nested shapes such as ai.params are left to the handler.

SWMLService also auto-generates convenience methods for every verb defined in the SWML schema (e.g., service.play(url=...), service.connect(to=...)). These call add_verb internally. Use add_verb directly when you need to pass a pre-built config dictionary or work with custom verbs.

Parameters

verb_name
strRequired

The SWML verb name (e.g., "answer", "play", "ai", "hangup", "connect").

config
dict[str, Any] | intRequired

Configuration dictionary for the verb. Most verbs accept a dict of parameters. The sleep verb is a special case that accepts a direct int value representing milliseconds.

Returns

bool — True if the verb was added successfully, False if the config type was invalid (non-dict for non-sleep verbs).

Example

from signalwire import SWMLService
service = SWMLService(name="ivr")
service.add_verb("answer", {})
service.add_verb("play", {"url": "https://example.com/greeting.mp3"})
service.add_verb("sleep", 2000)
service.add_verb("hangup", {"reason": "completed"})
print(service.render_document())