| 1 |
|
| 2 |
|
| 3 |
CONSOLE = "Console/dsp" -- Console interface for demo |
| 4 |
--CONSOLE = "DAHDI/1" |
| 5 |
--CONSOLE = "Phone/phone0" |
| 6 |
|
| 7 |
TRUNK = "DAHDI/G2" |
| 8 |
TRUNKMSD = 1 |
| 9 |
-- TRUNK = "IAX2/user:pass@provider" |
| 10 |
|
| 11 |
|
| 12 |
-- |
| 13 |
-- Extensions are expected to be defined in a global table named 'extensions'. |
| 14 |
-- The 'extensions' table should have a group of tables in it, each |
| 15 |
-- representing a context. Extensions are defined in each context. See below |
| 16 |
-- for examples. |
| 17 |
-- |
| 18 |
-- Extension names may be numbers, letters, or combinations thereof. If |
| 19 |
-- an extension name is prefixed by a '_' character, it is interpreted as |
| 20 |
-- a pattern rather than a literal. In patterns, some characters have |
| 21 |
-- special meanings: |
| 22 |
-- |
| 23 |
-- X - any digit from 0-9 |
| 24 |
-- Z - any digit from 1-9 |
| 25 |
-- N - any digit from 2-9 |
| 26 |
-- [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9) |
| 27 |
-- . - wildcard, matches anything remaining (e.g. _9011. matches |
| 28 |
-- anything starting with 9011 excluding 9011 itself) |
| 29 |
-- ! - wildcard, causes the matching process to complete as soon as |
| 30 |
-- it can unambiguously determine that no other matches are possible |
| 31 |
-- |
| 32 |
-- For example the extension _NXXXXXX would match normal 7 digit |
| 33 |
-- dialings, while _1NXXNXXXXXX would represent an area code plus phone |
| 34 |
-- number preceded by a one. |
| 35 |
-- |
| 36 |
-- If your extension has special characters in it such as '.' and '!' you must |
| 37 |
-- explicitly make it a string in the tabale definition: |
| 38 |
-- |
| 39 |
-- ["_special."] = function; |
| 40 |
-- ["_special!"] = function; |
| 41 |
-- |
| 42 |
-- There are no priorities. All extensions to asterisk appear to have a single |
| 43 |
-- priority as if they consist of a single priority. |
| 44 |
-- |
| 45 |
-- Each context is defined as a table in the extensions table. The |
| 46 |
-- context names should be strings. |
| 47 |
-- |
| 48 |
-- One context may be included in another context using the 'includes' |
| 49 |
-- extension. This extension should be set to a table containing a list |
| 50 |
-- of context names. Do not put references to tables in the includes |
| 51 |
-- table. |
| 52 |
-- |
| 53 |
-- include = {"a", "b", "c"}; |
| 54 |
-- |
| 55 |
-- Channel variables can be accessed through the global 'channel' table. |
| 56 |
-- |
| 57 |
-- v = channel.var_name |
| 58 |
-- v = channel["var_name"] |
| 59 |
-- v.value |
| 60 |
-- v:get() |
| 61 |
-- |
| 62 |
-- channel.var_name = "value" |
| 63 |
-- channel["var_name"] = "value" |
| 64 |
-- v:set("value") |
| 65 |
-- |
| 66 |
-- channel.func_name(1,2,3):set("value") |
| 67 |
-- value = channel.func_name(1,2,3):get() |
| 68 |
-- |
| 69 |
-- channel["func_name(1,2,3)"]:set("value") |
| 70 |
-- channel["func_name(1,2,3)"] = "value" |
| 71 |
-- value = channel["func_name(1,2,3)"]:get() |
| 72 |
-- |
| 73 |
-- Note the use of the ':' operator to access the get() and set() |
| 74 |
-- methods. |
| 75 |
-- |
| 76 |
-- Also notice the absence of the following constructs from the examples above: |
| 77 |
-- channel.func_name(1,2,3) = "value" -- this will NOT work |
| 78 |
-- value = channel.func_name(1,2,3) -- this will NOT work as expected |
| 79 |
-- |
| 80 |
-- |
| 81 |
-- Dialplan applications can be accessed through the global 'app' table. |
| 82 |
-- |
| 83 |
-- app.Dial("DAHDI/1") |
| 84 |
-- app.dial("DAHDI/1") |
| 85 |
-- app["dial"]("DAHDI/1") |
| 86 |
-- |
| 87 |
-- More examples can be found below. |
| 88 |
-- |
| 89 |
-- An autoservice is automatically run while lua code is executing. The |
| 90 |
-- autoservice can be stopped and restarted using the autoservice_stop() and |
| 91 |
-- autoservice_start() functions. The autservice should be running before |
| 92 |
-- starting long running operations. The autoservice will automatically be |
| 93 |
-- stopped before executing applications and dialplan functions and will be |
| 94 |
-- restarted afterwards. The autoservice_status() function can be used to |
| 95 |
-- check the current status of the autoservice and will return true if an |
| 96 |
-- autoservice is currently running. |
| 97 |
-- |
| 98 |
-- Note about naming conflicts: |
| 99 |
-- Lua allows you to refer to table entries using the '.' notation, |
| 100 |
-- I.E. app.goto(something), only if the entry doesn't conflict with an Lua |
| 101 |
-- reserved word. In the 'goto' example, with Lua 5.1 or earlier, 'goto' is |
| 102 |
-- not a reserved word so you'd be calling the Asterisk dialplan application |
| 103 |
-- 'goto'. Lua 5.2 however, introduced the 'goto' control statement which |
| 104 |
-- makes 'goto' a reserved word. This causes the interpreter to fail parsing |
| 105 |
-- the file and pbx_lua.so will fail to load. The same applies to any use of |
| 106 |
-- Lua tables including extensions, channels and any tables you create. |
| 107 |
-- |
| 108 |
-- There are two ways around this: Since Lua is case-sensitive, you can use |
| 109 |
-- capitalized names, I.E. app.Goto(something) to refer to the Asterisk apps, |
| 110 |
-- functions, etc. Or you can use the full syntax, I.E. app["goto"](something). |
| 111 |
-- Both syntaxes are backwards compatible with earlier Lua versions. To make |
| 112 |
-- your Lua dialplans easier to maintain and to reduce the chance of future |
| 113 |
-- conflicts you may want to use the app["goto"](something) syntax for all |
| 114 |
-- table accesses. |
| 115 |
-- |
| 116 |
|
| 117 |
function outgoing_local(c, e) |
| 118 |
app.dial("DAHDI/1/" .. e, "", "") |
| 119 |
end |
| 120 |
|
| 121 |
function demo_instruct() |
| 122 |
app.background("demo-instruct") |
| 123 |
app.waitexten() |
| 124 |
end |
| 125 |
|
| 126 |
function demo_congrats() |
| 127 |
app.background("demo-congrats") |
| 128 |
demo_instruct() |
| 129 |
end |
| 130 |
|
| 131 |
-- Answer the chanel and play the demo sound files |
| 132 |
function demo_start(context, exten) |
| 133 |
app.wait(1) |
| 134 |
app.answer() |
| 135 |
|
| 136 |
channel.TIMEOUT("digit"):set(5) |
| 137 |
channel.TIMEOUT("response"):set(10) |
| 138 |
-- app.set("TIMEOUT(digit)=5") |
| 139 |
-- app.set("TIMEOUT(response)=10") |
| 140 |
|
| 141 |
demo_congrats(context, exten) |
| 142 |
end |
| 143 |
|
| 144 |
function demo_hangup() |
| 145 |
app.playback("demo-thanks") |
| 146 |
app.hangup() |
| 147 |
end |
| 148 |
|
| 149 |
extensions = { |
| 150 |
demo = { |
| 151 |
s = demo_start; |
| 152 |
|
| 153 |
["2"] = function() |
| 154 |
app.background("demo-moreinfo") |
| 155 |
demo_instruct() |
| 156 |
end; |
| 157 |
["3"] = function () |
| 158 |
channel.LANGUAGE():set("fr") -- set the language to french |
| 159 |
demo_congrats() |
| 160 |
end; |
| 161 |
|
| 162 |
["1000"] = function() |
| 163 |
-- See the naming conflict note above. |
| 164 |
app['goto']("default", "s", 1) |
| 165 |
end; |
| 166 |
|
| 167 |
["1234"] = function() |
| 168 |
app.playback("transfer", "skip") |
| 169 |
-- do a dial here |
| 170 |
end; |
| 171 |
|
| 172 |
["1235"] = function() |
| 173 |
app.voicemail("1234", "u") |
| 174 |
end; |
| 175 |
|
| 176 |
["1236"] = function() |
| 177 |
app.dial("Console/dsp") |
| 178 |
app.voicemail(1234, "b") |
| 179 |
end; |
| 180 |
|
| 181 |
["#"] = demo_hangup; |
| 182 |
t = demo_hangup; |
| 183 |
i = function() |
| 184 |
app.playback("invalid") |
| 185 |
demo_instruct() |
| 186 |
end; |
| 187 |
|
| 188 |
["500"] = function() |
| 189 |
app.playback("demo-abouttotry") |
| 190 |
app.dial("IAX2/[email protected]/s@default") |
| 191 |
app.playback("demo-nogo") |
| 192 |
demo_instruct() |
| 193 |
end; |
| 194 |
|
| 195 |
["600"] = function() |
| 196 |
app.playback("demo-echotest") |
| 197 |
app.echo() |
| 198 |
app.playback("demo-echodone") |
| 199 |
demo_instruct() |
| 200 |
end; |
| 201 |
|
| 202 |
["8500"] = function() |
| 203 |
app.voicemailmain() |
| 204 |
demo_instruct() |
| 205 |
end; |
| 206 |
|
| 207 |
}; |
| 208 |
|
| 209 |
default = { |
| 210 |
-- by default, do the demo |
| 211 |
include = {"demo"}; |
| 212 |
}; |
| 213 |
|
| 214 |
public = { |
| 215 |
-- ATTENTION: If your Asterisk is connected to the internet |
| 216 |
-- double check which services you offer to the world. |
| 217 |
-- |
| 218 |
include = {"demo"}; |
| 219 |
}; |
| 220 |
|
| 221 |
["local"] = { |
| 222 |
["_NXXXXXX"] = outgoing_local; |
| 223 |
}; |
| 224 |
} |
| 225 |
|
| 226 |
hints = { |
| 227 |
demo = { |
| 228 |
[1000] = "SIP/1000"; |
| 229 |
[1001] = "SIP/1001"; |
| 230 |
}; |
| 231 |
|
| 232 |
default = { |
| 233 |
["1234"] = "SIP/1234"; |
| 234 |
}; |
| 235 |
} |