Skip to main content

switch

Execute a sequence of instructions depending on which value matches a variable.

Parameters

NameTypeDescription
variableRequiredstringName of the variable whose value needs to be compared
caseRequiredcase_params objectObject of values mapped to array of instructions to execute
defaultOptionalarrayOptional array of instructions to execute if no cases match

case_params

The case_params object should have the list of values to compare to as keys, and the array of instructions to execute should be assigned to corresponding keys.

NameTypeDescription
[key]Requiredarray of SWML instructionsName of the variable whose value needs to be compared

Examples

version: 1.0.0
sections:
main:
# in a noninstructional context, you might simply want to use
# play: "say:You're calling from %{call.type}."
- switch:
variable: call.type
case:
"sip":
- play: "say: You're calling from SIP."
"phone":
- play: "say: You're calling from phone."
default:
- play: "say: Unexpected error"
version: 1.0.0
sections:
main:
- set:
foo: 5
- execute:
dest: example_fn
params:
foo: "%{foo}"

example_fn:
- switch:
variable: params.foo
default:
- play: "say: nothing matches"
case:
"5":
- play: "say: yup, math works!"