Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Below is a quick reference that can be used to translate traditional extensions.conf dialplan concepts to their analog in extensions.lua.

Table of Contents
excludeextensions.conf|extensions.lua

Extension Patterns

Extension pattern matching syntax on logic works the same for extensions.conf and extensions.lua.

Section
Column
width50%
Panel

extensions.conf

Code Block
[users]
exten => _1XX,1,Dial(SIP/${EXTEN})

exten => _2XX,1,Voicemail(${EXTEN:1})
Column
width50%
Panel

extensions.lua

Code Block
extensions = {}
extensions.users = {}

extensions.users["_1XX"] = function(c, e)
   app.dial("SIP/" .. e)
end

extensions.users["_2XX"] = function(c, e)
  app.voicemail("1" .. e:sub(2))
end

Context Includes

Section
Column
width50%
Panel

extensions.conf

Code Block
[users]
exten => 100,1,Noop
exten => 100,n,Dial("SIP/100")

[demo]
exten => s,1,Noop
exten => s,n,Playback(demo-congrats)

[default]
include => demo
include => users

Column
width50%
Panel

extensions.lua

Code Block
extensions = {
   users = {
      [100] = function()
         app.dial("SIP/100")
      end;
   };

   demo = {
      ["s"] = function()
         app.playback(demo-congrats)
      end;
   };
      
   default = {
      include = {"demo", "users"};
   };
}

Loops

Section
Column
width50%
Panel

extensions.conf

Code Block
exten => 100,1,Noop
exten => 100,n,Set(i=0)
exten => 100,n,While($[i < 10])
exten => 100,n,Verbose(i = ${i})
exten => 100,n,EndWhile
Column
width50%
Panel

extensions.lua

Code Block
i = 0
while i < 10 do
  app.verbose("i = " .. i)
end

Variables

Section
Column
width50%
Panel

extensions.conf

Code Block
exten => 100,1,Set(my_variable=my_value)
exten => 100,n,Verbose(my_variable = ${my_variable})
Column
width50%
Panel

extensions.lua

Code Block
channel.my_variable = "my_value"
app.verbose("my_variable = " .. channel.my_variable:get())

Applications

Section
Column
width50%
Panel

extensions.conf

Code Block
exten => 100,1,Dial("SIP/100",,m)
Column
width50%
Panel

extensions.lua

Code Block
app.dial("SIP/100", nil, "m")

Macros/GoSub

Macros can be defined in pbx_lua by naming a context 'macro-*' just as in extensions.conf, but generally where you would use macros or gosub in extensions.conf you would simply use a function in lua.

Section
Column
width50%
Panel

extensions.conf

Code Block
[macro-dial]
exten => s,1,Noop
exten => s,n,Dial(${ARG1})

[default]
exten => 100,1,Macro(dial,SIP/100)
Column
width50%
Panel

extensions.lua

Code Block
extensions = {}
extensions.default = {}

function dial(resource)
   app.dial(resource)
end

extensions.default[100] = function()
   dial("SIP/100")
end

Goto

While Goto is an extenstions.conf staple, it should generally be avoided in pbx_lua in favor of functions.

Section
Column
width50%
Panel

extensions.conf

Code Block
[default]
exten => 100,1,Goto(102,1)

exten => 102,1,Playback("demo-thanks")
exten => 102,n,Hangup
Column
width50%
Panel

extensions.lua

Code Block
extensions = {}
extensions.default = {}

function do_hangup()
   app.playback("demo-thanks")
   app.hangup()
end

extensions.default[100] = function()
   do_hangup()
end

Info

The app.goto() function will not work as expected in pbx_lua in Asterisk 1.8. If you must use app.goto() you must manually return control back to asterisk using return from the dialplan extension function, otherwise execution will continue after the call to app.goto(). Calls to app.goto() should work as expected in Asterisk 10 but still should not be necessary in most cases.

Code Block
titleIn Asterisk 1.8, use return
function extension_function(c, e)
   return app.goto("default", "100", 1)

   -- without that 'return' the rest of the function would execute normally
   app.verbose("Did you forget to use 'return'?")
end