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.

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

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

Example

1from signalwire import SWMLService
2
3service = SWMLService(name="ivr")
4service.add_verb("answer", {})
5service.add_verb("play", {"url": "https://example.com/greeting.mp3"})
6service.add_verb("sleep", 2000)
7service.add_verb("hangup", {"reason": "completed"})
8
9print(service.render_document())