If else in asterisk

Hi all,

I have the following context in extensions.conf:

[a2billing]
exten => _X.,1,Gotoif($[${EXTEN} = 111] ? 21)
exten => _X.,2,DeadAGI,a2billing.php
exten => _X.,3,Wait,2
exten => _X.,4,Hangup
exten => _X.,21,Playback(AR_GetGiveToID)
exten => _X.,22,Wait(2)
exten => _X.,23,Record(/tmp/asterisk-recording:ulaw,,5)
exten => _X.,24,Wait(2)
exten => _X.,25,Playback(/tmp/asterisk-recording)
exten => _X.,26,Wait(2)
exten => _X.,27,Hangup

If the customer dial 111, it'll be router to the entry with priority 21, else it'll go to priority 2...I would like to add a third condition that if the user dial let's say 112 it'll go to the priority 28 let's say

Regards
LVL 9
michofreihaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

feptiasChief DudeCommented:
I would suggest you use 31 not 28 as the jump-to step because 28 might get executed after 27, even though 27 is a hangup. It's easy to have multiple gotoif tests, just put them one after another like this:

[a2billing]
exten => _X.,1,Gotoif($[${EXTEN} = 111] ? 21)
exten => _X.,2,Gotoif($[${EXTEN} = 112] ? 31)
exten => _X.,3,DeadAGI,a2billing.php
exten => _X.,4,Wait,2
exten => _X.,5,Hangup
exten => _X.,21,Playback(AR_GetGiveToID)
exten => _X.,22,Wait(2)
exten => _X.,23,Record(/tmp/asterisk-recording:ulaw,,5)
exten => _X.,24,Wait(2)
exten => _X.,25,Playback(/tmp/asterisk-recording)
exten => _X.,26,Wait(2)
exten => _X.,27,Hangup
0
palnerCommented:
You should really start looking at naming contexts and avoiding renumbering:

exten => _X.,1,Gotoif($[${EXTEN} = 111] ? givetoid)
exten => _X.,n,Gotoif($[${EXTEN} = 112] ? nextcondition)
exten => _X.,n,DeadAGI,a2billing.php
exten => _X.,n,Wait,2
exten => _X.,n,Hangup
exten => _X.,n(givetoid),Playback(AR_GetGiveToID)
exten => _X.,n,Wait(2)
exten => _X.,n,Record(/tmp/asterisk-recording:ulaw,,5)
exten => _X.,n,Wait(2)
exten => _X.,n,Playback(/tmp/asterisk-recording)
exten => _X.,n,Wait(2)
exten => _X.,n,Hangup
exten => _X.,n(nextcondition),NoOp(Whatever needed)
0
feptiasChief DudeCommented:
...assuming the next step after a Hangup() is never executed.

I quite like explicit step numbering (provided they are written sequentially) because you can quickly find specific steps in a long dial plan. Also, you can be certain that the dial plan will stop when it reaches step X if there is no step X+1. But I can see the attraction of using n and name labels.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IP Telephony

From novice to tech pro — start learning today.