Page 170 - Asterisk™: The Future of Telephony
P. 170
strip off the 9 with the ${EXTEN:1} syntax, and then attempt to dial that number on the
channel signified by the variable OUTBOUNDTRUNK. If the call is successful, the caller is
bridged with the outbound channel. If the call is unsuccessful (because either the chan-
nel is busy or the number can’t be dialed for some reason), the Congestion() application
is called, which plays a “fast busy signal” (congestion tone) to let the caller know that
the call was unsuccessful.
Before we go any further, let’s make sure our dialplan allows outbound emergency
numbers:
[outbound-local]
exten => _9NXXXXXX,1,Dial(${OUTBOUNDTRUNK}/${EXTEN:1})
exten => _9NXXXXXX,n,Congestion()
exten => _9NXXXXXX,n,Hangup()
exten => 911,1,Dial(${OUTBOUNDTRUNK}/911)
exten => 9911,1,Dial(${OUTBOUNDTRUNK}/911) ; So that folks who dial “9”
; first will also get through
Again, we’re assuming for the sake of these examples that we’re inside the United States
or Canada. If you’re outside of this area, please replace 911 with the emergency services
number in your particular location. This is something you never want to forget to put
in your dialplan!
Next, let’s add a context for long-distance calls:
[outbound-long-distance]
exten => _91NXXNXXXXXX,1,Dial(${OUTBOUNDTRUNK}/${EXTEN:1})
exten => _91NXXNXXXXXX,n,Playtones(congestion)
exten => _91NXXNXXXXXX,n,Hangup()
Now that we have these two new contexts, how do we allow internal users to take
advantage of them? We need a way for contexts to be able to use the functionality
contained in other contexts.
Includes
Asterisk has a feature that enables us to use the extensions from one context within
another context via the include directive. This is used to control access to different
sections of the dialplan. We’ll use the include functionality to allow users in our
[employees] context the ability to make outbound phone calls. But first, let’s cover the
syntax.
The include statement takes the following form, where context is the name of the
remote context we want to include in the current context:
include => context
§ The advantage of this is that if one day we decide to send all of our calls through some other channel, we
have to edit the channel name assigned to the variable OUTBOUNDTRUNK only in the [globals] context, instead
of having to manually edit every reference to the channel in our dialplan.
142 | Chapter 5: Dialplan Basics