extensions.lua 5.3 KB

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