Page 151 - Asterisk™: The Future of Telephony
P. 151

Don’t worry if you don’t understand what Answer() and Hangup() are—we’ll cover
               them shortly. The key point to remember here is that for a particular extension, Asterisk
               follows the priorities in order.

               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
               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.  You should note, however, that you must always specify priority number 1. If you
               accidentally put an n instead of 1 for the first priority, you’ll find that the extension will
               not be available.

               Priority labels
               Starting with Asterisk version 1.2 and higher, common practice is to assign text labels
               to priorities. This is to ensure that you can refer to a priority by something other than
               its number, which probably isn’t known, given that dialplans now generally use un-
               numbered priorities. To assign a text label to a priority, simply add the label inside
               parentheses after the priority, like this:

                   exten => 123,n(label),application()
                           A very common mistake when writing labels is to insert a comma be-
                           tween the n and the (, like this:
                              exten => 123,n,(label),application() ;<-- THIS IS NOT GOING TO WORK
                           This mistake will break that part of your dialplan, and you will get an
                           error that the application cannot be found.


               † Asterisk permits simple arithmetic within the priority, such as n+200 or the priority s (for same), but their
                 usage is considered to be an advanced topic. Please note that extension s and priority s are two distinct
                 concepts.

                                                                         Dialplan Syntax | 123
   146   147   148   149   150   151   152   153   154   155   156