Page 163 - Asterisk™: The Future of Telephony
P. 163
that it is possible to have different extensions in the dialplan ring the same endpoint.
For example, you could have extension 200 ring SIP/George, and then have extension
201 play a prompt of some kind and then ring SIP/George.
Now that our internal callers can call each other, we’re well on our way toward having
a complete dialplan. Next, we’ll see how we can make our dialplan more scalable and
easier to modify in the future.
Using Variables
Variables can be used in an Asterisk dialplan to help reduce typing, add clarity, or add
additional logic to a dialplan. If you have some computer programming experience,
you probably already understand what a variable is. If not, don’t worry; we’ll explain
what variables are and how they are used.
You can think of a variable as a container that can hold one value at a time. So, for
example, we might create a variable called JOHN and assign it the value of Zap/1. This
way, when we’re writing our dialplan, we can refer to John’s channel by name, instead
of remembering that John is using the channel named Zap/1.
There are two ways to reference a variable. To reference the variable’s name, simply
type the name of the variable, such as JOHN. If, on the other hand, you want to reference
its value, you must type a dollar sign, an opening curly brace, the name of the variable,
and a closing curly brace. Here’s how we’d reference the variable inside the Dial()
application:
exten => 555,1,Dial(${JOHN})
In our dialplan, whenever we write ${JOHN}, Asterisk will automatically replace it with
whatever value has been assigned to the variable named JOHN.
Note that variable names are case-sensitive. A variable named JOHN is
different than a variable named John. For readability’s sake, all the var-
iable names in the examples will be written in uppercase. You should
also be aware that any variables set by Asterisk will be uppercase as well.
Some variables, such as CHANNEL or EXTEN are reserved by Asterisk. You
should not attempt to set these variables.
There are three types of variables we can use in our dialplan: global variables, channel
variables, and environment variables. Let’s take a moment to look at each type.
Global variables
As their name implies, global variables apply to all extensions in all contexts. Global
variables are useful in that they can be used anywhere within a dialplan to increase
readability and manageability. Suppose for a moment that you had a large dialplan and
several hundred references to the Zap/1 channel. Now imagine you had to go through
Building an Interactive Dialplan | 135