Dial extensions in different context

I have asterisk running perfectly with two sip accounts. What I am tryng to do is when customers call they push 0 for example and asterisk transfers them to an isolated context where they can enter the 4-digit extension of who they are trying to reach, the actual extensions are in a different context. When they enter this 4-digit extension number, I want asterisk to dial the entered extension in that different context.

so dial it…
maybe not understanding what you want…

In the extensions.conf file, add @[context] after the dial string. Not sure if you’re doing it dynamically or static, but from what I think you’re saying is you want the 4 digits to be configured in a seperate context than the context caller originated from.


Same with your SIP providers, on our external OB plan in extensions.conf, you can add @[voipcarrier1context] referencing the voip context in your SIP.CONF.




Yes, I have a dynamic extension setup. I have tried a similar setup as above and I have also just tried the above response with no effect. Below are both contexts:

[customer call-in]

exten => i,1,Answer
exten => i,2,Playback(invalid)
exten => i,3,Goto(customer call-in,s,1)

exten=> _1NXXNXXXXXX, 1, dial(SIP/${EXTEN}@out,30)
exten=> _1NXXNXXXXXX, 2, dial(SIP/${EXTEN}@out2,30)
exten=> _1NXXNXXXXXX, 3, congestion()
exten=> _1NXXNXXXXXX, 102, busy()
exten=>*86,1,VoicemailMain,101 ;To check your voicemail by dialing *86



At this point I can’t really tell if it will successfully call the extension in the other context because the errors that keep coming up is mostly invalid extension; even though enter the 4-didgit extension, asterisk does not seem to catch the whole four digits. For example if I enter 1001, aterisk only catches “1”, or “10”, or “100” such as the debug below:

– Playing ‘please-enter-your-partys-ext’ (language ‘en’)
– Invalid extension ‘100’ in context ‘internal’ on SIP/myphonenumber-a3b6
== CDR updated on SIP/myphonenumber-a3b6
– Executing Answer(“SIP/myphonenumber-a3b6”, “”) in new stack
– Executing Playback(“SIP/myphonenumber-a3b6”, “invalid”) in new stack
– Playing ‘invalid’ (language ‘en’)
– Executing Goto(“SIP/myphonenumber-a3b6”, “internal|s|1”) in new stack
– Goto (internal,s,1)
– Executing Wait(“SIP/myphonenumber-a3b6”, “1”) in new stack

Ok I see what you’re trying to do. I think I have an idea that may work, I’m finishing it up and testing on my test box. However, you’re using older code formats. Are you running Asterisk 1.2 or higher?

Yes, I am running asterisk

Ok, depending how your voicemail app is setup, it may not be 100% perfect but see if this is what you want. This prompt exactly the same as you had it before. Have the user dial the 4 digit valid extension and will ring 30 seconds, then goto voice mail. If they enter an invalid extension, it will say your invalid and re-prompt to enter an extension. If they don’t respond in 10 seconds, will say are you still there, then prompt again.

The only “flaw” I see with this as-is, is if you don’t have the vm app configured to disconnect the call when the caller presses # or what not (in otherwords, once vm app exits, call goes to the next priority in dial plan), they will hear the “invalid” message again as if they had dialed an extension. However if they leave a message and hang up then there wouldn’t be anything out of the ordinary. Check this out and see if this is what you’re looking for.

I forgot to add… be sure to delete the following from your internal context…


The only reference for 4 digit dialing should be in what I gave you in the customer call-in context only. So on an inbound call, if they press 0 and you point 0 to the customer call-in context, that 4 digit plan is exclusive to that customer call-in context.

Thanx for the response. The above config you provided does not seem to make a difference. The response was the same, it did not completely catch the whole 4 digits before trying to dial the extension and at other times it just rang busy. In a previous response, you mentioned that I was working with older code format, where can I find newer code formats please? The main reason I am trying to isolate incoming customers to the ‘customer call-in’ context is that the main context that actually contains the extensions also contains the outbound dial plans such that if customers get in there they can make outbound calls (aka call-through) which I don’t want to allow. So I am still working on trying to have customer incoming calls isolated and somehow be able to dial the extensions in the other context through the isolated context [customer-call-in] .

If you want to secure your system so only internal extensions can dialout, yet all extensions are available for incoming callers, you may want to create separate contexts for your system extensions and your outbound trunks.

This is how I got around that problem. Basically I have my extensions in a context, my outbound trunks in another context and my inbound calls in another context. Since my inbound calls never hit a context that includes [pstn_outbound] they can never get to my outbound trunks, only to the operator and the IVR with the ability to dial internal extensions.

For Example:

include => operator
include => extension_1100
include => extension_1102
include => extension_1103

include => pstn_outbound
include => system_extensions 

exten => 8664561496,1,Answer
exten => 8664561496,2,Goto(start,s,3)

include => system_extensions
; If someone dials the Operator, just start them here.
exten => 0,1,Goto(s,1)

exten => s,1,Answer                     ; Answer the line
exten => s,2,Wait(1)                     ; Wait a second, just for fun
exten => s,3,SetMusicOnHold,default
exten => s,4,ResponseTimeout,15         ; Set Response Timeout

etc, etc, etc,

exten => _1NXXNXXXXXX,1,Dial,${OUTBOUND_TRUNK}/${EXTEN},tr
exten => _NXXXXXX,1,Dial,${OUTBOUND_TRUNK}/${EXTEN},tr

I have been busy with a lot of other things. Amongst which I just configured a Cisco 7960 with the * server, works perfectly except that I still need to configure it to be able to dial 4-digit extensions in the diaplan.xml, anyone has an idea? What I am planning to do is purchase a dual pentium 3 server or Pentium D dual core desktop, add 1 or 2 3com gigabit nics to it and setup the asterisk on it. All I basically have to do is transfer all my config files into the appropriate directories and get running in no time, I think the rate at which the current box (dell gx240, PIII @ about 600Mhz) is processing might be affecting the intake of digits amongst others. I noticed that when I ran AAH on a Compaq ML330 PIII server @ 1Ghz it went fine and the voice was clearer using x-lite on various laptops, even remotely. But running asterisk on the present Dell gx240 described above the performance does not match. So I am looking to get same compaq as above but with dual PIIIs and more resources like the gigabit nics and more disk space.

Thanks to everyone that contributed to this thread. I was able to isolate internal extensions, outbound trunks, and customer-call-in in their own respective contexts and used the include=> command which does the job just fine. My convergence lab is fully functional unless I further attempt new features which I just might.