text
stringlengths
0
152
use AGI and ARI to write their dialplan.
While there’s certainly something to be said for writing dialplan in an external lan‐
guage (and we’ll cover it in later chapters), the Asterisk dialplan is native to it, and
you will not get better performance than this. Dialplan code executes fast.
Also, if you want to understand how Asterisk thinks, you need to understand its
dialplan.
Priority labels
Priority labels allow you to assign a name to a priority within an extension. This is to
ensure that you can refer to a priority by something other than its number (which
probably isn’t known, given that dialplans now generally use unnumbered priorities).
Later you will learn that it’s often necessary to send calls from other parts of the dia‐
lplan to a particular priority in a particular extension. To assign a text label to a prior‐
ity, simply add the label inside parentheses after the priority, like this:
exten => 123,n(label),application()
Later, we’ll cover how to jump between different priorities based on dialplan logic.
You’ll see a lot more of priority labels, and you’ll use them often in your dialplans.
A very common mistake when writing labels is to insert a comma
between the n and the (, like this:
exten => 555,n,(label),application() ;<-- THIS WON'T WORK
exten => 556,n(label),application() :<-- This is what we want
This mistake will break that part of your dialplan, and you will get
an error stating that the application cannot be found.
Applications
Applications are the workhorses of the dialplan. Each application performs a specific
action on the current channel, such as playing a sound, accepting touch-tone input,
84
|
Chapter 6: Dialplan Basics
looking something up in a database, dialing a channel, hanging up the call, feeding
the cat, and so forth.4 In the previous example, you were introduced to two simple
applications: Answer() and Hangup(). It’s obvious what they do, but it’s also obvious
that on their own they aren’t terribly useful.
Some applications, including Answer() and Hangup(), need no other instructions to
do their jobs. Most applications, however, require more information. These addi‐
tional elements, or arguments, are passed on to the applications to affect how they
perform their actions. To pass arguments to an application, place them between the
parentheses that follow the application name, separated by commas.
The Answer(), Playback(), and Hangup() Applications
The Answer() application is used to answer a channel that is ringing. It seems a sim‐
ple thing, but a lot of things happen on the channel with this one command.
Answer() tells the channel to send a message back to the far end that the call has been
answered, and also to enable the media paths (the network streams that will carry the
sound between the caller and the system). As we mentioned earlier, Answer() takes
no arguments. Answer() is not always required (in fact, in some cases it may not be
desirable at all), but it is an effective way to ensure a channel is connected before per‐
forming further actions.
The Progress() Application
Sometimes it is useful to be able to pass information back to the network before
answering a call. The Progress() application attempts to provide call progress infor‐
mation to the originating channel. Some carriers expect this, and thus you may be
able to resolve strange signaling problems by inserting Progress() into the dialplan
where your incoming calls arrive. In terms of billing, the use of Progress() lets the
carrier know you’re handling the call, without starting the billing meter.
The Playback() application is used for playing a previously recorded sound file over
a channel. Input from the user is ignored, which means that you would not use Play
back() in an auto attendant, for example, unless you did not want to accept input at
that point.5
4 OK, so feeding the cat isn’t a common use for a telephone system, but through Asterisk, such things are not
impossible. Doc Brown would’ve loved this thing.
5 There is another application called Background() that is very similar to Playback(), except that it does allow
input from the caller. You can read more about this application in Chapters 14 and 16.
Dialplan Syntax
|
85
Asterisk comes with many professionally recorded sound files,
which should be found in the default sounds directory (usu‐
ally /var/lib/asterisk/sounds). When you compile Asterisk, you can
choose to install various sets of sample sounds that have been
recorded in a variety of languages and file formats. We’ll be using
these files in many of our examples. Several of the files in our
examples come from the Extra Sound Package, which we installed
in Chapter 3. You can also have your own sound prompts recorded
in the same voices as the stock prompts by visiting www.theivr‐
voice.com. Later in the book, we’ll talk more about how you can