extensions.lua.sample 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. --
  83. -- More examples can be found below.
  84. --
  85. -- An autoservice is automatically run while lua code is executing. The
  86. -- autoservice can be stopped and restarted using the autoservice_stop() and
  87. -- autoservice_start() functions. The autservice should be running before
  88. -- starting long running operations. The autoservice will automatically be
  89. -- stopped before executing applications and dialplan functions and will be
  90. -- restarted afterwards. The autoservice_status() function can be used to
  91. -- check the current status of the autoservice and will return true if an
  92. -- autoservice is currently running.
  93. --
  94. function outgoing_local(c, e)
  95. app.dial("DAHDI/1/" .. e, "", "")
  96. end
  97. function demo_instruct()
  98. app.background("demo-instruct")
  99. app.waitexten()
  100. end
  101. function demo_congrats()
  102. app.background("demo-congrats")
  103. demo_instruct()
  104. end
  105. -- Answer the chanel and play the demo sound files
  106. function demo_start(context, exten)
  107. app.wait(1)
  108. app.answer()
  109. channel.TIMEOUT("digit"):set(5)
  110. channel.TIMEOUT("response"):set(10)
  111. -- app.set("TIMEOUT(digit)=5")
  112. -- app.set("TIMEOUT(response)=10")
  113. demo_congrats(context, exten)
  114. end
  115. function demo_hangup()
  116. app.playback("demo-thanks")
  117. app.hangup()
  118. end
  119. extensions = {
  120. demo = {
  121. s = demo_start;
  122. ["2"] = function()
  123. app.background("demo-moreinfo")
  124. demo_instruct()
  125. end;
  126. ["3"] = function ()
  127. channel.LANGUAGE():set("fr") -- set the language to french
  128. demo_congrats()
  129. end;
  130. ["1000"] = function()
  131. app.goto("default", "s", 1)
  132. end;
  133. ["1234"] = function()
  134. app.playback("transfer", "skip")
  135. -- do a dial here
  136. end;
  137. ["1235"] = function()
  138. app.voicemail("1234", "u")
  139. end;
  140. ["1236"] = function()
  141. app.dial("Console/dsp")
  142. app.voicemail(1234, "b")
  143. end;
  144. ["#"] = demo_hangup;
  145. t = demo_hangup;
  146. i = function()
  147. app.playback("invalid")
  148. demo_instruct()
  149. end;
  150. ["500"] = function()
  151. app.playback("demo-abouttotry")
  152. app.dial("IAX2/guest@misery.digium.com/s@default")
  153. app.playback("demo-nogo")
  154. demo_instruct()
  155. end;
  156. ["600"] = function()
  157. app.playback("demo-echotest")
  158. app.echo()
  159. app.playback("demo-echodone")
  160. demo_instruct()
  161. end;
  162. ["8500"] = function()
  163. app.voicemailmain()
  164. demo_instruct()
  165. end;
  166. };
  167. default = {
  168. -- by default, do the demo
  169. include = {"demo"};
  170. };
  171. ["local"] = {
  172. ["_NXXXXXX"] = outgoing_local;
  173. };
  174. }
  175. hints = {
  176. demo = {
  177. [1000] = "SIP/1000";
  178. [1001] = "SIP/1001";
  179. };
  180. default = {
  181. ["1234"] = "SIP/1234";
  182. };
  183. }