switch
Execute a sequence of instructions depending on which value matches a variable.
Name | Type | Default | Description |
---|---|---|---|
switch Required | object | - | An object that accepts the switch parameters . |
switch Parameters
Name | Type | Default | Description |
---|---|---|---|
variable Required | string | - | Name of the variable whose value needs to be compared. |
case Required | object | - | Case_params object of key-mapped values to array of SWML Methods to execute. |
default Optional | [] | - | 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.
Name | Type | Description |
---|---|---|
[key: string] Required | SWMLMethods[] | Name of the variable whose value needs to be compared |
Examples
- YAML
- JSON
version: 1.0.0
sections:
main:
- switch:
variable: call.type
case:
sip:
- play:
url: "say: You're calling from SIP."
phone:
- play:
url: "say: You're calling from phone."
default:
- play:
url: 'say: Unexpected error'
{
"version": "1.0.0",
"sections": {
"main": [
{
"switch": {
"variable": "call.type",
"case": {
"sip": [
{
"play": {
"url": "say: You're calling from SIP."
}
}
],
"phone": [
{
"play": {
"url": "say: You're calling from phone."
}
}
]
},
"default": [
{
"play": {
"url": "say: Unexpected error"
}
}
]
}
}
]
}
}
- YAML
- JSON
version: 1.0.0
sections:
main:
- set:
foo: 5
- execute:
dest: example_fn
params:
foo: '%{foo}'
example_fn:
- switch:
variable: params.foo
default:
- play:
url: 'say: nothing matches'
case:
'5':
- play:
url: 'say: yup, math works!'
{
"version": "1.0.0",
"sections": {
"main": [
{
"set": {
"foo": 5
}
},
{
"execute": {
"dest": "example_fn",
"params": {
"foo": "%{foo}"
}
}
}
],
"example_fn": [
{
"switch": {
"variable": "params.foo",
"default": [
{
"play": {
"url": "say: nothing matches"
}
}
],
"case": {
"5": [
{
"play": {
"url": "say: yup, math works!"
}
}
]
}
}
}
]
}
}