System information

Either of the destinations may be omitted, but not both. If the omitted destination is
to be followed, Asterisk simply goes on to the next priority in the current extension.
Let’s use GotoIf() in an example:
exten => 345,1,Set(TEST=1)
same => n,GotoIf($[${TEST} = 1]?weasels:iguanas)
same => n(weasels),Playback(weasels-eaten-phonesys)
same => n,Hangup()
same => n(iguanas),Playback(office-iguanas)
same => n,Hangup()
You will notice that we have used the Hangup() application following
each use of the Playback() application. This is done so that when we
jump to the weasels label, the call stops before execution gets to the
office-iguanas sound file. It is becoming increasingly common to see
extensions broken up into multiple components (protected from each
other by the Hangup() command), each one a distinct sequence of steps
executed following a GotoIf().
Providing Only a False Conditional Path
If we wanted to, we could have crafted the preceding example like this:
exten => 345,1,Set(TEST=1)
same => n,GotoIf($[${TEST} = 1]?:iguanas) ; we don't have the weasels label anymore,
; but this will still work
same => n,Playback(weasels-eaten-phonesys)
same => n,Hangup()
same => n(iguanas),Playback(office-iguanas)
same => n,Hangup()
There’s nothing between the ? and the :, so if the statement evaluates to true, execution
will continue at the next step. Since that’s what we want, a label isn’t needed.
We don’t really recommend doing this, because it’s hard to read, but you will see
dialplans like this, so it’s good to be aware that this syntax is totally correct.
Typically, when you have this type of layout where you end up wanting to prevent
Asterisk from falling through to the next priority after you’ve performed that jump, it’s
probably better to jump to separate extensions instead of priority labels. If anything, it
makes it a bit more clear when reading the dialplan. We could rewrite the previous bit
of dialplan like this:
exten => 345,1,Set(TEST=1)
same => n,GotoIf($[${TEST} = 1]?weasels,1:iguanas,1) ; now we're going to
; extension,priority
exten => weasels,1,Playback(weasels-eaten-phonesys) ; this is NOT a label.
; It is a different extension
same => n,Hangup()
200 | Chapter 10:Deeper into the Dialplan