System information

of the variable, and a closing curly brace (in the case of LEIF, we would reference the
value of the variable with ${LEIF}). Here’s how we might use a variable inside the
Dial() application:
exten => 301,1,Set(LEIF=SIP/0000FFFF0001)
same => n,Dial(${LEIF})
In our dialplan, whenever we refer to ${LEIF}, Asterisk will automatically replace it
with whatever value has been assigned to the variable named LEIF.
Note that variable names are case-sensitive. A variable named LEIF is
different than a variable named Leif. For readability’s sake, all our 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. Some
variables, such as CHANNEL and EXTEN, are reserved by Asterisk. You
should not attempt to set these variables. It is popular to write global
variables in uppercase and channel variables in Pascal/Camel case.
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 are visible to all channels at all times. 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 SIP/0000FFFF0001 channel. Now imagine you had to
go through your dialplan and change all of those references to SIP/0000FFFF0002. It
would be a long and error-prone process, to say the least.
On the other hand, if you had defined a global variable that contained the value SIP/
0000FFFF0001 at the beginning of your dialplan and then referenced that instead, you
would have to change only one line of code to affect all places in the dialplan where
that channel was used.
Global variables should be declared in the [globals] context at the beginning of the
extensions.conf file. As an example, we will create a global variable named LEIF with a
value of SIP/0000FFFF0001. This variable is set at the time Asterisk parses the dialplan:
[globals]
LEIF=SIP/0000FFFF0001
Channel variables
A channel variable is a variable that is associated only with a particular call. Unlike
global variables, channel variables are defined only for the duration of the current call
and are available only to the channels participating in that call.
Building an Interactive Dialplan | 123