text
stringlengths
0
152
Asterisk also comes with a detailed extensions.conf file that can be installed with the
sample configuration files (the installation command make samples will do this), and
if you ran that command (which we don’t recommend during the install, but is sug‐
gested by the installer), you will most likely have an /etc/asterisk/extensions.conf file
that is chock-full of information. Instead of starting with the sample file, we suggest
that you build your extensions.conf file from scratch with a blank file (you can rename
it or move it somewhere if you wish to keep it as a reference).
That being said, the extensions.conf.sample file is a fantastic resource, full of examples
and ideas that you can use after you’ve learned the basic concepts. If you followed our
installation instructions, you will find the file extensions.conf.sample in the folder
~/src/asterisk-15.<TAB>/configs/samples (along with many other sample config files).
Contexts
Dialplans are divided into sections called contexts, which serve to separate different
parts of the dialplan. An extension that is defined in one context is completely iso‐
lated from extensions in any other context, unless interaction is specifically allowed.
As a simple example, let’s imagine we have two companies sharing an Asterisk server.
If we place each company’s automated attendant (IVR) in its own context, the two
companies will be completely separated from each other. This allows us to independ‐
ently define what happens when, say, extension 0 is dialed:
78
|
Chapter 6: Dialplan Basics
• Callers dialing 0 from Company A’s voice menu need to be transferred to Com‐
pany A’s receptionist.
• Callers dialing 0 at Company B’s voice menu will be sent to Company B’s cus‐
tomer service department.
Both callers are on the same system, interacting with the same dialplan, but because
they arrived in different contexts, they experience totally separate call flow. What
happens to each incoming call is determined by the dialplan code in each context.
This is a very important consideration. With traditional PBXs,
there is generally a set of defaults for things like reception, which
means that if you forget to define them, they will probably work
anyway. In Asterisk, the opposite is true. If you do not tell Asterisk
how to handle every situation, and it comes across something it
cannot handle, the call will typically be disconnected.
Contexts are defined in the extensions.conf file by placing the name of the context
inside square brackets ([]). The name can be made up of the letters A through Z
(upper- and lowercase), the numbers 0 through 9, and the hyphen and underscore.1 A
context for incoming calls from a carrier might simply be named this:
[incoming]
Context names have a maximum length of 79 characters (80 char‐
acters minus 1 terminating null).
Or perhaps:
[incoming_company_A]
Which then of course might require something like:
[incoming_company_B]
All of the instructions placed after a context definition are part of that context, until
the next context is defined.
At the beginning of the dialplan, there are two special sections named [general] and
[globals]. The [general] section contains a list of general dialplan settings (which
you’ll probably never have to worry about), and we will discuss the [globals]
1 Please note that the space is conspicuously absent from the list of allowed characters. Don’t use spaces in your
context names—you won’t like the result!
Dialplan Syntax
|
79
context shortly. For now, it’s only important to know that these two labels are not
contexts, despite using context syntax. Do not use [general], [globals], and
[default]2 as context names, but otherwise name your contexts anything you wish.
The contexts in a typical extensions.conf file might be structured something like this:
[general] ; This always has to be here
[globals] ; Global variables (we'll discuss these later)
[incoming] ; Calls from the carriers could arrive here
[sets] ; on a simple system, we can use this
[sets1] ; Multi-tenanted perhaps needs this (sets from one company enter dialplan here)
[sets2] ; ... and this (another group of sets might enter the dialplan here)