Asterisk dialplan function GotoIf : Asterisk command gotoif

The GotoIf( ) Application

GotoIf( ) uses a special syntax, often called the conditional syntax:

GotoIf(expression?destination1:destination2)

If the expression evaluates to true, the caller is sent to the first destination. If the expression evaluates to false, the caller is sent to the second destination. So, what is true and what is false? An empty string and the number 0 evaluate as false. Anything else evaluates as true.

GotoIf is conditional goto command.

Go to label1 if condition is true or to next step (or label2 if defined) if condition is false, or

GotoIf(condition?[label1]:label2)

Go to next step (or label1 if defined) if condition is true or to label2 if condition is false.

Exapmle:

exten => 200,1,GotoIf($[“${CALLERID(num)}” = “303”]?dial1)
exten => 200,n,GotoIf($[“${CALLERID(num)}” != “304”]?moh:dial2)
exten => 200,n(dial1),Dial(${EXTEN},15,rt)
exten => 200,n,Hangup()
exten => 200,n(dial2),Dial(${myphone},15,rt)
exten => 200,n,Hangup()
exten => 200,n(moh),MusicOnHold(default)

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 have one more example:

exten => 100,1,Set(COUNT=5)
exten => 100,n,GotoIf($[${COUNT} > 0]?:5)
exten => 100,n,SayNumber(${COUNT})
exten => 100,n,Set(COUNT=$[${COUNT} – 1])
exten => 100,n,Goto(2)
exten => 100,n,Hangup( )

 

 

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

One thought on “Asterisk dialplan function GotoIf : Asterisk command gotoif

  • April 19, 2015 at 5:13 pm
    Permalink

    I do not even know the way I ended up here, however I assumed this publish used to be great.

    I don’t recognise who you are however certainly you’re going to a well-known blogger in case you
    are not already. Cheers!

Leave a Reply