aboutsummaryrefslogtreecommitdiffstats
path: root/pbx/ael/ael-test/ael-test7/extensions.ael
blob: 52f9a077acb6db2d8d6ad705f6548b462f2796d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
//
// Example AEL config file
//

globals {
	CONSOLE=Console/dsp;
	TRUNKMSD=0;					//MSD digits to strip (usually 1 or 0)
	TRUNCPROTO=SIP;
	TRUNK=sunrocket;
	PSTN=pstn-spa3k;
	PSTNPROTO=SIP;
	TARIOPROTO=SIP;
	TARIO=tario;
	CPPROTO=SIP;
	CPACKET1=callpacket1;
	CPACKET2=callpacket2;
	SELLVOIP=1577040314;
	SVPROTO=IAX2;
};


macro stdexten (ext , dev ) {
	PrivacyManager(3,10);
	if("${PRIVACYMGRSTATUS}" = "FAILED") {
		Playback(vm-goodbye);
		Hangup();
	};

	AGI(calleridnamelookup.agi);
        Dial(${dev}/${ext},30,t);
        switch(${DIALSTATUS}) {
        case BUSY:
                Voicemail(b${ext});
                break;
        default:
                Voicemail(u${ext});
        };
        catch a {
                VoiceMailMain(${ext});
                return;
        };
};

macro announce_minutes(minutes) {
	Playback(vm-youhave);
	SayNumber(${minutes});
	Playback(vm-minutes);
	Wait(1);
};

// Check if given provider allows only some free minutes per month
// and announce number of free minutes remaining.
// The limit will be reset monthly by cron job.
// The macro sets the following variables:
// MINUTES_LIMIT - number of free minutes per month
// MINUTES_USED - number of free minutes used in the current month
// PROVIDER - provider name

macro checkanddial(prov,proto,ext,arg1,arg2,arg3,arg4) {
	Set(MINUTES_LIMIT=0);
	Set(MINUTES_USED=0);
	Set(PROVIDER=${prov});

	if(${DB_EXISTS(Provider/${prov}/used)})
		Set(MINUTES_USED=${DB_RESULT});
	
	country_c = 0;
	switch(${LEN(${ext})}) {	//assuming all international numbers are 11 digits long.
	case 10:			//NXXNXXXXXX
		country_c=1;
		break;
	case 11:			//XNXXNXXXXXX
		country_c = ${ext:0:1};
		break;
	default:			//011XNXXNXXXXXX
		country_c = ${ext:3:1};
		break;
	};
		
	if("${prov}" = "${TRUNK}" & ${country_c} != 1) {	// SunRocket international calls
		Set(MINUTES_LIMIT=${DB(Provider/${prov}/limit)});
		&announce_minutes($[${MINUTES_LIMIT} - ${MINUTES_USED}]);
	};
	if("${prov}" = "${CPACKET1}" | "${prov}" = "${CPACKET2}") {			// Callpacket has a limit on domestic calls
		Set(MINUTES_LIMIT=${DB(Provider/${prov}/limit)});
		&announce_minutes($[${MINUTES_LIMIT} - ${MINUTES_USED}]);
	};
	DeadAGI(dial.agi,${proto}/${ext}@${prov},${arg1},${arg2},${arg3},${arg4});
};

macro trunkdial(ext) {	// Dial sunrocket and set correct collerid
	if("${CALLERID(number)}" = "1") {
		Set(CALLERID(number)=7322271653);
	} else {
		Set(CALLERID(number)=7326260100);
	};
	Set(CALLERID(name)=Sergey Okhapkin);
	&checkanddial(${TRUNK},${TRUNCPROTO},${ext},60,T);
	Hangup;
};

macro checklocal(ext) {	// lookup the number in DB and call the number via pstn or sunrocket
	Set(AREACODE=${ext:0:3});
	Set(EXCHANGE=${ext:3:3});
	Set(IS_LOCAL=${DB_EXISTS(localnum/${AREACODE}/${EXCHANGE})});
	if(${IS_LOCAL}) {
		&checkanddial(${PSTN},${PSTNPROTO},${ext},60,T);
		if ("${DIALSTATUS}" = "BUSY")
			&trunkdial(${ext});
	} else
		&trunkdial(${ext});
};

macro autodial(ext) {	// Find Least Cost Route
	LCDial(${ext},60,T);
	if("${DIALSTATUS}" = "NOPROVIDER")
		Playback(invalid);
	Hangup();
};

