switch
Execute a sequence of instructions depending on which value matches a variable.
Parameters
Name | Type | Required? | Description |
---|---|---|---|
variable | string | Required | Name of the variable whose value needs to be compared |
case | case_params object | Required | Object of values mapped to array of instructions to execute |
default | array | Optional | Optional 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.
Name | Type | Required? | Description |
---|---|---|---|
[key] | array of SWML instructions | Required | Name of the variable whose value needs to be compared |
Examples
- YAML
- JSON
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": [
{
"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!"