For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
ReferenceGuides
ReferenceGuides
  • Core
    • Introduction to SWML
    • Expressions
    • Template functions
    • Variables
    • Errors
  • Calling
    • Overview
    • ai
    • ai_sidecar
    • amazon_bedrock
    • answer
    • cond
    • connect
    • denoise
    • detect_machine
    • enter_queue
    • execute
    • goto
    • hangup
    • join_conference
    • join_room
    • label
    • live_transcribe
    • live_translate
    • pay
    • play
    • prompt
    • receive_fax
    • record
    • record_call
    • request
    • return
    • send_digits
    • send_fax
    • send_sms
    • set
    • sip_refer
    • sleep
    • stop_denoise
    • stop_record_call
    • stop_tap
    • switch
    • tap
    • transcribe
    • transcribe_stop
    • transfer
    • unset
    • user_event
  • Messaging
    • Overview
    • execute
    • goto
    • label
    • receive
    • reply
    • request
    • return
    • switch
    • transfer
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Properties
  • Examples
  • Keyword-based reply
  • Branch on a saved request response
Messaging

switch

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

transfer

Next
Built with

Branch on a variable’s value, with optional text transforms applied before matching. Useful for keyword-driven inbound message handling.

Properties

switch
objectRequired

An object that accepts the following properties.

switch.variable
stringRequired

Variable path to match. Specified without the %{} wrapper (e.g. message.body).

switch.transform
string

Transform to apply to the value before matching. One of lowercase, uppercase, trim, lowercase_trim, or uppercase_trim.

switch.case
objectRequired

Map of values to arrays of SWML methods to execute. The key is the value to compare against variable (after applying transform); the value is the array of methods to run on match.

switch.default
object[]

Array of SWML methods to execute if no case matches. If omitted and no case matches, execution stops with an error.

Examples

Keyword-based reply

1version: 1.0.0
2sections:
3 main:
4 - switch:
5 variable: message.body
6 transform: lowercase_trim
7 case:
8 help:
9 - reply:
10 body: "Reply STOP to unsubscribe, or visit https://example.com/help."
11 stop:
12 - reply:
13 body: "You've been unsubscribed."
14 start:
15 - reply:
16 body: "Welcome back!"
17 default:
18 - reply:
19 body: "Sorry, I didn't understand that. Reply HELP for assistance."

Branch on a saved request response

1version: 1.0.0
2sections:
3 main:
4 - request:
5 url: "https://api.example.com/customer"
6 body:
7 phone: "%{message.from}"
8 save_variables: true
9 - switch:
10 variable: request_response.tier
11 case:
12 gold:
13 - reply:
14 body: "Welcome back, valued customer!"
15 silver:
16 - reply:
17 body: "Thanks for being a member."
18 default:
19 - reply:
20 body: "Thanks for your message."