extensions.lua.sample 6.9 KB

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