System information
Each step in an extension is composed of three components:
• The name (or number) of the extension
• The priority (each extension can include multiple steps; the step number is called
the “priority”)
• The application (or command) that will take place at that step
These three components are separated by commas, like this:
exten => name,priority,application()
Here’s a simple example of what a real extension might look like:
exten => 123,1,Answer()
In this example, 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 example,
the following extension would answer the phone (in priority number 1), and then hang
it up (in priority number 2):
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. 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:
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()
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 something
at step 2: all of the subsequent priorities would have to be manually renumbered.
Asterisk does not handle missing steps or misnumbered priorities, and debugging these
types of errors was pointless and 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
Dialplan Syntax | 111