Priorities

An extension can have multiple steps (priorities) which are executed in order. Each priority will execute a specific application. For example, consider the following dialplan:

exten => 100,1,Playback(tt-weasels)
exten => 100,2,Voicemail(10)
exten => 100,3,Hangup()

The priority is defined after the extension. In the example above we have defined the extension 100. When a call is made to that extension, Asterisk will play a sound file called tt-weasels, give the user an opportunity to leave a voicemail message for the mailbox 10, and then hangup the call.

Note that Asterisk doesn’t care about the order in which you write the lines in extensions.conf. Instead, Asterisk uses the priority of each line to determine order of execution. In our example, the lines in this order would produce the same result:

exten => 100,3,Hangup()
exten => 100,1,Playback(tt-weasels)
exten => 100,2,Voicemail(10)

The n priority
Starting with Asterisk 1.2, instead of having to manually number priorities within a given extension, it is possible to use n to represent the next priority. The n value automatically increases a priority’s value by 1, which makes changing the dialplan easier. In our case, the dialplan could look like this:

exten => 100,1,Playback(tt-weasels)
exten => 100,n,Voicemail(10)
exten => 100,n,Hangup()
You must always specify the first priority for an extension.

 

The same => operator
Another way in which you can simplify your dialplan is to use the same => operator. This operator enables you to avoid writing the extension on each line, as long the extension remains the same. In our case, the dialplan could be written like this:

exten => 100,1,Playback(tt-weasels)
 same => n,Voicemail(10)
 same => n,Hangup()

 

 

 

Geek University 2022