extensions.ael 11 KB

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