O'Reilly logo

Asterisk: The Future of Telephony by Leif Madsen, Jared Smith, Jim Van Meggelen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

GotoIf() — Conditionally goes to the specified priority

Synopsis

    GotoIf(condition?label1:label2)

Sends the call to label1 if condition is true or to label2 if condition is false. Either label1 or label2 may be omitted (in that case, we just don’t take the particular branch), but not both.

A label can be any one of the following:

  • A priority, such as 10

  • An extension and a priority, such as 123,10

  • A context, extension, and priority, such as incoming,123,10

  • A named priority within the same extension, such as passed

Each type of label is explained in the example below.

    [globals]
    ; set TEST to something else besides 101 to see what GotoIf()
    ; does when the condition is false
    TEST=101
    ;
    [incoming]
    ; set a variable
    ; go to priority 10 if ${TEST} is 101, otherwise go to priority 20
    exten => 123,1,GotoIf($[ ${TEST} = 101 ]?10:20)
    exten => 123,10,Playback(the-monkeys-twice)
    exten => 123,20,Playback(tt-somethingwrong)
    ;
    ; same thing as above, but this time we'll specify an extension
    ; and a priority for each label
    exten => 124,1,GotoIf($[ ${TEST} = 101 ]?123,10:123,20)
    ;
    ; same thing as above, but these labels have a context, extension, and
    ; priority
    exten => 125,1,GotoIf($[ ${TEST} = 101 ]?incoming,123,10:incoming,123,20)
    ;
    ; same thing as above, but this time we'll go to named priorities
    exten => 126,1,GotoIf($[ ${TEST} = 101 ]?passed:failed)
    exten => 126,15(passed),Playback(the-monkeys-twice)
    exten => 126,25(failed),Playback(the-monkeys-twice)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required