<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/2041/1/7/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities">Contexts, Extensions, and Priorities</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://wiki.asterisk.org/wiki/display/~lmadsen">Leif Madsen</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Make dialplan pretty.<br />
    </div>
        <br/>
                         <h4>Changes (12)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code:lang=javascript}[users]{code} <br>Within each context, we can define one or more *extensions*. As explained in the previous module, an extension is simply a named set of actions. Asterisk will perform each action, in sequence, when that extension number is dialed. The syntax for an extension is: <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:lang=javascript}exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>number,priority,application([parameter[,parameter2...]])</span> <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br>As an example, let&#39;s review extension *6001* from the previous module. It looks like: <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{code:lang=javascript}exten=&gt;6001,1,Dial(SIP/demo-alice,20) <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{code:lang=javascript}exten =&gt; 6001,1,Dial(SIP/demo-alice,20) <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br>In this case, the extension number is *6001*, the priority number is *1*, the application is *Dial()*, and the two parameters to the application are *SIP/demo-alice* and *20*. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Priority numbers <br>Priority numbers must begin with 1, and must increment sequentially. If Asterisk can&#39;t find the next priority number, it will terminate the call. We call this _auto-fallthrough_. Consider the example below: <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:lang=javascript}exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,1,do</span> something <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,2,do</span> something else <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,4,do</span> something different <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br>In this case, Asterisk would execute priorites one and two, but would then terminate the call, because it couldn&#39;t find priority number three. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Priority number can also be simplied by using the letter *n* in place of the priority numbers greater than one. The letter *n* stands for *next*, and when Asterisk sees priority n it replaces it in memory with the previous priority number plus one. Note that you must still explicitly declare priority number one. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:lang=javascript}exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,1,do</span> something <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,n,do</span> something else <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,n,do</span> something different{code} <br></td></tr>
            <tr><td class="diff-unchanged" >You can also assign a label (or alias) to a particular priority number by placing the label in parentheses directly after the priority number, as shown below. Labels make it easier to jump back to a particular location within the extension at a later time. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{code:lang=javascript}exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,1,do</span> something <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,n(repeat),do</span> something else <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">exten<span class="diff-added-chars"style="background-color: #dfd;"> </span>=&gt;<span class="diff-added-chars"style="background-color: #dfd;"> </span>6123,n,do</span> something different{code} <br></td></tr>
            <tr><td class="diff-unchanged" >Here, we&#39;ve assigned a label named *repeat* to the second priority. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The dialplan is organized into various sections, called contexts. Contexts are the basic organizational unit within the dialplan, and as such, they keep different sections of the dialplan independent from each other. We'll use contexts to enforce security boundaries between the various parts of our dialplan, as well as to provide different classes of service to groups of users.</p>

<p>The syntax for a context is exactly the same as any other section heading in the configuration files, as explained in <a href="/wiki/display/AST/Sections+and+Settings" title="Sections and Settings">Section 206.2.1. Sections and Settings</a>. Simply place the context name in square brackets. For example, here is the context we defined in the previous module:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: javascript; gutter: false"><![CDATA[[users]]]></script>
</div></div>
<p>Within each context, we can define one or more <b>extensions</b>. As explained in the previous module, an extension is simply a named set of actions. Asterisk will perform each action, in sequence, when that extension number is dialed. The syntax for an extension is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: javascript; gutter: false"><![CDATA[exten =&gt; number,priority,application([parameter[,parameter2...]])
]]></script>
</div></div>
<p>As an example, let's review extension <b>6001</b> from the previous module. It looks like:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: javascript; gutter: false"><![CDATA[exten =&gt; 6001,1,Dial(SIP/demo-alice,20)
]]></script>
</div></div>
<p>In this case, the extension number is <b>6001</b>, the priority number is <b>1</b>, the application is <b>Dial()</b>, and the two parameters to the application are <b>SIP/demo-alice</b> and <b>20</b>.<br/>
Within each extension, there must be one or more <em>priorities</em>. A priority is simply a sequence number. The first priority on an extension is executed first. When it finishes, the second priority is executed, and so forth.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Priority numbers<br/>
Priority numbers must begin with 1, and must increment sequentially. If Asterisk can't find the next priority number, it will terminate the call. We call this <em>auto-fallthrough</em>. Consider the example below:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: javascript; gutter: false"><![CDATA[exten =&gt; 6123,1,do something
exten =&gt; 6123,2,do something else
exten =&gt; 6123,4,do something different
]]></script>
</div></div>
<p>In this case, Asterisk would execute priorites one and two, but would then terminate the call, because it couldn't find priority number three.</p></td></tr></table></div>

<p>Priority number can also be simplied by using the letter <b>n</b> in place of the priority numbers greater than one. The letter <b>n</b> stands for <b>next</b>, and when Asterisk sees priority n it replaces it in memory with the previous priority number plus one. Note that you must still explicitly declare priority number one.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: javascript; gutter: false"><![CDATA[exten =&gt; 6123,1,do something
exten =&gt; 6123,n,do something else
exten =&gt; 6123,n,do something different]]></script>
</div></div>
<p>You can also assign a label (or alias) to a particular priority number by placing the label in parentheses directly after the priority number, as shown below. Labels make it easier to jump back to a particular location within the extension at a later time.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: javascript; gutter: false"><![CDATA[exten =&gt; 6123,1,do something
exten =&gt; 6123,n(repeat),do something else
exten =&gt; 6123,n,do something different]]></script>
</div></div>
<p>Here, we've assigned a label named <b>repeat</b> to the second priority.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities">View Online</a>
        |
        <a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=4817410&revisedVersion=7&originalVersion=6">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>