Correct syntax for "Or" condition in GotoIf command

I am not sure about the correct syntax of an “or” condition in a GotoIF statement, in particular the use of square brackets.

Which of below four possibilities is correct?

exten => s,1,GotoIf($["${CALLERID(num)}" = “1000” | “${CALLERID(num)}” = “2000”]?2:3)

exten => s,1,GotoIf($[$["${CALLERID(num)}" = “1000”] | $["${CALLERID(num)}" = “2000”]]?2:3)

exten => s,1,GotoIf($["${CALLERID(num)}" = “1000”] | $["${CALLERID(num)}" = “2000”]?2:3)

exten => s,1,GotoIf($["${CALLERID(num)}" = “1000” | $["${CALLERID(num)}" = “2000”]?2:3)

My suggestion would be to use the following dialplan:

exten => s,1,NoOp()
same => n,GotoIf($["${CALLERID(num)}"="1000"]?true)
same => n,GotoIf($["${CALLERID(num)}"="2000"]?true)
same => n(false),NoOp(False)
same => n,Hangup()
same => n(true),NoOp(True)
same => n,Hangup()
2 Likes

Are you sure?
Both Asterisk wiki and other threads suggest you can do GotoIF statements with several “Or” conditions.
http://forums.asterisk.org/viewtopic.php?f=1&t=74354

https://wiki.asterisk.org/wiki/display/AST/Operators

1 Like

The first one.

However, also consider ex-girlfriend logic:

s/_[12]000

1 Like

Apologies, I will edit my post to remove the incorrect statement.

I’m a fan of doing it with a regex.

exten => 1000,1,NoOP()
same => n,Answer()
same => n,Set(MyNumber=2000)
same => n,NoOP(MyNumber is ${MyNumber})
same => n,ExecIf($[${MyNumber}:“1000|2000”]?Playback(demo-congrats)
same => n,Playback(goodbye)
same => n,Hangup()

2 Likes

same => n,ExecIf($[$["${curltmp:0:1}" = "-"] | ["${curltmp:0:1}" = "0"]?Playback(${stPath}/vouchers/balance-credit):Playback(${stPath}/vouchers/balance-debit))

is there something wrong with the syntax or it is nor supposed to work?

same => n,ExecIf($[$[“${curltmp:0:1}” = “-”] | [“${curltmp:0:1}” = “0”]]?Playback(${stPath}/vouchers/balance-credit):Playback(${stPath}/vouchers/balance-debit))

this works now(it was missing a closing bracket) if someone could explain to me the square brackets concept i would appreciate it

The square brackets define an “expression”.
https://wiki.asterisk.org/wiki/display/AST/Expressions

The string resulting from expanding variables and functions, within the square brackets is rescanned as an expression, and a numerical value is generated, as a string (and which you can see in the verbose log, for the outermost expression). If that string isn’t 0, the true branch is taken.

Assuming curltmp contains xyzza, the initial substitutions result in:

$[“x” = “-” | “x” = “0”]

which would evaluate to

0

when the $[...] is applied.

With your overcomplicated solution, one gets

$[$["x" = "-"] | $["x" = "0"]]

which reduces to:

$[0 | 0]

and finally to

0