context default {	// Calls to us
	s => {
		Wait(1);
		Answer;
start:
		Set(TIMEOUT(digit)=3);
		Set(TIMEOUT(response)=10);
repeat:
		for (x=0; ${x} < 5; x=${x} + 1) {
			Background(home/greeting);
			WaitExten();
		};
	};
	t => jump *;
	i => {	// invalid extension
		Playback(invalid);
		goto s|repeat;
	};
	_* => {
		Playback(vm-goodbye);
		Wait(1);
		Hangup;
	};
	1 => &stdexten(1,SIP/1);
	2 => &stdexten(2,SIP/2);
	3 => &stdexten(3,SIP/3);

	2271653 => jump 1;
	7322271653 => jump 1;
	17322271653 => jump 1;

	6260100 => jump 2;
	7326260100 => jump 2;
	17326260100 => jump 2;
	8058701100 => jump 2;
	3103622835 => jump 2;
	sos => jump 2;
	1400898 => jump 2;

	6260101 => jump s;
	7326260101 => jump s;
	17326260101 => jump s;

	2271677 => jump 3;
	7322271677 => jump 3;
	17322271677 => jump 3;
	galka => jump 3;
	911 => Dial(${PSTNPROTO}/911@${PSTN},60,);
	380 => Dial(SIP/topspeen@212.40.38.70,60,T);

	// Fun stuff
	100 => {
		SayUnixTime();
		goto s|start;
	};
	101 => {	// Voicemail
		VoicemailMain(${CALLERID(number)});
		Hangup;
	};
	102 => MusicOnHold();
//	103 => {
//		Wait(1);
//start:
//		Read(NUMBER,vm-enter-num-to-call);
//		LCDial(${NUMBER},T);
//		goto start;
//	};
	105 => jump s@phrase-menu;
	7312 => {
		ForkCDR;
		Set(CALLERID(name)=Sergey Okhapkin);
		Set(CALLERID(number)=7326260100);
		DISA(1111|home);
	};
};

context goiax {
	s => {
		Answer();
		Ringing();
		Wait(1);
start:
		Read(NUMBER,vm-enter-num-to-call);
		Set(CALLERID(name)=Central NJ);
		Dial(IAX2/14301@fwdOUT/q${NUMBER},60,T);
		goto start;
	};

};

context phrase-menu {

	s => {
		Answer;			// Answer the line
		TIMEOUT(digit)=2; 	// Set Digit Timeout to 5 seconds
		TIMEOUT(response)=10; 	// Set Response Timeout to 10 seconds
		BackGround(custom/phrase-menu);	//  Play main menu.
	};
	1 => {				// Phrase Recording
		Wait(1);
		Read(PHRASEID|custom/enter-phrase-num);
		Wait(2); 		// give yourself 2 secs to take a breath and wait for beep
		Record(custom/${PHRASEID}:gsm);
		Wait(2);
		Playback(custom/${PHRASEID});
		Wait(1);
		jump s;
	};
	2 => {				// Phrase review
		Wait(1);
		Read(PHRASEID|custom/enter-phrase-num);
		Wait(1);
		Playback(custom/${PHRASEID});
		Wait(1);
		jump s;
	};
	t => Hangup;
	i => {
		Playback(custom/invalid-option);
		jump s;
	};
};

context outbound {
	// North America seven-, ten- and eleven digits
	_NXXXXXX => &autodial(1732${EXTEN});
	_NXXNXXXXXX => &autodial(1${EXTEN});
	_ZNXXNXXXXX. => &autodial(${EXTEN});
	// Toll free numbers via PSTN
//	_1800NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
//	_1888NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
//	_1877NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);
//	_1866NXXXXXX => &checkanddial(${PSTN},${PSTNPROTO},${EXTEN},60,T);

	_011. => {	//International context accessed through trunk
		&trunkdial(${EXTEN});
	};
	_012. => {	//fwdOUT
		Set(CALLERID(name)=Central NJ);
		Dial(IAX2/14301@fwdOUT/q${EXTEN:3},60,T);
	};                     
	_013X. => {	//NECC
		Dial(${PSTNPROTO}/011${EXTEN:3}@${PSTN},60,T);
	};
	_0131. => {	//NECC to US
		Dial(${PSTNPROTO}/${EXTEN:3}@${PSTN},60,T);
	};
	_014. => {	//TARIO by SIP ID
		Set(CALLERID(name)=Sergey Okhapkin);
		Set(CALLERID(number)=1400898);
		Dial(${TARIOPROTO}/${EXTEN:3}@${TARIO},60,T);
	};
	_0157. => {	//TARIO outbound Russia
		Set(CALLERID(name)=Sergey Okhapkin);
		Set(CALLERID(number)=1400898);
		Dial(${TARIOPROTO}/8${EXTEN:4}@${TARIO},60,T);
	};
//	_015. => {	//TARIO outbound international
//		CALLERID(name)="Sergey Okhapkin";
//		CALLERID(number)=1400898;
//		Dial(${TARIOPROTO}/810${EXTEN:3}@${TARIO},60,T);
//	};
	_0161NXXNXXXXXX => {	//Callpacket outbound USA/Canada
		&checkanddial(${CPACKET1},${CPPROTO},${EXTEN:3},60,T);
	};
	_0171NXXNXXXXXX => {	//Callpacket outbound USA/Canada
		&checkanddial(${CPACKET2},${CPPROTO},${EXTEN:3},60,T);
	};
	_0181NXXNXXXXXX => {	//sellvoip outbound USA/Canada
		Dial(${SVPROTO}/${SELLVOIP}@${SELLVOIP}/${EXTEN:3},60,T);
	};
	_019. => {	//Voipbuster
		Dial(IAX2/sokhapkin@voipbuster/00${EXTEN:3},60,T);
	};
};

