ExecIF is quite powerful but not that well document, and the documentation I've seen is usually wrong or not well explained. I'm not sure if I can explain it that well, but what I can give are some reasonable real world diaplan examples.
Here are some ExecIF statements (Asterisk 1.6+)This method is probably the most common usage of the command. Here's is the structure of the command broke out in colors to identify the different components.
ExecIf($[StringCondition]?CMD-if-TRUE(cmd-args))
ExecIF condition Matched
This code will play "Beep Beep" if the variable matches as 'TRUE"
ExecIf($["${VARIABLE}" = "TRUE"]?Playback(beep&beep))
This will execute a 'goto' IF variable is NOT equal to "Always" (hence the !=)
ExecIf($["${VARIABLE}" != "TRUE"]?Goto(subheading))
ExecIf($["${VARIABLE}" = "TRUE"]?Set(variable=100))
ExecIf($["${VARIABLE}" = "TRUE"]?Set(variable=${anothervariable}))
ExecIf / Else condition
ExecIf($[StringCondition]?CMD-if-TRUE(args):CMD-if-FALSE(args))
EXAMPLE 1
exten => s,n,ExecIf($["${REALCALLERIDNUM}" = "5551234"]?set(testvar=TRUE):set(testvar=FALSE))
RESULT
If variable "REALCALLERIDNUM" is equal to 5551234 then the result is TRUE
If variable "REALCALLERIDNUM" does not equal, RESULT will be FALSE and testvar will be set to FALSE
EXAMPLE 2
exten => s,n,ExecIf($["${REALCALLERIDNUM}" != "5551234"]?set(testvar=Match):Goto(NoMatch))
exten => s,n,NoOp(MATCH!)
exten => s,n,Hangup()
exten => s,n(NoMatch),NoOp(NO MATCH!)
exten => s,n,Hangup()
RESULT - If equal, var set to "Match". ELSE goto (False) cmd executed.
ExecIF with a function
Using a Function in the string condition. We'll use a "!" symbol indicating "NOT". You'll notice it precedes the "LEN" (Length) CMD with a ! function.
The first example basically says. Is the LEN of the variable !NOT have data ("NULL")?
testvar4=TESTData4
exten => s,n,ExecIf($[!${LEN(${testvar4})}]?Set(testvar=TRUE):Set(testvar=FALSE))
RESULT = FALSE, the length of testvar4 is not null (variable contains data)
testvar4=
exten => s,n,ExecIf($[!${LEN(${testvar4})}]?Set(testvar=TRUE):Set(testvar=FALSE))
RESULT TRUE, the length of testvar4 is NULL (Variable contains no data)
ExecIF group of variables all match the same condition
"Are all the variables listed set to the same value required"
exten => s,n,set(testvar1=TEST1)
exten => s,n,set(testvar2=TEST2)
exten => s,n,set(status=NO)
exten => s,n,ExecIf($["${testvar1}${testvar2}" = ""]?Set(status=TRUE))
RESULT is not true
The check confirms neither variables are both NULL status is NOT "TRUE"
We set testvar2 to "Null"
exten => s,n,set(testvar1=TEST1)
exten => s,n,set(testvar2=)
exten => s,n,set(status=NO)
exten => s,n,ExecIf($["${testvar1}${testvar2}" = ""]?Set(status=TRUE))
RESULT is not true
The check confirms neither variables are both NULL status is NOT "TRUE"
We set testvar1 to "Null"
exten => s,n,set(testvar1=)
exten => s,n,set(testvar2=)
exten => s,n,set(status=NO)
exten => s,n,ExecIf($["${testvar1}${testvar2}" = ""]?Set(status=TRUE))
RESULT is TRUE
The check confirms both variables are NULL and sets status is "TRUE"
ExecIF with OR operator ( | )
Testing if either variable is set, the | pipe symbol indicating an OR.
In this example we look to see if either variable is assigned with "TEST"
exten => s,n,set(testvar1=TEST)
exten => s,n,set(testvar2=TEST)
exten => s,n,set(status=FALSE)
exten => s,n,ExecIf($["${testvar1}" = "TEST" | "${testvar2}" = "TEST"]?set(status=TRUE))
RESULT = TRUE
exten => s,n,set(testvar1=FALSE)
exten => s,n,set(testvar2=TEST)
exten => s,n,set(status=FALSE)
exten => s,n,ExecIf($["${testvar1}" = "TEST" | "${testvar2}" = "TEST"]?set(status=TRUE))
RESULT = TRUE
exten => s,n,set(testvar1=FALSE)
exten => s,n,set(testvar2=FALSE)
exten => s,n,set(status=FALSE)
exten => s,n,ExecIf($["${testvar1}" = "TEST" | "${testvar2}" = "TEST"]?set(status=TRUE))
RESULT = FALSE
ExecIF with AND operator (&)
exten => s,n,set(testvar1=TESTData1)
exten => s,n,set(testvar2=TESTData2)
exten => s,n,ExecIf($["${testvar1}" = "TESTData1" & "${testvar2}" = "TESTData2"]?set(status=TRUE):set(status=FALSE))
RESULT = TRUE
exten => s,n,set(testvar1=TESTData1)
exten => s,n,set(testvar2=)
exten => s,n,ExecIf($["${testvar1}" = "TESTData1" & "${testvar2}" = "TESTData2"]?set(status=TRUE):set(status=FALSE))
RESULT = FALSE testvar2 is not a match
placeholder
No comments:
Post a Comment
Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.