text stringlengths 0 152 |
|---|
Here’s a simple example: |
exten => 123,1,Answer() |
The extension name is 123, the priority is 1, and the application is Answer(). |
Priorities |
Each extension can have multiple steps, called priorities. The priorities are numbered |
sequentially, starting with 1, and each executes one specific application. As an exam‐ |
ple, the following extension would answer the phone in priority number 1, and then |
hang it up in priority number 2. The steps in an extension take place one after the |
other. |
exten => 123,1,Answer() |
exten => 123,2,Hangup() |
It’s pretty obvious that this code doesn’t really do anything useful. We’ll get there. The |
key point to note here is that for a particular extension, Asterisk follows the priorities |
in order. |
exten => 123,1,Answer() |
exten => 123,2,do something |
exten => 123,3,do something else |
exten => 123,4,do one last thing |
exten => 123,5,Hangup() |
This style of dialplan syntax is still seen from time to time, although (as you’ll see |
momentarily) it is not generally used anymore for new code. Newer syntax is similar, |
but simplified. |
82 |
| |
Chapter 6: Dialplan Basics |
Unnumbered priorities |
In older releases of Asterisk, the numbering of priorities caused a lot of problems. |
Imagine having an extension that had 15 priorities, and then needing to add some‐ |
thing at step 2: all of the subsequent priorities would have to be manually renum‐ |
bered. Asterisk does not handle missing steps or misnumbered priorities, and |
debugging these types of errors was frustrating. |
Beginning with version 1.2, Asterisk addressed this problem: it introduced the use of |
the n priority, which stands for “next.” Each time Asterisk encounters a priority |
named n, it takes the number of the previous priority and adds 1. This makes it easier |
to make changes to your dialplan, as you don’t have to keep renumbering all your |
steps. For example, your dialplan might look something like this: |
exten => 123,1,Answer() |
exten => 123,n,do something |
exten => 123,n,do something else |
exten => 123,n,do one last thing |
exten => 123,n,Hangup() |
Internally, Asterisk will calculate the next priority number every time it encounters an |
n.3 Now, if we want to add a new item at priority 3, we just input the new line where |
we need it, and no renumbering is required. |
exten => 123,1,Answer() |
exten => 123,n,do something |
exten => 123,n,SOME NEW THING |
exten => 123,n,do something else |
exten => 123,n,do one last thing |
exten => 123,n,Hangup() |
Bear in mind that you must always specify priority number 1. If you accidentally put |
an n instead of 1 for the first priority (a common mistake even among experienced |
dialplan coders), you’ll find after reloading the dialplan that the extension will not |
exist. |
The same => operator |
In order to further simplify dialplan writing, a new syntax was created. As long as the |
extension remains the same, you can simply type same => followed by the priority |
and application rather than having to type the full extension on each line: |
3 Asterisk permits simple arithmetic within the priority, such as n+200, and the priority s (for same), but their |
usage is somewhat deprecated due to the existence of priority labels. Please note that extension s and priority s |
are two distinct concepts. |
Dialplan Syntax |
| |
83 |
exten => 123,1,Answer() |
same => n,do something |
same => n,do something |
same => n,do one last thing |
same => n,Hangup() |
This style of dialplan will also make it easier to copy code from one extension to |
another. This is the preferred and recommended style. The only reason for the dis‐ |
cussion of previous styles is to help understand how we got here. |
Make no mistake, the Asterisk dialplan is peculiar. Many folks avoid it altogether, and |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.