Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

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

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

...

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())

...

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")

...

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

...

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()

   -- we could have just set extensions.default[100] = do_hangup
end

...