74aad13b1f0bdf44db916574fa117253555a278c
[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 _0x60ff=['substr','indexOf','split','length','match','E_AGI_SOCKET_ERROR','code','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','write','close','inherits','prototype','sendRequest','sync','answer','ANSWER','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','isArray','EXEC\x20%s\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','setContext','GOTO\x20%s\x20%s\x20%s','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','agi','AGI','wait','exec','WAIT','error','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','EventEmitter','./reply','./error','call','setEncoding','utf8','setTimeout','headers','emit','ready','line','toLowerCase','hangup','substring','520-Invalid','520\x20End\x20of\x20proper','function','replace','result='];(function(_0x3e30a8,_0x257732){var _0x5d5d1d=function(_0x2987f1){while(--_0x2987f1){_0x3e30a8['push'](_0x3e30a8['shift']());}};_0x5d5d1d(++_0x257732);}(_0x60ff,0x1e2));var _0xf60f=function(_0x16b477,_0x2935c8){_0x16b477=_0x16b477-0x0;var _0x49287d=_0x60ff[_0x16b477];return _0x49287d;};'use strict';var util=require(_0xf60f('0x0'));var _=require(_0xf60f('0x1'));var EventEmitter=require(_0xf60f('0x2'))[_0xf60f('0x3')];var AGIReply=require(_0xf60f('0x4'));var AGIError=require(_0xf60f('0x5'));function AGIChannel(_0x12d046){var _0x317360=this,_0x1b9ae4=new AGIReply(),_0x56bd39=![],_0x53607d={};EventEmitter[_0xf60f('0x6')](_0x317360);_0x12d046[_0xf60f('0x7')](_0xf60f('0x8'));_0x12d046[_0xf60f('0x9')](0x8*0x3c*0x3c*0x3e8);_0x1b9ae4[_0xf60f('0x7')](_0xf60f('0x8'));_0x1b9ae4['on'](_0xf60f('0xa'),function(_0x912773){for(var _0x231774 in _0x912773){_0x317360[_0x231774]=_0x912773[_0x231774];}_0x317360[_0xf60f('0xb')](_0xf60f('0xc'));});_0x1b9ae4['on'](_0xf60f('0xd'),function(_0x1944dd){if(_0x1944dd[_0xf60f('0xe')]()=='hangup'){_0x317360[_0xf60f('0xb')](_0xf60f('0xf'));return;}if(_0x1944dd[_0xf60f('0x10')](0x0,0xb)==_0xf60f('0x11')){_0x56bd39=!![];}if(_0x56bd39){_0x53607d['rx']+=_0x1944dd+'\x0a';if(_0x1944dd['search'](_0xf60f('0x12'))!=-0x1){_0x56bd39=![];}}else{_0x53607d['rx']=_0x1944dd;}if(_0x56bd39){return;}if(typeof _0x53607d['cb']==_0xf60f('0x13')){var _0x377c45=_0x53607d['rx'][_0xf60f('0x10')](0x0,0x3),_0x5c1361=null,_0xe0f6de=null;_0x377c45=parseInt(_0x377c45);if(isNaN(_0x377c45)){_0x53607d['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x377c45!=0xc8){_0x53607d['cb'](null,{'code':_0x377c45,'result':-0x1,'extra':'KO'});return;}_0x5c1361=_0x53607d['rx'][_0xf60f('0x10')](0x4)[_0xf60f('0x14')](_0xf60f('0x15'),'');if(_0x5c1361['indexOf']('\x20')!=-0x1){_0x5c1361=_0x5c1361[_0xf60f('0x16')](0x0,_0x5c1361[_0xf60f('0x17')]('\x20'));}if(_['startsWith'](_0x5c1361,'-1')){_0x5c1361=parseInt(_0x5c1361);}_0xe0f6de=_0x53607d['rx'][_0xf60f('0x18')]('\x20');if(_0xe0f6de[_0xf60f('0x19')]==0x3){_0xe0f6de=_0xe0f6de[0x2][_0xf60f('0x10')](0x1,_0xe0f6de[0x2][_0xf60f('0x19')]-0x1);}else if(_0xe0f6de[_0xf60f('0x19')]>0x3){var _0x5254d6=/\((.+)\)/;var _0x586294=_0x53607d['rx'][_0xf60f('0x1a')](_0x5254d6);if(_0x586294){_0xe0f6de=_0x586294[0x1];}else{_0xe0f6de=null;}}else{_0xe0f6de=null;}_0x53607d['cb'](null,{'code':_0x377c45,'result':_0x5c1361,'extra':_0xe0f6de});}});_0x12d046['on']('error',function(_0x4791dc){_0x317360[_0xf60f('0xb')]('error',new AGIError(_0xf60f('0x1b'),_0x4791dc[_0xf60f('0x1c')]));});_0x12d046['on']('close',function(){_0x317360[_0xf60f('0xb')]('close',new AGIError(_0xf60f('0x1d')));});_0x12d046['on'](_0xf60f('0x1e'),function(){_0x317360[_0xf60f('0xb')](_0xf60f('0x1e'),new AGIError(_0xf60f('0x1f')));_0x12d046[_0xf60f('0x20')]();});_0x12d046[_0xf60f('0x21')](_0x1b9ae4);this[_0xf60f('0x22')]=function(_0x4bc66f,_0x3ccf78){var _0x4bc66f=_0x4bc66f||'',_0x3ccf78=typeof _0x3ccf78==_0xf60f('0x13')?_0x3ccf78:new Function();_0x53607d={'tx':_0x4bc66f,'rx':'','cb':_0x3ccf78};_0x12d046[_0xf60f('0x23')](_0x4bc66f+'\x0a');},this[_0xf60f('0x24')]=function(){_0x12d046['destroy']();};}util[_0xf60f('0x25')](AGIChannel,EventEmitter);AGIChannel[_0xf60f('0x26')][_0xf60f('0x27')]=function(_0x404859){return this[_0xf60f('0x22')][_0xf60f('0x28')](this,_0x404859);};AGIChannel[_0xf60f('0x26')][_0xf60f('0x29')]=function(){return this[_0xf60f('0x27')](_0xf60f('0x2a'));};AGIChannel[_0xf60f('0x26')]['getData']=function(_0x26cfba,_0x20be13,_0x5878c5){_0x26cfba=_0x26cfba===undefined?_0xf60f('0x2b'):_0x26cfba;_0x20be13=_0x20be13===undefined?'5':_0x20be13;_0x5878c5=_0x5878c5===undefined?'1':_0x5878c5;return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x2d'),_0x26cfba,_0x20be13*0x3e8,_0x5878c5));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x2e')]=function(_0x587e54){_0x587e54=_0x587e54||_0xf60f('0x2f');return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x30'),_0x587e54));};AGIChannel['prototype']['exec']=function(_0x4e6557,_0x3f7ad9){if(_[_0xf60f('0x31')](_0x3f7ad9)){return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x32'),_0x4e6557,_0x3f7ad9['join'](',')));}return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x32'),_0x4e6557,_0x3f7ad9));};AGIChannel[_0xf60f('0x26')]['setContext']=function(_0x201ead){return this[_0xf60f('0x27')](util[_0xf60f('0x2c')]('SET\x20CONTEXT\x20%s',_0x201ead));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x33')]=function(_0x48d362){return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x34'),_0x48d362));};AGIChannel['prototype'][_0xf60f('0x35')]=function(_0x2d32dd){return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x36'),_0x2d32dd));};AGIChannel['prototype'][_0xf60f('0xf')]=function(){return this[_0xf60f('0x27')](_0xf60f('0x37'));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x38')]=function(_0x31b4f1,_0x49bb7e){var _0x493a3e=_[_0xf60f('0x39')](_0x49bb7e)||_[_0xf60f('0x3a')](_0x49bb7e)?_0x49bb7e[_0xf60f('0x3b')]():_0x49bb7e;return this['sendRequest'](util[_0xf60f('0x2c')](_0xf60f('0x3c'),_0x31b4f1,_0x493a3e?_0x493a3e[_0xf60f('0x3b')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x3d')]=function(_0x536f9f,_0x17922a){return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x3e'),_0x536f9f,_0x17922a));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x3f')]=function(_0xb4b221,_0x20b24b){return this['sendRequest'](util['format'](_0xf60f('0x40'),_0xb4b221,_0x20b24b));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x41')]=function(_0x50e818,_0x35780e){return this[_0xf60f('0x27')](util[_0xf60f('0x2c')](_0xf60f('0x42'),_0x50e818,_0x35780e));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x43')]=function(_0x3e5dd5,_0x15c65f,_0x2fa70e){_0x15c65f=_0x15c65f||this['extension'];_0x2fa70e=_0x2fa70e||0x1;this[_0xf60f('0x44')](_0x3e5dd5);this[_0xf60f('0x33')](_0x15c65f);this[_0xf60f('0x35')](_0x2fa70e);return this[_0xf60f('0x2e')](util[_0xf60f('0x2c')](_0xf60f('0x45'),_0x3e5dd5,_0x15c65f,_0x2fa70e));};AGIChannel[_0xf60f('0x26')]['getVariable']=function(_0x35ec5b){return this[_0xf60f('0x27')](util['format'](_0xf60f('0x46'),_0x35ec5b));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x47')]=function(_0x1b5361,_0x419e2d,_0x570354,_0x40709d,_0x5af29f,_0x5aa8e2){_0x419e2d=_0x419e2d||_0xf60f('0x48');_0x570354=_0x570354||'';_0x40709d=_0x40709d===undefined?-0x1:_0x40709d==='-1'?-0x1:_0x40709d*0x3e8;_0x5af29f=_0x5af29f===undefined?'':'s='+_0x5af29f;_0x5aa8e2=_0x5aa8e2?_0xf60f('0x49'):'';return this['sendRequest'](util[_0xf60f('0x2c')](_0xf60f('0x4a'),_0x1b5361,_0x419e2d,_0x570354,_0x40709d,_0x5aa8e2,_0x5af29f));};AGIChannel[_0xf60f('0x26')]['streamFile']=function(_0x551888,_0x5baf0a){_0x5baf0a=_0x5baf0a||'';return this[_0xf60f('0x27')](util['format']('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x551888,_0x5baf0a));};AGIChannel[_0xf60f('0x26')][_0xf60f('0x4b')]=function(_0x3f753c){return this['exec'](_0xf60f('0x4c'),_0x3f753c);};AGIChannel[_0xf60f('0x26')][_0xf60f('0x4d')]=function(_0x28417f){return this[_0xf60f('0x4e')](_0xf60f('0x4f'),_0x28417f);};AGIChannel[_0xf60f('0x26')][_0xf60f('0x50')]=function(_0x2d455e,_0x5d729f){this[_0xf60f('0x2e')](util['format'](_0xf60f('0x51'),_0x2d455e['id'],_0x2d455e[_0xf60f('0x52')],_0x5d729f));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xf60f('0x53')]=AGIChannel;