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
  • case_params
  • Examples
  • See Also
Calling

switch

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

tap

Next
Built with

Execute different instructions based on a variable’s value

Properties

switch
objectRequired

An object that accepts the following properties.

switch.variable
stringRequired

Name of the variable whose value needs to be compared.

switch.case
objectRequired

Case_params object of key-mapped values to array of SWML Methods to execute.

switch.default
[]

Array of SWML Methods to execute if no cases match.

case_params

The case_params object serves as a dictionary where each key is a string identifier, and the associated value is an array of SWML Method objects.

case.property_name
[]objectRequired

Name of the variable whose value needs to be compared.

Examples

1version: 1.0.0
2sections:
3 main:
4 - switch:
5 variable: call.type
6 case:
7 sip:
8 - play:
9 url: "say: You're calling from SIP."
10 phone:
11 - play:
12 url: "say: You're calling from phone."
13 default:
14 - play:
15 url: 'say: Unexpected error'
1version: 1.0.0
2sections:
3 main:
4 - set:
5 foo: 5
6 - execute:
7 dest: example_fn
8 params:
9 foo: '${foo}'
10 example_fn:
11 - switch:
12 variable: params.foo
13 default:
14 - play:
15 url: 'say: nothing matches'
16 case:
17 '5':
18 - play:
19 url: 'say: yup, math works!'

See Also

  • Variables and Expressions: Complete reference for SWML variables, scopes, and using variables in conditional logic
  • cond: Alternative conditional logic method