add_verb_to_section

View as MarkdownOpen in Claude

Add a verb to a specific named section of the SWML document. If the section does not exist, it is created automatically before the verb is 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.

Parameters

section_name
strRequired

Name of the section to add the verb to (e.g., "main", "transfer_flow").

verb_name
strRequired

The SWML verb name.

config
dict[str, Any] | intRequired

Configuration dictionary for the verb, or a direct int for the sleep verb.

Returns

boolTrue 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="transfer-flow")
# Build the main section
service.add_verb("answer", {})
service.add_verb("ai", {"prompt": {"text": "You are a helpful assistant"}})
# Build a separate transfer section
service.add_verb_to_section("transfer", "connect", {
"to": "+15551234567",
"from": "+15559876543"
})
print(service.render_document())