<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2160/3/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/Lua+Dialplan+Examples">Lua Dialplan 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 (0)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<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="LuaDialplanExamples-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>
<h2><a name="LuaDialplanExamples-LessClutterv2"></a>Less Clutter v2</h2>
<p>In this example, we use a fancy function to register extensions.</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">function register(context, extension, func)
if not extensions then
extensions = {}
end
if not extensions[context] then
extensions[context] = {}
end
extensions[context][extension] = func
end
function include(context, included_context)
if not extensions then
extensions = {}
end
if not extensions[context] then
extensions[context] = {}
end
if not extensions[context].include then
extensions[context].include = {}
end
table.insert(extensions[context].include, included_context)
end
-- 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
include("default", "users")
include("default", "sales")
register("users", "100", call_user)
register("users", "101", call_user)
register("sales", "5000", call_sales_queue("sales1"))
register("sales", "6000", call_sales_queue("sales2"))
register("sales", "7000", function()
app.queue("sales3")
end)</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/Lua+Dialplan+Examples">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=16548020&revisedVersion=4&originalVersion=3">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/Lua+Dialplan+Examples?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>