Debian Codegraph @

pbx/ael/ael-test/ael-test7/extensions.ael

raw
1 //
2 // Example AEL config file
3 //
4
5 globals {
6 CONSOLE=Console/dsp;
7 TRUNKMSD=0; //MSD digits to strip (usually 1 or 0)
8 TRUNCPROTO=SIP;
9 TRUNK=sunrocket;
10 PSTN=pstn-spa3k;
11 PSTNPROTO=SIP;
12 TARIOPROTO=SIP;
13 TARIO=tario;
14 CPPROTO=SIP;
15 CPACKET1=callpacket1;
16 CPACKET2=callpacket2;
17 SELLVOIP=1577040314;
18 SVPROTO=IAX2;
19 };
20
21
22 macro stdexten (ext , dev ) {
23 PrivacyManager(3,10);
24 if("${PRIVACYMGRSTATUS}" = "FAILED") {
25 Playback(vm-goodbye);
26 Hangup();
27 };
28
29 AGI(calleridnamelookup.agi);
30 Dial(${dev}/${ext},30,t);
31 switch(${DIALSTATUS}) {
32 case BUSY:
33 Voicemail(b${ext});
34 break;
35 default:
36 Voicemail(u${ext});
37 };
38 catch a {
39 VoiceMailMain(${ext});
40 return;
41 };
42 };
43
44 macro announce_minutes(minutes) {
45 Playback(vm-youhave);
46 SayNumber(${minutes});
47 Playback(vm-minutes);
48 Wait(1);
49 };
50
51 // Check if given provider allows only some free minutes per month
52 // and announce number of free minutes remaining.
53 // The limit will be reset monthly by cron job.
54 // The macro sets the following variables:
55 // MINUTES_LIMIT - number of free minutes per month
56 // MINUTES_USED - number of free minutes used in the current month
57 // PROVIDER - provider name
58
59 macro checkanddial(prov,proto,ext,arg1,arg2,arg3,arg4) {
60 Set(MINUTES_LIMIT=0);
61 Set(MINUTES_USED=0);
62 Set(PROVIDER=${prov});
63
64 if(${DB_EXISTS(Provider/${prov}/used)})
65 Set(MINUTES_USED=${DB_RESULT});
66
67 country_c = 0;
68 switch(${LEN(${ext})}) { //assuming all international numbers are 11 digits long.
69 case 10: //NXXNXXXXXX
70 country_c=1;
71 break;
72 case 11: //XNXXNXXXXXX
73 country_c = ${ext:0:1};
74 break;
75 default: //011XNXXNXXXXXX
76 country_c = ${ext:3:1};
77 break;
78 };
79
80 if("${prov}" = "${TRUNK}" & ${country_c} != 1) { // SunRocket international calls
81 Set(MINUTES_LIMIT=${DB(Provider/${prov}/limit)});
82 &announce_minutes($[${MINUTES_LIMIT} - ${MINUTES_USED}]);
83 };
84 if("${prov}" = "${CPACKET1}" | "${prov}" = "${CPACKET2}") { // Callpacket has a limit on domestic calls
85 Set(MINUTES_LIMIT=${DB(Provider/${prov}/limit)});
86 &announce_minutes($[${MINUTES_LIMIT} - ${MINUTES_USED}]);
87 };
88 DeadAGI(dial.agi,${proto}/${ext}@${prov},${arg1},${arg2},${arg3},${arg4});
89 };
90
91 macro trunkdial(ext) { // Dial sunrocket and set correct collerid
92 if("${CALLERID(num)}" = "1") {
93 Set(CALLERID(num)=7322271653);
94 } else {
95 Set(CALLERID(num)=7326260100);
96 };
97 Set(CALLERID(name)=Sergey Okhapkin);
98 &checkanddial(${TRUNK},${TRUNCPROTO},${ext},60,T);
99 Hangup;
100 };
101
102 macro checklocal(ext) { // lookup the number in DB and call the number via pstn or sunrocket
103 Set(AREACODE=${ext:0:3});
104 Set(EXCHANGE=${ext:3:3});
105 Set(IS_LOCAL=${DB_EXISTS(localnum/${AREACODE}/${EXCHANGE})});
106 if(${IS_LOCAL}) {
107 &checkanddial(${PSTN},${PSTNPROTO},${ext},60,T);
108 if ("${DIALSTATUS}" = "BUSY")
109 &trunkdial(${ext});
110 } else
111 &trunkdial(${ext});
112 };
113
114 macro autodial(ext) { // Find Least Cost Route
115 LCDial(${ext},60,T);
116 if("${DIALSTATUS}" = "NOPROVIDER")
117 Playback(invalid);
118 Hangup();
119 };
120
121 context default { // Calls to us
122 s => {
123 Wait(1);
124 Answer;
125 start:
126 Set(TIMEOUT(digit)=3);
127 Set(TIMEOUT(response)=10);
128 repeat:
129 for (x=0; ${x} < 5; x=${x} + 1) {
130 Background(home/greeting);
131 WaitExten();
132 };
133 };
134 t => jump *;
135 i => { // invalid extension
136 Playback(invalid);
137 goto s|repeat;
138 };
139 _* => {
140 Playback(vm-goodbye);
141 Wait(1);
142 Hangup;
143 };
144 1 => &stdexten(1,PJSIP/1);
145 2 => &stdexten(2,PJSIP/2);
146 3 => &stdexten(3,PJSIP/3);
147
148 2271653 => jump 1;
149 7322271653 => jump 1;
150 17322271653 => jump 1;
151
152 6260100 => jump 2;
153 7326260100 => jump 2;
154 17326260100 => jump 2;
155 8058701100 => jump 2;
156 3103622835 => jump 2;
157 sos => jump 2;
158 1400898 => jump 2;
159
160 6260101 => jump s;
161 7326260101 => jump s;
162 17326260101 => jump s;
163
164 2271677 => jump 3;
165 7322271677 => jump 3;
166 17322271677 => jump 3;
167 galka => jump 3;
168 911 => Dial(${PSTNPROTO}/911@${PSTN},60,);
169 380 => Dial(PJSIP/[email protected],60,T);
170
171 // Fun stuff
172 100 => {
173 SayUnixTime();
174 goto s|start;
175 };
176 101 => { // Voicemail
177 VoicemailMain(${CALLERID(num)});
178 Hangup;
179 };
180 102 => MusicOnHold();
181 // 103 => {
182 // Wait(1);
183 //start:
184 // Read(NUMBER,vm-enter-num-to-call);
185 // LCDial(${NUMBER},T);
186 // goto start;
187 // };
188 105 => jump s@phrase-menu;
189 7312 => {
190 ForkCDR;
191 Set(CALLERID(name)=Sergey Okhapkin);
192 Set(CALLERID(num)=7326260100);
193 DISA(1111|home);
194 };
195 };
196
197 context goiax {
198 s => {
199 Answer();
200 Ringing();
201 Wait(1);
202 start:
203 Read(NUMBER,vm-enter-num-to-call);
204 Set(CALLERID(name)=Central NJ);
205 Dial(IAX2/14301@fwdOUT/q${NUMBER},60,T);
206 goto start;
207 };
208
209 };
210
211 context phrase-menu {
212
213 s => {
214 Answer; // Answer the line
215 TIMEOUT(digit)=2; // Set Digit Timeout to 5 seconds
216 TIMEOUT(response)=10; // Set Response Timeout to 10 seconds
217 BackGround(custom/phrase-menu); // Play main menu.
218 };
219 1 => { // Phrase Recording
220 Wait(1);
221 Read(PHRASEID|custom/enter-phrase-num);
222 Wait(2); // give yourself 2 secs to take a breath and wait for beep
223 Record(custom/${PHRASEID}:gsm);
224 Wait(2);
225 Playback(custom/${PHRASEID});
226 Wait(1);
227 jump s;
228 };
229 2 => { // Phrase review
230 Wait(1);
231 Read(PHRASEID|custom/enter-phrase-num);
232 Wait(1);
233 Playback(custom/${PHRASEID});
234 Wait(1);
235 jump s;
236 };
237 t => Hangup;
238 i => {
239 Playback(custom/invalid-option);
240 jump s;
241 };
242 };
243
244 context outbound {
245 // North America seven-, ten- and eleven digits
246 _NXXXXXX => &autodial(1732${EXTEN});
247 _NXXNXXXXXX => &autodial(1${EXTEN});
248 _ZNXXNXXXXX. => &autodial(${EXTEN});
249 // Toll free numbers via PSTN
250 // _1800NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
251 // _1888NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
252 // _1877NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
253 // _1866NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
254
255 _011. => { //International context accessed through trunk
256 &trunkdial(${EXTEN});
257 };
258 _012. => { //fwdOUT
259 Set(CALLERID(name)=Central NJ);
260 Dial(IAX2/14301@fwdOUT/q${EXTEN:3},60,T);
261 };
262 _013X. => { //NECC
263 Dial(${PSTNPROTO}/011${EXTEN:3}@${PSTN},60,T);
264 };
265 _0131. => { //NECC to US
266 Dial(${PSTNPROTO}/${EXTEN:3}@${PSTN},60,T);
267 };
268 _014. => { //TARIO by SIP ID
269 Set(CALLERID(name)=Sergey Okhapkin);
270 Set(CALLERID(num)=1400898);
271 Dial(${TARIOPROTO}/${EXTEN:3}@${TARIO},60,T);
272 };
273 _0157. => { //TARIO outbound Russia
274 Set(CALLERID(name)=Sergey Okhapkin);
275 Set(CALLERID(num)=1400898);
276 Dial(${TARIOPROTO}/8${EXTEN:4}@${TARIO},60,T);
277 };
278 // _015. => { //TARIO outbound international
279 // CALLERID(name)="Sergey Okhapkin";
280 // CALLERID(num)=1400898;
281 // Dial(${TARIOPROTO}/810${EXTEN:3}@${TARIO},60,T);
282 // };
283 _0161NXXNXXXXXX => { //Callpacket outbound USA/Canada
284 &checkanddial(${CPACKET1},${CPPROTO},${EXTEN:3},60,T);
285 };
286 _0171NXXNXXXXXX => { //Callpacket outbound USA/Canada
287 &checkanddial(${CPACKET2},${CPPROTO},${EXTEN:3},60,T);
288 };
289 _0181NXXNXXXXXX => { //sellvoip outbound USA/Canada
290 Dial(${SVPROTO}/${SELLVOIP}@${SELLVOIP}/${EXTEN:3},60,T);
291 };
292 _019. => { //Voipbuster
293 Dial(IAX2/sokhapkin@voipbuster/00${EXTEN:3},60,T);
294 };
295 };
296
297 context home { //calls from us
298 includes {
299 default;
300 outbound;
301 };
302 };
303
304 context sunrocket-in {
305 7322271653 => jump s;
306 7326260100 => jump 2@default;
307 s => {
308 if("${CALLERID(num)}" = "sunrocketcom")
309 Set(CALLERID(num)=);
310 switch(${CALLERID(RDNIS)}) {
311 case 7326260100:
312 jump 2@default;
313 break;
314 case 7326260101:
315 jump s@default;
316 break;
317 default:
318 jump 1@default;
319 break;
320 };
321 };
322 };
323
324 context pstn-in {
325 3 => {
326 if ("${CALLERID(num)}" = "7322271677")
327 Set(CALLERID(num)=);
328 jump 3@default;
329 };
330 };
331
332 context tario.net-in {
333 _X. => {
334 Set(CALLERID(name)=);
335 if("${CALLERID(num):-11:1}" = "8")
336 Set(CALLERID(num)=7${CALLERID(num):1});
337 if("${SIP_HEADER(To)}" = "<sip:[email protected]>") {
338 jump 3@default;
339 } else if("${SIP_HEADER(To)}" = "<sip:[email protected]>") {
340 jump 1@default;
341 } else
342 jump 2@default;
343 };
344 };
345
346 context from-callpacket {
347 8058701100 => jump 2@default;
348 3103622835 => {
349 Answer;
350 Ringing;
351 Wait(10);
352 Voicemail(b3103622835);
353 Hangup;
354 };
355 a => Hangup;
356 };
357
358 context fromfwdOUT { // make sure we only accept US and Canada calls, limit to 30 minutes
359 includes {
360 fromfwdOUT-catchbad;
361 fromfwdOUT-isgood;
362 fromfwdOUT-catchall;
363 };
364 };
365
366 context fromfwdOUT-isgood {
367 _17326260100 => jump 2@default;
368 _17326260101 => jump s@default;
369 _17322271653 => jump 1@default;
370 _17322271677 => jump 3@default;
371 _1NXXNXXXXXX => {
372 Set(CALLERID(name)=Sergey Okhapkin);
373 // Set(CALLERID(num)=7326260100);
374 // Dial(${TRUNCPROTO}/*67${EXTEN:${TRUNKMSD}}@${TRUNK},60,,L(1800000:60000));
375 Dial(${CPPROTO}/${EXTEN}@${CPACKET2},60,,L(1800000:60000));
376 };
377 };
378
379 context fromfwdOUT-catchbad { //block bahamas, etc
380 _1900. => congestion ; //N11
381 _1XXX976. => congestion ; //N11
382 _1XXX555. => congestion ; //N11
383 _1X11. => congestion ; //N11
384 _1867. => congestion ; //Yukon (sorry mike)
385
386 // exten => _1NPA Country
387 _1242. => congestion; //BAHAMAS
388 _1246. => congestion; //BARBADOS
389 _1264. => congestion; //ANGUILLA
390 _1268. => congestion; //ANTIGUA/BARBUDA
391 _1284. => congestion; //BRITISH VIRGIN ISLANDS
392 _1345. => congestion; //CAYMAN ISLANDS
393 _1441. => congestion; //BERMUDA
394 _1473. => congestion; //GRENADA
395 _1649. => congestion; //TURKS & CAICOS ISLANDS
396 _1664. => congestion; //MONTSERRAT
397 _1758. => congestion; //ST. LUCIA
398 _1767. => congestion; //DOMINICA
399 _1784. => congestion; //ST. VINCENT & GRENADINES
400 _1809. => congestion; //DOMINICAN REPUBLIC
401 _1829. => congestion; //DOMINICAN REPUBLIC
402 _1868. => congestion; //TRINIDAD AND TOBAGO
403 _1869. => congestion; //ST. KITTS AND NEVIS
404 _1876. => congestion; //JAMAICA
405 _1787. => congestion; //Puerto Rico 787, 939 $0.07
406 _1939. => congestion; //Puerto Rico 787, 939 $0.07
407 _1671. => congestion; //Guam 671 $0.08
408 _1340. => congestion; //U.S. Virgin Islands 340 $0.06
409 };
410
411 context fromfwdOUT-catchall {
412 _X. => Congestion;
413 h => Hangup ; //hangup event
414 i => Hangup ; //invalid event
415 t => Hangup ; //timeout event
416 };
417
418 context ael-demo {
419 s => {
420 Wait(1);
421 Answer();
422 TIMEOUT(digit)=5;
423 TIMEOUT(response)=10;
424 restart:
425 Background(demo-congrats);
426 instructions:
427 for (x=0; ${x} < 3; x=${x} + 1) {
428 Background(demo-instruct);
429 WaitExten();
430 };
431 };
432 2 => {
433 Background(demo-moreinfo);
434 goto s|instructions;
435 };
436 3 => {
437 LANGUAGE()=fr;
438 goto s|restart;
439 };
440 500 => {
441 Playback(demo-abouttotry);
442 Dial(IAX2/[email protected]);
443 Playback(demo-nogo);
444 goto s|instructions;
445 };
446 600 => {
447 Playback(demo-echotest);
448 Echo();
449 Playback(demo-echodone);
450 goto s|instructions;
451 };
452 _1234 => &std-exten-ael(${EXTEN}, "IAX2");
453 # => {
454 Playback(demo-thanks);
455 Hangup();
456 };
457 t => jump #;
458 i => Playback(invalid);
459 };