text stringlengths 0 152 |
|---|
also be aware that any variables set by Asterisk will be uppercase. |
Some variables, such as CHANNEL and EXTEN, are reserved by Aster‐ |
isk. You should not attempt to set these variables. It is popular to |
write global variables in uppercase and channel variables in Pascal/ |
Camel case, but it is not strictly required. |
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 PJSIP/0000f30A0A01 channel. Now imagine |
you replaced the phone with a different unit (perhaps a different MAC address), and |
had to go through your dialplan and change all of those references to PJSIP/ |
0000f30A0A01. Not pretty. |
On the other hand, if you had defined a global variable that contained the value |
PJSIP/0000f30A0A01 at the beginning of your dialplan and then referenced that |
16 Specifically, what we are setting here is a channel variable. |
Building an Interactive Dialplan |
| |
97 |
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 few global variables that store the |
channel identifiers of our devices. These variables are set at the time Asterisk parses |
the dialplan: |
[globals] |
UserA_DeskPhone=PJSIP/0000f30A0A01 |
UserA_SoftPhone=PJSIP/SOFTPHONE_A |
UserB_DeskPhone=PJSIP/0000f30B0B02 |
UserB_SoftPhone=PJSIP/SOFTPHONE_B |
We’ll come back to these later. |
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. |
There are many predefined channel variables available for use within the dialplan, |
which are explained in the Asterisk wiki. You define a channel variable with exten‐ |
sion 203 and the Set() application: |
exten => 203,1,Noop(say some digits) |
same => n,Set(SomeDigits=123) |
same => n,SayDigits(${SomeDigits}) |
same => n,Wait(.25) |
same => n,Set(SomeDigits=543) |
same => n,SayDigits(${SomeDigits}) |
You’re going to be seeing a lot more channel variables. Read on. |
Environment variables |
Environment variables are a way of accessing Unix environment variables from within |
Asterisk. These are referenced using the ENV() dialplan function.17 The syntax looks |
like ${ENV(var)}, where var is the Unix environment variable you wish to reference. |
Environment variables aren’t commonly used in Asterisk dialplans, but they are avail‐ |
able should you need them. |
17 We’ll get into dialplan functions later. Don’t worry too much about environment variables right now. They are |
not important to understanding the dialplan. |
98 |
| |
Chapter 6: Dialplan Basics |
Adding variables to our dialplan |
Now that we’ve learned about variables, let’s put them to work in our dialplan. We’re |
going to add three global variables that will associate a variable name to a channel |
name: |
[general] |
[globals] |
UserA_DeskPhone=PJSIP/0000f30A0A01 |
UserA_SoftPhone=PJSIP/SOFTPHONE_A |
UserB_DeskPhone=PJSIP/0000f30B0B02 |
UserB_SoftPhone=PJSIP/SOFTPHONE_B |
[sets] |
exten => 100,1,Dial(${UserA_DeskPhone}) |
exten => 101,1,Dial(${UserA_SoftPhone}) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.