5ceb0b9fb363d3199fa67ab2f2a843b74f1c6773
[motion2.git] / server / services / agi / channel.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x0530=['520-Invalid','520\x20End\x20of\x20proper','function','no\x20code','replace','indexOf','substr','startsWith','length','error','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','pipe','write','inherits','prototype','sendRequest','command','answer','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','isArray','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','agi','exec','AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','EventEmitter','./reply','./error','setTimeout','setEncoding','headers','emit','ready','hangup','substring'];(function(_0x1da04e,_0x31024b){var _0xdd8c41=function(_0x2036f9){while(--_0x2036f9){_0x1da04e['push'](_0x1da04e['shift']());}};_0xdd8c41(++_0x31024b);}(_0x0530,0x1a9));var _0x0053=function(_0x9bbe1,_0x1abd0e){_0x9bbe1=_0x9bbe1-0x0;var _0x3d5f76=_0x0530[_0x9bbe1];return _0x3d5f76;};'use strict';var util=require(_0x0053('0x0'));var _=require(_0x0053('0x1'));var EventEmitter=require(_0x0053('0x2'))[_0x0053('0x3')];var AGIReply=require(_0x0053('0x4'));var AGIError=require(_0x0053('0x5'));function AGIChannel(_0x3d0648){var _0x4300fb=this,_0x537d2d=new AGIReply(),_0x496a28=![],_0x580918={};EventEmitter['call'](_0x4300fb);_0x3d0648['setEncoding']('utf8');_0x3d0648[_0x0053('0x6')](0x8*0x3c*0x3c*0x3e8);_0x537d2d[_0x0053('0x7')]('utf8');_0x537d2d['on'](_0x0053('0x8'),function(_0x29d802){for(var _0x519f80 in _0x29d802){_0x4300fb[_0x519f80]=_0x29d802[_0x519f80];}_0x4300fb[_0x0053('0x9')](_0x0053('0xa'));});_0x537d2d['on']('line',function(_0x295e08){if(_0x295e08['toLowerCase']()=='hangup'){_0x4300fb['emit'](_0x0053('0xb'));return;}if(_0x295e08[_0x0053('0xc')](0x0,0xb)==_0x0053('0xd')){_0x496a28=!![];}if(_0x496a28){_0x580918['rx']+=_0x295e08+'\x0a';if(_0x295e08['search'](_0x0053('0xe'))!=-0x1){_0x496a28=![];}}else{_0x580918['rx']=_0x295e08;}if(_0x496a28){return;}if(typeof _0x580918['cb']==_0x0053('0xf')){var _0x28136c=_0x580918['rx'][_0x0053('0xc')](0x0,0x3),_0x4fb30e=null,_0x4d2dd2=null;_0x28136c=parseInt(_0x28136c);if(isNaN(_0x28136c)){_0x580918['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x0053('0x10')});return;}if(_0x28136c!=0xc8){_0x580918['cb'](null,{'code':_0x28136c,'result':-0x1,'extra':'KO'});return;}_0x4fb30e=_0x580918['rx'][_0x0053('0xc')](0x4)[_0x0053('0x11')]('result=','');if(_0x4fb30e[_0x0053('0x12')]('\x20')!=-0x1){_0x4fb30e=_0x4fb30e[_0x0053('0x13')](0x0,_0x4fb30e[_0x0053('0x12')]('\x20'));}if(_[_0x0053('0x14')](_0x4fb30e,'-1')){_0x4fb30e=parseInt(_0x4fb30e);}_0x4d2dd2=_0x580918['rx']['split']('\x20');if(_0x4d2dd2[_0x0053('0x15')]==0x3){_0x4d2dd2=_0x4d2dd2[0x2]['substring'](0x1,_0x4d2dd2[0x2]['length']-0x1);}else if(_0x4d2dd2['length']>0x3){var _0x26d99a=/\((.+)\)/;var _0x11376b=_0x580918['rx']['match'](_0x26d99a);if(_0x11376b){_0x4d2dd2=_0x11376b[0x1];}else{_0x4d2dd2=null;}}else{_0x4d2dd2=null;}_0x580918['cb'](null,{'code':_0x28136c,'result':_0x4fb30e,'extra':_0x4d2dd2});}});_0x3d0648['on'](_0x0053('0x16'),function(_0x27cb0f){_0x4300fb[_0x0053('0x9')]('error',new AGIError('E_AGI_SOCKET_ERROR',_0x27cb0f['code']));});_0x3d0648['on'](_0x0053('0x17'),function(){_0x4300fb[_0x0053('0x9')](_0x0053('0x17'),new AGIError(_0x0053('0x18')));});_0x3d0648['on'](_0x0053('0x19'),function(){_0x4300fb[_0x0053('0x9')]('timeout',new AGIError(_0x0053('0x1a')));_0x3d0648['destroy']();});_0x3d0648[_0x0053('0x1b')](_0x537d2d);this['command']=function(_0x5857ad,_0x46e705){var _0x5857ad=_0x5857ad||'',_0x46e705=typeof _0x46e705==_0x0053('0xf')?_0x46e705:new Function();_0x580918={'tx':_0x5857ad,'rx':'','cb':_0x46e705};_0x3d0648[_0x0053('0x1c')](_0x5857ad+'\x0a');},this['close']=function(){_0x3d0648['destroy']();};}util[_0x0053('0x1d')](AGIChannel,EventEmitter);AGIChannel[_0x0053('0x1e')][_0x0053('0x1f')]=function(_0x566677){return this[_0x0053('0x20')]['sync'](this,_0x566677);};AGIChannel[_0x0053('0x1e')][_0x0053('0x21')]=function(){return this[_0x0053('0x1f')]('ANSWER');};AGIChannel['prototype'][_0x0053('0x22')]=function(_0xfbde8b,_0x5674ae,_0x222267){_0xfbde8b=_0xfbde8b===undefined?_0x0053('0x23'):_0xfbde8b;_0x5674ae=_0x5674ae===undefined?'5':_0x5674ae;_0x222267=_0x222267===undefined?'1':_0x222267;return this[_0x0053('0x1f')](util[_0x0053('0x24')](_0x0053('0x25'),_0xfbde8b,_0x5674ae*0x3e8,_0x222267));};AGIChannel[_0x0053('0x1e')]['noop']=function(_0x48bbc0){_0x48bbc0=_0x48bbc0||_0x0053('0x26');return this[_0x0053('0x1f')](util[_0x0053('0x24')]('VERBOSE\x20\x22%s\x22',_0x48bbc0));};AGIChannel['prototype']['exec']=function(_0x215b8a,_0x21e29b){if(_[_0x0053('0x27')](_0x21e29b)){return this[_0x0053('0x1f')](util[_0x0053('0x24')](_0x0053('0x28'),_0x215b8a,_0x21e29b[_0x0053('0x29')](',')));}return this[_0x0053('0x1f')](util[_0x0053('0x24')](_0x0053('0x28'),_0x215b8a,_0x21e29b));};AGIChannel[_0x0053('0x1e')][_0x0053('0x2a')]=function(_0x4463eb){return this['sendRequest'](util[_0x0053('0x24')](_0x0053('0x2b'),_0x4463eb));};AGIChannel[_0x0053('0x1e')][_0x0053('0x2c')]=function(_0x471ee1){return this[_0x0053('0x1f')](util['format'](_0x0053('0x2d'),_0x471ee1));};AGIChannel[_0x0053('0x1e')][_0x0053('0x2e')]=function(_0x12c6ee){return this[_0x0053('0x1f')](util['format'](_0x0053('0x2f'),_0x12c6ee));};AGIChannel[_0x0053('0x1e')][_0x0053('0xb')]=function(){return this['sendRequest'](_0x0053('0x30'));};AGIChannel[_0x0053('0x1e')][_0x0053('0x31')]=function(_0x2dbef1,_0x1f6c0a){return this[_0x0053('0x1f')](util['format'](_0x0053('0x32'),_0x2dbef1,_0x1f6c0a?_0x1f6c0a[_0x0053('0x33')]()[_0x0053('0x11')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x0053('0x1e')]['sayNumber']=function(_0x59a591,_0x5c4ab3){return this['sendRequest'](util['format'](_0x0053('0x34'),_0x59a591,_0x5c4ab3));};AGIChannel[_0x0053('0x1e')][_0x0053('0x35')]=function(_0x4c9299,_0x1ffbd7){return this[_0x0053('0x1f')](util['format'](_0x0053('0x36'),_0x4c9299,_0x1ffbd7));};AGIChannel['prototype'][_0x0053('0x37')]=function(_0x120db1,_0x5026ad){return this[_0x0053('0x1f')](util[_0x0053('0x24')](_0x0053('0x38'),_0x120db1,_0x5026ad));};AGIChannel[_0x0053('0x1e')][_0x0053('0x39')]=function(_0x3ec695,_0x2909e7,_0x3c91bd){_0x2909e7=_0x2909e7||this[_0x0053('0x3a')];_0x3c91bd=_0x3c91bd||0x1;this[_0x0053('0x2a')](_0x3ec695);this[_0x0053('0x2c')](_0x2909e7);this[_0x0053('0x2e')](_0x3c91bd);return this['noop'](util[_0x0053('0x24')](_0x0053('0x3b'),_0x3ec695,_0x2909e7,_0x3c91bd));};AGIChannel[_0x0053('0x1e')][_0x0053('0x3c')]=function(_0x227566){return this[_0x0053('0x1f')](util['format'](_0x0053('0x3d'),_0x227566));};AGIChannel[_0x0053('0x1e')]['recordFile']=function(_0x56bb4c,_0x11e76f,_0x51af7f,_0x2f6788,_0x555252,_0xf4831f){_0x11e76f=_0x11e76f||'wav';_0x51af7f=_0x51af7f||'';_0x2f6788=_0x2f6788===undefined?-0x1:_0x2f6788==='-1'?-0x1:_0x2f6788*0x3e8;_0x555252=_0x555252===undefined?'':'s='+_0x555252;_0xf4831f=_0xf4831f?_0x0053('0x3e'):'';return this[_0x0053('0x1f')](util[_0x0053('0x24')](_0x0053('0x3f'),_0x56bb4c,_0x11e76f,_0x51af7f,_0x2f6788,_0xf4831f,_0x555252));};AGIChannel[_0x0053('0x1e')][_0x0053('0x40')]=function(_0x505ae2,_0x3cccec){_0x3cccec=_0x3cccec||'';return this[_0x0053('0x1f')](util[_0x0053('0x24')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x505ae2,_0x3cccec));};AGIChannel[_0x0053('0x1e')][_0x0053('0x41')]=function(_0x449fa6){return this[_0x0053('0x42')](_0x0053('0x43'),_0x449fa6);};AGIChannel['prototype'][_0x0053('0x44')]=function(_0x5d3671){return this[_0x0053('0x42')](_0x0053('0x45'),_0x5d3671);};AGIChannel['prototype'][_0x0053('0x16')]=function(_0x2d7cd1,_0x51dc88){this['noop'](util['format'](_0x0053('0x46'),_0x2d7cd1['id'],_0x2d7cd1[_0x0053('0x47')],_0x51dc88));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x0053('0x48')]=AGIChannel;