ADelphini
(usa Arch Linux)
Enviado em 21/06/2011 - 17:52h
Asterisk Dialplan com Lua:
módulo para escrever Asterisk dialplan na linguagem de programação Lua foi incorporada tronco Asterisk. Ele foi desenvolvido por Matt Nicholson da Digium, Inc. Veja a comprometer e emitir mantis . Ele está disponível desde a versão 1.6 do Asterisk.
De lua.org :
Lua é uma poderosa, rápida e leve, linguagem de script incorporável.
Lua combina sintaxe simples para programação procedural com poderosas construções para descrição de dados baseadas em tabelas associativas e semântica extensível. Lua é tipada dinamicamente, é interpretada a partir de bytecodes para uma máquina virtual baseada em registradores, e tem gerenciamento automático de memória com coleta de lixo incremental, tornando-a ideal para configuração, scripts e prototipagem rápida.
'Lua' significa 'lua' em Português e é pronunciado LOO-ah.
Este módulo fornece uma outra alternativa para a programação dialplan nativa. Confira o extensions.lua exemplo de arquivo para um exemplo de como parece.
Tem havido alguma discussão sobre pbx_lua benchmarking versus o extensions.conf existentes e extensions.ael para o desempenho de execução dialplan, mas não houve resultados foram lançados ainda.
=================================================================
Updated the sample pbx_lua config file to reflect autoservice changes.
1
2
3 CONSOLE = "Console/dsp" -- Console interface for demo
4 --CONSOLE = "DAHDI/1"
5 --CONSOLE = "Phone/phone0"
6
7 IAXINFO = "guest" -- IAXtel username/password
8 --IAXINFO = "myuser:mypass"
9
10 TRUNK = "DAHDI/G2"
11 TRUNKMSD = 1
12 -- TRUNK = "IAX2/user:pass@provider"
13
14
15 --
16 -- Extensions are expected to be defined in a global table named 'extensions'.
17 -- The 'extensions' table should have a group of tables in it, each
18 -- representing a context. Extensions are defined in each context. See below
19 -- for examples.
20 --
21 -- Extension names may be numbers, letters, or combinations thereof. If
22 -- an extension name is prefixed by a '_' character, it is interpreted as
23 -- a pattern rather than a literal. In patterns, some characters have
24 -- special meanings:
25 --
26 -- X - any digit from 0-9
27 -- Z - any digit from 1-9
28 -- N - any digit from 2-9
29 -- [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9)
30 -- . - wildcard, matches anything remaining (e.g. _9011. matches
31 -- anything starting with 9011 excluding 9011 itself)
32 -- ! - wildcard, causes the matching process to complete as soon as
33 -- it can unambiguously determine that no other matches are possible
34 --
35 -- For example the extension _NXXXXXX would match normal 7 digit
36 -- dialings, while _1NXXNXXXXXX would represent an area code plus phone
37 -- number preceded by a one.
38 --
39 -- If your extension has special characters in it such as '.' and '!' you must
40 -- explicitly make it a string in the tabale definition:
41 --
42 -- ["_special."] = function;
43 -- ["_special!"] = function;
44 --
45 -- There are no priorities. All extensions to asterisk appear to have a single
46 -- priority as if they consist of a single priority.
47 --
48 -- Each context is defined as a table in the extensions table. The
49 -- context names should be strings.
50 --
51 -- One context may be included in another context using the 'includes'
52 -- extension. This extension should be set to a table containing a list
53 -- of context names. Do not put references to tables in the includes
54 -- table.
55 --
56 -- include = {"a", "b", "c"};
57 --
58 -- Channel variables can be accessed thorugh the global 'channel' table.
59 --
60 -- v = channel.var_name
61 -- v = channel["var_name"]
62 -- v.value
63 -- v:get()
64 --
65 -- channel.var_name = "value"
66 -- channel["var_name"] = "value"
67 -- v:set("value")
68 --
69 -- channel.func_name(1,2,3):set("value")
70 -- value = channel.func_name(1,2,3):get()
71 --
72 -- channel["func_name(1,2,3)"]:set("value")
73 -- channel["func_name(1,2,3)"] = "value"
74 -- value = channel["func_name(1,2,3)"]:get()
75 --
76 -- Note the use of the ':' operator to access the get() and set()
77 -- methods.
78 --
79 -- Also notice the absence of the following constructs from the examples above:
80 -- channel.func_name(1,2,3) = "value" -- this will NOT work
81 -- value = channel.func_name(1,2,3) -- this will NOT work as expected
82 --
83 --
84 -- Dialplan applications can be accessed through the global 'app' table.
85 --
86 -- app.Dial("DAHDI/1")
87 -- app.dial("DAHDI/1")
88 --
89 -- More examples can be found below.
90 --
91 -- An autoservice is automatically run while lua code is executing. The
92 -- autoservice can be stopped and restarted using the autoservice_stop() and
93 -- autoservice_start() functions. The autservice should be running before
94 -- starting long running operations. The autoservice will automatically be
95 -- stopped before executing applications and dialplan functions and will be
96 -- restarted afterwards. The autoservice_status() function can be used to
97 -- check the current status of the autoservice and will return true if an
98 -- autoservice is currently running.
99 --
100
101 function outgoing_local(c, e)
102 app.dial("DAHDI/1/" .. e, "", "")
103 end
104
105 function demo_instruct()
106 app.background("demo-instruct")
107 app.waitexten()
108 end
109
110 function demo_congrats()
111 app.background("demo-congrats")
112 demo_instruct()
113 end
114
115 -- Answer the chanel and play the demo sound files
116 function demo_start(context, exten)
117 app.wait(1)
118 app.answer()
119
120 channel.TIMEOUT("digit"):set(5)
121 channel.TIMEOUT("response"):set(10)
122 -- app.set("TIMEOUT(digit)=5")
123 -- app.set("TIMEOUT(response)=10")
124
125 demo_congrats(context, exten)
126 end
127
128 function demo_hangup()
129 app.playback("demo-thanks")
130 app.hangup()
131 end
132
133 extensions = {
134 demo = {
135 s = demo_start;
136
137 ["2"] = function()
138 app.background("demo-moreinfo")
139 demo_instruct()
140 end;
141 ["3"] = function ()
142 channel.LANGUAGE():set("fr") -- set the language to french
143 demo_congrats()
144 end;
145
146 ["1000"] = function()
147 app.goto("default", "s", 1)
148 end;
149
150 ["1234"] = function()
151 app.playback("transfer", "skip")
152 -- do a dial here
153 end;
154
155 ["1235"] = function()
156 app.voicemail("1234", "u")
157 end;
158
159 ["1236"] = function()
160 app.dial("Console/dsp")
161 app.voicemail(1234, "b")
162 end;
163
164 ["#"] = demo_hangup;
165 t = demo_hangup;
166 i = function()
167 app.playback("invalid")
168 demo_instruct()
169 end;
170
171 ["500"] = function()
172 app.playback("demo-abouttotry")
173 app.dial("IAX2/guest@misery.digium.com/s@default")
174 app.playback("demo-nogo")
175 demo_instruct()
176 end;
177
178 ["600"] = function()
179 app.playback("demo-echotest")
180 app.echo()
181 app.playback("demo-echodone")
182 demo_instruct()
183 end;
184
185 ["8500"] = function()
186 app.voicemailmain()
187 demo_instruct()
188 end;
189
190 };
191
192 default = {
193 -- by default, do the demo
194 include = {"demo"};
195 };
196
197 ["local"] = {
198 ["_NXXXXXX"] = outgoing_local;
199 };
200 }
201
202 hints = {
203 demo = {
204 [1000] = "SIP/1000";
205 [1001] = "SIP/1001";
206 };
207
208 default = {
209 ["1234"] = "SIP/1234";
210 };
211 }
================================================================
Agora igualmente a programação convencional, ael a lua também aceita programação segmentada, o qual eu recomendo para ficar fácil de dar manutenção ao seu servidor IP PBX.
Cumprimentos.
--
Angelo Delphini | Smart Solutions | Diretor de Tecnologia da Informação
Telf: 707 450 155 | Móvel: +351 914 039 706 |
www.smart-solutions.pt