Branching In Extensions.conf?
Is there any less cumbersome way of doing conditionalized/branching in extensions.conf other than something like:
exten => s,n,GotoIf($[“${SIP}” = “PJSIP” ]?pjsip)
exten => s,n,Dial(${ARG2},20,TtWw)
exten => s,n,Goto(afterdial)
exten => s,n(pjsip),Dial(${PJSIP_DIAL_CONTACTS(${STRREPLACE(ARG2,”PJSIP/”,””)})},20,TtWw)
exten => s,n(afterdial),Goto(s-${DIALSTATUS},1)
Granted the particular above example could probably be better written to simply modify $ARG2 based on ${SIP} rather than having two Dial()
branches, but using the above as just an example for wanting to have branches, is there a less cumbersome way?
Cheers, b.
5 thoughts on - Branching In Extensions.conf?
Use the IF function to evaluate and change the dial command directly.
My braces and parens may be off in this example sorry if it doesn’t work out of the box. exten => s,n,Dial(${IF($[“${SIP}” = “PJSIP”]?
${PJSIP_DIAL_CONTACTS(${STRREPLACE(ARG2,”PJSIP/”,””)})}{ARG2})},20,TtWw)
Thanks for taking the time, but that doesn’t actually answer the question I asked. It in fact answers the caveat I specifically mentioned:
But I also stated that I was just using it as example of a need to branch and how cumbersome using Goto[If] makes it.
Again, appreciate that you took the time, but really looking for an answer to the “better way to branch” question.
Hah. This won’t work either, for the reason I asked about in my followup question about where the “true” value of an ${IF …}has a colon in it and is taken to be the end of the true value and the start of the false value.
And your ${IF …} is missing the colon between the true and false values but I still understood what you were getting at.
Cheers, b.
I don’t see any other messages in this thread other than your initial one and my response, perhaps the listserv hasn’t relayed it to me yet.
I switch between ExecIf/GotoIf/GosubIf and the IF function as needed in my dialplan design, if It’s just a one liner I’ll usually use either the IF
function or the ExecIf, When I need to handle multiple different lines I
either Gosub to a different context to handle things and return or use a priority label in the same context.
I’ve not run into any problem with colons in my IF statements but I don’t think that’s something I’ve had to work with/around before.
Shoot, I must have erased the colon when I was trying to fix the parentheses.
It seems like these days everyone wants to use ARI, You could always send the call into Stasis and handle your logic in a language of your choice but that’s a whole different discussion.
If you want your dialplan code to look pretty, use AEL.
—
http://help.nyigc.net/
—
I started a new thread:
http://lists.digium.com/pipermail/asterisk-users/2019-February/293668.html
since it was a separate question and only tangentially related to this one.
Yeah, ExecIf was the suggested workaround in the companion thread mentioned above.
Likely that’s just it. I’ve only just run into it for the first time now after many years of Asterisk.
NP. I understood your proposal.
Yeah. extensions.conf is starting to feel long-in-the-tooth these days. 🙂
Cheers, b.