Basic GotoIf Question

Home » Asterisk Users » Basic GotoIf Question
Asterisk Users 4 Comments

Hi all,

on Asterisk 1.4.21 I’m trying to block, that means directly hang up on, several inbound Caller ID‘s like this:

exten => 5555,1,GotoIf($[“${CALLERID(num)}” != “6666”]?pass)
exten => 5555,n,GotoIf($[“${CALLERID(num)}” != “7777”]?pass)
exten => 5555,n,GotoIf($[“${CALLERID(num)}” != “8888”]?pass)
exten => 5555,n,Hangup exten => 5555,n(pass),Set… everything from here on works.

When I’m calling with caller ID 6666 I get hung up. When I’m calling from 7777 or 8888 I get connected.

That means on the first GotoIf match the remaining GotoIf’s are ignored. How can I avoid that?

I’m a bit surprised, because “Example 3” at http://www.voip-info.org/wiki/view/Asterisk+cmd+GotoIf shows that it should actually be working.

A few more questions – the doc link that I just mentioned shows:

” GotoIf(condition?label1[[:label2]) “

What is the [[ before :label2? There are two opening square brackets, but just one ] closing? Is that a typo?

Also, the doc shows:

” GotoIf(condition?[label1]:label2) “

Why is label1 in square brackets and label2 isn’t?

I’m confused. 🙂

Thanks so much!
Markus

4 thoughts on - Basic GotoIf Question

  • Am 25.08.2012 09:21, schrieb Noah Engelberth:

    Thanks Noah! That worked.

    Can anyone shed some light on:

    A few more questions – the doc link that I just mentioned shows:

    GotoIf(condition?label1[[:label2])

    What are the [[ before :label2? There are two opening square brackets, but just one ] closing? Is that a typo?

    Also, the doc shows:

    GotoIf(condition?[label1]:label2)

    Why is label1 in square brackets and label2 isn’t?

    Thanks!
    Markus

  • In article <50390065.6020200@truemetal.org>, Markus wrote:

    Yes, it looks like a typo and should be [ instead of [[

    These square brackets are not part of the syntax, but are just showing that the colon and label2 are optional, so it means you can have either:

    GotoIf(condition?label1:label2)

    or:

    GotoIf(condition?label1)

    In the latter case, you branch to label1 if the condition is true, and just continue with the next statement if it’s false.

    This is saying that label1 is optional. If you only want to branch when the condition is false, you say:

    GotoIf(condition?:label2)

    I guess it could easily have been confusing because typically the condition is an expression contained within $[…], where the square brackets ARE part of the syntax!

    Hope this helps!

    Cheers Tony