<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2160/1/7/_/styles/combined.css?spaceKey=AST&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/Examples">Examples</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~mnicholson">Matthew Nicholson</a>
</h4>
<br/>
<h4>Changes (1)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-unchanged" >Some example {{extensions.lua}} files can be found below. They demonstrate various ways to organize extensions. <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> <br>h2. Less Clutter <br> <br>Instead of defining every extension inline, you can use this method to create a neater {{extensions.lua}} file. Since the extensions table and each context are both normal lua tables, you can treat them as such and build them piece by piece. <br> <br>{code:title=extensions.lua} <br>-- this function serves as an extension function directly <br>function call_user(c, user) <br> app.dial("SIP/" .. user, 60) <br>end <br> <br>-- this function returns an extension function <br>function call_sales_queue(queue) <br> return function(c, e) <br> app.queue(queue) <br> end <br>end <br> <br>e = {} <br> <br>e.default = {} <br>e.default.include = {"users", "sales"} <br> <br>e.users = {} <br>e.users["100"] = call_user <br>e.users["101"] = call_user <br> <br>e.sales = {} <br>e.sales["5000"] = call_sales_queue("sales1") <br>e.sales["6000"] = call_sales_queue("sales2") <br> <br>extensions = e <br>{code} <br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p>Some example <tt>extensions.lua</tt> files can be found below. They demonstrate various ways to organize extensions.</p>
<h2><a name="Examples-LessClutter"></a>Less Clutter</h2>
<p>Instead of defining every extension inline, you can use this method to create a neater <tt>extensions.lua</tt> file. Since the extensions table and each context are both normal lua tables, you can treat them as such and build them piece by piece.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>extensions.lua</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">-- this function serves as an extension function directly
function call_user(c, user)
app.dial("SIP/" .. user, 60)
end
-- this function returns an extension function
function call_sales_queue(queue)
return function(c, e)
app.queue(queue)
end
end
e = {}
e.default = {}
e.default.include = {"users", "sales"}
e.users = {}
e.users["100"] = call_user
e.users["101"] = call_user
e.sales = {}
e.sales["5000"] = call_sales_queue("sales1")
e.sales["6000"] = call_sales_queue("sales2")
extensions = e</pre>
</div></div>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/Examples">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=16548020&revisedVersion=2&originalVersion=1">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/Examples?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>