GotoIF in extension

Hi, I inherited an existing system for a new client, and they are wanting to make some changes. They have multiple DID’s in the system, and need to play a certain message based on the number dialed. They have a bunch of different DIDs in different areas, and rather than have to keep modifying the call flow everytime, figured it’d be easier to use variables. We’re still waiting for credentials and access, but figured, I’d start working on this

This is what I was thinking of doing: (#included from extensions.conf)

exten => 55305,1,Answer
same => n,AGI(cmp-weather-v2.php,“KMIA”)
same => n,Playback(/var/lib/asterisk/sounds/weather/KMIA-weather)
same => n,Playback(/var/lib/asterisk/sounds/KMIA-status)
same => n,Playback(/var/lib/asterisk/sounds/en/goodbye)
same => n,Hangup

exten => 55954,1,Answer
same => n,AGI(cmp-weather-v2.php,“KFLL”)
same => n,Playback(/var/lib/asterisk/sounds/weather/KFLL-weather)
same => n,Playback(/var/lib/asterisk/sounds/KFLL-status)
same => n,Playback(/var/lib/asterisk/sounds/en/goodbye)
same => n,Hangup

exten => 55999,1,NoOp(Here we go)
same => n,Playback(/var/lib/asterisk/sounds/companygreeting)
same => n,Goto(${CALLERID(dnid):-7})
same => n(305),Goto(55305,1)
same => n(954),Goto(55954,1)
same => n,NoOp(No match)
same => n,Playback(/var/lib/asterisk/sounds/en/goodbye)
same => n,Hangup

Would this work?

You’d need to prefix/suffix the label so that it is not a pure number, as I’d expect a pure number to be treated as a literal priority.

Where is CALLERID(dnid) set, and where the the original extensions come from if not the dialled numbers?

Isn’t CALLERID(dnid) one of the standard channel variable?

Would something like this be acceptable then:

same => n,Goto(“x”~~${CALLERID(dnid):-7})
same => n(x305),Goto(55305,1)
same => n(x954),Goto(55954,1)

Why wouldn’t you read EXTEN in the AGI, do your magic there, and play the weather, status, and goodbye as well?

If you drive the AGI based on database lookups using EXTEN and all the dialplan complexity/maintenance goes away.

Go a step further and give them a web page to maintain the database table(s) and you may not have to touch anything for years :slight_smile:

I might be wrong, but I think you have to explicitly set it. In any case, the only thing to sensibly set it to would be the initial value of ${EXTEN} for the call, hence my question about where the extension comes from.

Have you considered doing this directly in the context that handles the DID?

[voipms-inbound]
exten = 5715555555,1,Set(iext=6420)
same = n,Goto(inbound-ivr,s,1)


exten = 5875555555,1,Set(iext=6421)
same = n,Goto(inbound-ivr,s,1)


exten = 445555555555,1,Set(iext=6423)
same = n,Goto(inbound-ivr,s,1)

This basically sets the iext variable for the channel; which contains the extension that I run that “line” on. This allows me to have a single generic IVR while directing the calls to the right extension.

exten = XXXX,1,Playback(pls-hold-while-try)
same = n,Dial(${PJSIP_DIAL_CONTACTS(${iext})},20})
same = n,VoiceMail(${iext}@default,u)
same = n,Hangup()

That would be another possibility once we get a bit more under the hood in this environment. There’s a lot of moving pieces, as one of the owners wants to start making a lot of changes, so going to see what they’re thinking of doing before I reinvent the wheel…Thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.