extensions.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. dofile('/etc/asterisk/rorFunctions.lua')
  2. dofile('/etc/asterisk/rorDebug.lua')
  3. dofile('/etc/asterisk/rorConf.lua')
  4. SIP = "PJSIP/"
  5. CONSOLE = "Console/dsp" -- Console interface for demo
  6. --CONSOLE = "DAHDI/1"
  7. --CONSOLE = "Phone/phone0"
  8. IAXINFO = "guest" -- IAXtel username/password
  9. --IAXINFO = "myuser:mypass"
  10. TRUNK = "DAHDI/G2"
  11. TRUNKMSD = 1
  12. -- TRUNK = "IAX2/user:pass@provider"
  13. --
  14. -- Extensions are expected to be defined in a global table named 'extensions'.
  15. -- The 'extensions' table should have a group of tables in it, each
  16. -- representing a context. Extensions are defined in each context. See below
  17. -- for examples.
  18. --
  19. -- Extension names may be numbers, letters, or combinations thereof. If
  20. -- an extension name is prefixed by a '_' character, it is interpreted as
  21. -- a pattern rather than a literal. In patterns, some characters have
  22. -- special meanings:
  23. --
  24. -- X - any digit from 0-9
  25. -- Z - any digit from 1-9
  26. -- N - any digit from 2-9
  27. -- [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9)
  28. -- . - wildcard, matches anything remaining (e.g. _9011. matches
  29. -- anything starting with 9011 excluding 9011 itself)
  30. -- ! - wildcard, causes the matching process to complete as soon as
  31. -- it can unambiguously determine that no other matches are possible
  32. --
  33. -- For example the extension _NXXXXXX would match normal 7 digit
  34. -- dialings, while _1NXXNXXXXXX would represent an area code plus phone
  35. -- number preceded by a one.
  36. --
  37. -- If your extension has special characters in it such as '.' and '!' you must
  38. -- explicitly make it a string in the tabale definition:
  39. --
  40. -- ["_special."] = function;
  41. -- ["_special!"] = function;
  42. --
  43. -- There are no priorities. All extensions to asterisk appear to have a single
  44. -- priority as if they consist of a single priority.
  45. --
  46. -- Each context is defined as a table in the extensions table. The
  47. -- context names should be strings.
  48. --
  49. -- One context may be included in another context using the 'includes'
  50. -- extension. This extension should be set to a table containing a list
  51. -- of context names. Do not put references to tables in the includes
  52. -- table.
  53. --
  54. -- include = {"a", "b", "c"};
  55. --
  56. -- Channel variables can be accessed thorugh the global 'channel' table.
  57. --
  58. -- v = channel.var_name
  59. -- v = channel["var_name"]
  60. -- v.value
  61. -- v:get()
  62. --
  63. -- channel.var_name = "value"
  64. -- channel["var_name"] = "value"
  65. -- v:set("value")
  66. --
  67. -- channel.func_name(1,2,3):set("value")
  68. -- value = channel.func_name(1,2,3):get()
  69. --
  70. -- channel["func_name(1,2,3)"]:set("value")
  71. -- channel["func_name(1,2,3)"] = "value"
  72. -- value = channel["func_name(1,2,3)"]:get()
  73. --
  74. -- Note the use of the ':' operator to access the get() and set()
  75. -- methods.
  76. --
  77. -- Also notice the absence of the following constructs from the examples above:
  78. -- channel.func_name(1,2,3) = "value" -- this will NOT work
  79. -- value = channel.func_name(1,2,3) -- this will NOT work as expected
  80. --
  81. --
  82. -- Dialplan applications can be accessed through the global 'app' table.
  83. --
  84. -- app.Dial("DAHDI/1")
  85. -- app.dial("DAHDI/1")
  86. -- app["dial"]("DAHDI/1")
  87. --
  88. -- More examples can be found below.
  89. --
  90. -- An autoservice is automatically run while lua code is executing. The
  91. -- autoservice can be stopped and restarted using the autoservice_stop() and
  92. -- autoservice_start() functions. The autservice should be running before
  93. -- starting long running operations. The autoservice will automatically be
  94. -- stopped before executing applications and dialplan functions and will be
  95. -- restarted afterwards. The autoservice_status() function can be used to
  96. -- check the current status of the autoservice and will return true if an
  97. -- autoservice is currently running.
  98. --
  99. -- Note about naming conflicts:
  100. -- Lua allows you to refer to table entries using the '.' notation,
  101. -- I.E. app.goto(something), only if the entry doesn't conflict with an Lua
  102. -- reserved word. In the 'goto' example, with Lua 5.1 or earlier, 'goto' is
  103. -- not a reserved word so you'd be calling the Asterisk dialplan application
  104. -- 'goto'. Lua 5.2 however, introduced the 'goto' control statement which
  105. -- makes 'goto' a reserved word. This casues the interpreter to fail parsing
  106. -- the file and pbx_lua.so will fail to load. The same applies to any use of
  107. -- Lua tables including extensions, channels and any tables you create.
  108. --
  109. -- There are two ways around this: Since Lua is case-sensitive, you can use
  110. -- capitalized names, I.E. app.Goto(something) to refer to the Asterisk apps,
  111. -- functions, etc. Or you can use the full syntax, I.E. app["goto"](something).
  112. -- Both syntaxes are backwards compatible with earlier Lua versions. To make
  113. -- your Lua dialplans easier to maintain and to reduce the chance of future
  114. -- conflicts you may want to use the app["goto"](something) syntax for all
  115. -- table accesses.
  116. --
  117. function outgoing_local(c, e)
  118. app.dial("DAHDI/1/" .. e, "", "")
  119. end
  120. function demo_instruct()
  121. app.background("demo-instruct")
  122. app.waitexten()
  123. end
  124. function demo_congrats()
  125. app.background("demo-congrats")
  126. demo_instruct()
  127. end
  128. -- Answer the chanel and play the demo sound files
  129. function demo_start(context, exten)
  130. app.wait(1)
  131. app.answer()
  132. channel.TIMEOUT("digit"):set(5)
  133. channel.TIMEOUT("response"):set(10)
  134. -- app.set("TIMEOUT(digit)=5")
  135. -- app.set("TIMEOUT(response)=10")
  136. demo_congrats(context, exten)
  137. end
  138. function demo_hangup()
  139. app.playback("demo-thanks")
  140. app.hangup()
  141. end
  142. extensions = {
  143. demo = {
  144. s = demo_start;
  145. ["2"] = function()
  146. app.background("demo-moreinfo")
  147. demo_instruct()
  148. end;
  149. ["3"] = function ()
  150. channel.LANGUAGE():set("fr") -- set the language to french
  151. demo_congrats()
  152. end;
  153. ["1000"] = function()
  154. -- See the naming conflict note above.
  155. app['goto']("default", "s", 1)
  156. end;
  157. ["1234"] = function()
  158. app.playback("transfer", "skip")
  159. -- do a dial here
  160. end;
  161. ["1235"] = function()
  162. app.voicemail("1234", "u")
  163. end;
  164. ["1236"] = function()
  165. app.dial("Console/dsp")
  166. app.voicemail(1234, "b")
  167. end;
  168. ["#"] = demo_hangup;
  169. t = demo_hangup;
  170. i = function()
  171. app.playback("invalid")
  172. demo_instruct()
  173. end;
  174. ["500"] = function()
  175. app.playback("demo-abouttotry")
  176. app.dial("IAX2/guest@misery.digium.com/s@default")
  177. app.playback("demo-nogo")
  178. demo_instruct()
  179. end;
  180. ["600"] = function()
  181. app.playback("demo-echotest")
  182. app.echo()
  183. app.playback("demo-echodone")
  184. demo_instruct()
  185. end;
  186. ["8500"] = function()
  187. app.voicemailmain()
  188. demo_instruct()
  189. end;
  190. };
  191. tointerni = {};
  192. debug = {};
  193. testing = {};
  194. -- ci sono 4 classi di utenti fondamentali:
  195. -- - mixer (aka il tel invisibile)
  196. -- - regia (2 tel, il mixer non conta come regia)
  197. -- - interni (altri interni)
  198. -- - ext (esterno)
  199. ["from-mixer"] = {};
  200. ["from-interni"] = { include = {"tointerni", "debug"}; };
  201. ["from-regia"] = { include= {"from-interni", "testing"}; };
  202. ["from-ext"] = {};
  203. -- nessun utente "parte" da private, lo si puo' usare solo quando si fanno megahack
  204. ["private"] = {};
  205. default = {
  206. -- by default, do the demo
  207. include = {"demo"};
  208. };
  209. public = {
  210. -- ATTENTION: If your Asterisk is connected to the internet and you do
  211. -- not have allowguest=no in sip.conf, everybody out there may use your
  212. -- public context without authentication. In that case you want to
  213. -- double check which services you offer to the world.
  214. --
  215. include = {"demo"};
  216. };
  217. ["local"] = {
  218. ["_NXXXXXX"] = outgoing_local;
  219. };
  220. }
  221. -- gli interni si possono chiamare fra loro
  222. for _, num in ipairs(INTERNI) do
  223. extensions["from-interni"][num] = function()
  224. app.set("__DYNAMIC_FEATURES=mandainondaChiamante")
  225. app.dial(SIP .. num)
  226. end
  227. end
  228. --[[ for _, num in ipairs(EXT) do
  229. extensions["from-interni"][x] = function()
  230. app.set("__DYNAMIC_FEATURES=mandainonda")
  231. app.dial(SIP .. num)
  232. end
  233. end ]]--
  234. -- con il prefisso 0, gli interni possono chiamare qualsiasi cosa
  235. extensions["from-interni"]["_0."] = chiamaEsterno(TRUNKS)
  236. extensions["from-regia"]["_1[12]."] = chiamaEsterno(TRUNKS)
  237. -- gli esterni possono chiamare, e squilla in tutti i telefoni
  238. extensions["from-ext"]["0612345678"] = chiamaDaEsterno(INTERNI)
  239. extensions["debug"][9000] = function ()
  240. app.answer()
  241. -- TODO: fagli spiegare cosa sta leggendo
  242. for num, func in pairs(extensions["debug"]) do
  243. app.saydigits(num)
  244. -- TODO: fagli dire cosa fa
  245. app.wait(2)
  246. end
  247. app.hangup()
  248. end
  249. extensions["debug"][9440] = tono(440)
  250. extensions["debug"][9880] = tono(880)
  251. extensions["private"][9438] = tono(438)
  252. -- questa e' la stanza in cui 401 incontra i suoi interlocutori
  253. extensions["private"][9401] = function()
  254. app.answer()
  255. app.confbridge("401", "regia", "regia")
  256. app.hangup()
  257. end
  258. -- questa e' la stanza in cui 401 sente la musica a loop mentre aspetta
  259. extensions["private"][94011] = function()
  260. app.answer()
  261. app.musiconhold("default")
  262. app.hangup()
  263. end
  264. extensions["from-regia"][94011] = function()
  265. app.answer()
  266. app.musiconhold("default")
  267. app.hangup()
  268. end
  269. -- se inizia con 99, vuol dire che fa dial del numero di debug tramite Local/
  270. extensions["debug"][99440] = function()
  271. app.set("__DYNAMIC_FEATURES=mandainonda")
  272. app.dial("Local/9440@from-regia/n")
  273. end
  274. extensions["testing"][9009] = function()
  275. app.agi("agi:async")
  276. end
  277. hints = {
  278. demo = { };
  279. default = { };
  280. }