context home {		//calls from us
	includes {
		default;
		outbound;
	};
};

context sunrocket-in {
	7322271653 => jump s;
	7326260100 => jump 2@default;
	s => {
		if("${CALLERID(number)}" = "sunrocketcom")
			Set(CALLERID(number)=);
		switch(${CALLERID(RDNIS)}) {
		case 7326260100:
			jump 2@default;
			break;
		case 7326260101:
			jump s@default;
			break;
		default:
			jump 1@default;
			break;
		};
	};
};

context pstn-in {
	3 => {
		if ("${CALLERID(number)}" = "7322271677")
			Set(CALLERID(number)=);
		jump 3@default;
	};
};

context tario.net-in {
	_X. => {
		Set(CALLERID(name)=);
		if("${CALLERID(number):-11:1}" = "8")
			Set(CALLERID(number)=7${CALLERID(number):1});
		if("${SIP_HEADER(To)}" = "<sip:2271677@sipnet.ru>") {
			jump 3@default;
		} else if("${SIP_HEADER(To)}" = "<sip:2271653@sipnet.ru>") {
			jump 1@default;
		} else
			jump 2@default;                                                     
	};
};

context from-callpacket {
	8058701100 => jump 2@default;
	3103622835 => {
		Answer;
		Ringing;
		Wait(10);
		Voicemail(b3103622835);
		Hangup;
	};
	a => Hangup;
};

context fromfwdOUT {	//  make sure we only accept US and Canada calls, limit to 30 minutes
	includes {
		fromfwdOUT-catchbad;
		fromfwdOUT-isgood;
		fromfwdOUT-catchall;
	};
};

context fromfwdOUT-isgood {
	_17326260100 => jump 2@default;
	_17326260101 => jump s@default;
	_17322271653 => jump 1@default;
	_17322271677 => jump 3@default;
	_1NXXNXXXXXX => {
		Set(CALLERID(name)=Sergey Okhapkin);
//		Set(CALLERID(number)=7326260100);
//		Dial(${TRUNCPROTO}/*67${EXTEN:${TRUNKMSD}}@${TRUNK},60,,L(1800000:60000));
		Dial(${CPPROTO}/${EXTEN}@${CPACKET2},60,,L(1800000:60000));
	};
};

context fromfwdOUT-catchbad {	//block bahamas, etc
	_1900. => congestion    ; //N11
	_1XXX976. => congestion ; //N11
	_1XXX555. => congestion ; //N11
	_1X11. => congestion    ; //N11
	_1867. => congestion    ; //Yukon (sorry mike)

		// exten => _1NPA Country
	_1242. => congestion;   //BAHAMAS
	_1246. => congestion;   //BARBADOS
	_1264. => congestion;   //ANGUILLA
	_1268. => congestion;   //ANTIGUA/BARBUDA
	_1284. => congestion;   //BRITISH VIRGIN ISLANDS
	_1345. => congestion;   //CAYMAN ISLANDS
	_1441. => congestion;   //BERMUDA
	_1473. => congestion;   //GRENADA
	_1649. => congestion;   //TURKS & CAICOS ISLANDS
	_1664. => congestion;   //MONTSERRAT
	_1758. => congestion;   //ST. LUCIA
	_1767. => congestion;   //DOMINICA
	_1784. => congestion;   //ST. VINCENT & GRENADINES
	_1809. => congestion;   //DOMINICAN REPUBLIC
	_1829. => congestion;   //DOMINICAN REPUBLIC
	_1868. => congestion;   //TRINIDAD AND TOBAGO
	_1869. => congestion;   //ST. KITTS AND NEVIS
	_1876. => congestion;   //JAMAICA
	_1787. => congestion;   //Puerto Rico 787, 939 $0.07
	_1939. => congestion;   //Puerto Rico 787, 939 $0.07
	_1671. => congestion;   //Guam 671 $0.08
	_1340. => congestion;   //U.S. Virgin Islands 340 $0.06
};

context fromfwdOUT-catchall {
	_X. => Congestion;
	h => Hangup    ;	//hangup event
	i => Hangup    ;	//invalid event
	t => Hangup    ;	//timeout event
};

context ael-demo {
	s => {
		Wait(1);
		Answer();
		TIMEOUT(digit)=5;
		TIMEOUT(response)=10;
restart:
		Background(demo-congrats);
instructions:
		for (x=0; ${x} < 3; x=${x} + 1) {
			Background(demo-instruct);
			WaitExten();
		};
	};
	2 => {
		Background(demo-moreinfo);
		goto s|instructions;
	};
	3 => {
		LANGUAGE()=fr;
		goto s|restart;
	};
	500 => {
		Playback(demo-abouttotry);
		Dial(IAX2/guest@misery.digium.com);
		Playback(demo-nogo);
		goto s|instructions;
	};
	600 => {
		Playback(demo-echotest);
		Echo();
		Playback(demo-echodone);
		goto s|instructions;
	};
	_1234 => &std-exten-ael(${EXTEN}, "IAX2");
	# => {
		Playback(demo-thanks);
		Hangup();
	};
	t => jump #;
	i => Playback(invalid);
};