[asterisk-users] Basic GotoIf question

Noah Engelberth Noah at directlinkcomputers.com
Sat Aug 25 12:01:33 CDT 2012



-----Original Message-----
From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Markus
Sent: Saturday, August 25, 2012 12:42 PM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Basic GotoIf question

Am 25.08.2012 09:21, schrieb Noah Engelberth:
>
> 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
>
> ---
>
> You need to run your logic the other way. What you're doing now is "if it's not CallerID A, pass it through and accept"
>
> So change to:
>
> exten => 5555,1,GotoIf($["${CALLERID(num)}" = "6666"]?hangup) exten => 
> 5555,n,GotoIf($["${CALLERID(num)}" = "7777"]?hangup) exten => 
> 5555,n,GotoIf($["${CALLERID(num)}" = "8888"]?hangup) exten => 
> 5555,n,Set...
> ...more logic for accepted calls...
> exten => 5555,n(hangup),Hangup()

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 general in the documentation, [something] means that said something is optional.  Sometimes you might see [[something] something else] which indicates a "chain" of optional inputs.

Basically, for GotoIf (and the sister applications GotoIfTime, ExecIf, and ExecIfTime), you have the syntax as follows:
GotoIf(condtion?what-to-do-if-true:what-to-do-if-false)

So, Asterisk evalutates your condition, then if it's true, does what's between the ? and the :.  If your condition is false, Asterisk does what's between the : and the ).  You don't have to have either condition (though you have to have at least one).  If there is no condition for true (or false), Asterisk will "do nothing" with the GotoIf and continue on to the next line in your dialplan.  Obviously, then, having a GotoIf without at least one of what-to-do-if-true or what-to-do-if-false will wind up being pretty useless -- you'll always want at least one, if not both "what to do's" in your GotoIfs.

Thank you,

Noah Engelberth 
MetaLINK Technologies



More information about the asterisk-users mailing list