switch

View as MarkdownOpen in Claude

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