Built motion from commit (unavailable).|2.3.9
[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 _0xae04=['prototype','answer','sendRequest','ANSWER','beep','noop','NO\x20MESSAGE','format','exec','isArray','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','hangup','HANGUP','setVariable','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','streamFile','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','wait','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','EventEmitter','./reply','./error','call','setEncoding','utf8','emit','ready','line','toLowerCase','substring','520-Invalid','search','no\x20code','result=','indexOf','substr','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','command'];(function(_0x1b660d,_0x443a47){var _0x423829=function(_0x348f01){while(--_0x348f01){_0x1b660d['push'](_0x1b660d['shift']());}};_0x423829(++_0x443a47);}(_0xae04,0x151));var _0x4ae0=function(_0xa08526,_0xd2a376){_0xa08526=_0xa08526-0x0;var _0x2684eb=_0xae04[_0xa08526];return _0x2684eb;};'use strict';var util=require(_0x4ae0('0x0'));var _=require(_0x4ae0('0x1'));var EventEmitter=require(_0x4ae0('0x2'))[_0x4ae0('0x3')];var AGIReply=require(_0x4ae0('0x4'));var AGIError=require(_0x4ae0('0x5'));function AGIChannel(_0x37153c){var _0x4eebda=this,_0x4991da=new AGIReply(),_0x14eae2=![],_0x49a8a7={};EventEmitter[_0x4ae0('0x6')](_0x4eebda);_0x37153c[_0x4ae0('0x7')](_0x4ae0('0x8'));_0x37153c['setTimeout'](0x8*0x3c*0x3c*0x3e8);_0x4991da[_0x4ae0('0x7')](_0x4ae0('0x8'));_0x4991da['on']('headers',function(_0x4fb7d7){for(var _0x1b0446 in _0x4fb7d7){_0x4eebda[_0x1b0446]=_0x4fb7d7[_0x1b0446];}_0x4eebda[_0x4ae0('0x9')](_0x4ae0('0xa'));});_0x4991da['on'](_0x4ae0('0xb'),function(_0x1c285f){if(_0x1c285f[_0x4ae0('0xc')]()=='hangup'){_0x4eebda['emit']('hangup');return;}if(_0x1c285f[_0x4ae0('0xd')](0x0,0xb)==_0x4ae0('0xe')){_0x14eae2=!![];}if(_0x14eae2){_0x49a8a7['rx']+=_0x1c285f+'\x0a';if(_0x1c285f[_0x4ae0('0xf')]('520\x20End\x20of\x20proper')!=-0x1){_0x14eae2=![];}}else{_0x49a8a7['rx']=_0x1c285f;}if(_0x14eae2){return;}if(typeof _0x49a8a7['cb']=='function'){var _0x3425d8=_0x49a8a7['rx'][_0x4ae0('0xd')](0x0,0x3),_0x2f7dc9=null,_0x42fd8d=null;_0x3425d8=parseInt(_0x3425d8);if(isNaN(_0x3425d8)){_0x49a8a7['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x4ae0('0x10')});return;}if(_0x3425d8!=0xc8){_0x49a8a7['cb'](null,{'code':_0x3425d8,'result':-0x1,'extra':'KO'});return;}_0x2f7dc9=_0x49a8a7['rx'][_0x4ae0('0xd')](0x4)['replace'](_0x4ae0('0x11'),'');if(_0x2f7dc9[_0x4ae0('0x12')]('\x20')!=-0x1){_0x2f7dc9=_0x2f7dc9[_0x4ae0('0x13')](0x0,_0x2f7dc9[_0x4ae0('0x12')]('\x20'));}if(_[_0x4ae0('0x14')](_0x2f7dc9,'-1')){_0x2f7dc9=parseInt(_0x2f7dc9);}_0x42fd8d=_0x49a8a7['rx'][_0x4ae0('0x15')]('\x20');if(_0x42fd8d[_0x4ae0('0x16')]==0x3){_0x42fd8d=_0x42fd8d[0x2][_0x4ae0('0xd')](0x1,_0x42fd8d[0x2][_0x4ae0('0x16')]-0x1);}else if(_0x42fd8d[_0x4ae0('0x16')]>0x3){var _0x33cc45=/\((.+)\)/;var _0x4769b0=_0x49a8a7['rx'][_0x4ae0('0x17')](_0x33cc45);if(_0x4769b0){_0x42fd8d=_0x4769b0[0x1];}else{_0x42fd8d=null;}}else{_0x42fd8d=null;}_0x49a8a7['cb'](null,{'code':_0x3425d8,'result':_0x2f7dc9,'extra':_0x42fd8d});}});_0x37153c['on'](_0x4ae0('0x18'),function(_0x5ae926){_0x4eebda[_0x4ae0('0x9')](_0x4ae0('0x18'),new AGIError(_0x4ae0('0x19'),_0x5ae926[_0x4ae0('0x1a')]));});_0x37153c['on']('close',function(){_0x4eebda[_0x4ae0('0x9')](_0x4ae0('0x1b'),new AGIError(_0x4ae0('0x1c')));});_0x37153c['on'](_0x4ae0('0x1d'),function(){_0x4eebda['emit'](_0x4ae0('0x1d'),new AGIError(_0x4ae0('0x1e')));_0x37153c[_0x4ae0('0x1f')]();});_0x37153c['pipe'](_0x4991da);this[_0x4ae0('0x20')]=function(_0x5cbd59,_0x3488ed){var _0x5cbd59=_0x5cbd59||'',_0x3488ed=typeof _0x3488ed=='function'?_0x3488ed:new Function();_0x49a8a7={'tx':_0x5cbd59,'rx':'','cb':_0x3488ed};_0x37153c['write'](_0x5cbd59+'\x0a');},this[_0x4ae0('0x1b')]=function(){_0x37153c[_0x4ae0('0x1f')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel[_0x4ae0('0x21')]['sendRequest']=function(_0x560653){return this['command']['sync'](this,_0x560653);};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x22')]=function(){return this[_0x4ae0('0x23')](_0x4ae0('0x24'));};AGIChannel[_0x4ae0('0x21')]['getData']=function(_0x276ad1,_0x706943,_0x4f0054){_0x276ad1=_0x276ad1===undefined?_0x4ae0('0x25'):_0x276ad1;_0x706943=_0x706943===undefined?'5':_0x706943;_0x4f0054=_0x4f0054===undefined?'1':_0x4f0054;return this[_0x4ae0('0x23')](util['format']('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x276ad1,_0x706943*0x3e8,_0x4f0054));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x26')]=function(_0x2c255b){_0x2c255b=_0x2c255b||_0x4ae0('0x27');return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')]('VERBOSE\x20\x22%s\x22',_0x2c255b));};AGIChannel['prototype'][_0x4ae0('0x29')]=function(_0x3d755f,_0x241adb){if(_[_0x4ae0('0x2a')](_0x241adb)){return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x2b'),_0x3d755f,_0x241adb[_0x4ae0('0x2c')](',')));}return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x2b'),_0x3d755f,_0x241adb));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x2d')]=function(_0x1a5a88){return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x2e'),_0x1a5a88));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x2f')]=function(_0x5f2028){return this['sendRequest'](util['format'](_0x4ae0('0x30'),_0x5f2028));};AGIChannel['prototype'][_0x4ae0('0x31')]=function(_0x18da19){return this['sendRequest'](util[_0x4ae0('0x28')]('SET\x20PRIORITY\x20%s',_0x18da19));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x32')]=function(){return this[_0x4ae0('0x23')](_0x4ae0('0x33'));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x34')]=function(_0x491391,_0x257b34){return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x35'),_0x491391,_0x257b34?_0x257b34[_0x4ae0('0x36')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x37')]=function(_0x4bc241,_0x962d0e){return this[_0x4ae0('0x23')](util['format'](_0x4ae0('0x38'),_0x4bc241,_0x962d0e));};AGIChannel[_0x4ae0('0x21')]['sayDigits']=function(_0x4c5f0a,_0x227ce8){return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x39'),_0x4c5f0a,_0x227ce8));};AGIChannel['prototype'][_0x4ae0('0x3a')]=function(_0x4d8b4a,_0x43f9dc){return this['sendRequest'](util[_0x4ae0('0x28')](_0x4ae0('0x3b'),_0x4d8b4a,_0x43f9dc));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x3c')]=function(_0x550381,_0x3eb194,_0x40d446){_0x3eb194=_0x3eb194||this['extension'];_0x40d446=_0x40d446||0x1;this[_0x4ae0('0x2d')](_0x550381);this['setExtension'](_0x3eb194);this[_0x4ae0('0x31')](_0x40d446);return this[_0x4ae0('0x26')](util['format'](_0x4ae0('0x3d'),_0x550381,_0x3eb194,_0x40d446));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x3e')]=function(_0x5061cc){return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x3f'),_0x5061cc));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x40')]=function(_0x3838e9,_0x333395,_0x2d291c,_0x1797cb,_0x538de1,_0x2b0857){_0x333395=_0x333395||_0x4ae0('0x41');_0x2d291c=_0x2d291c||'';_0x1797cb=_0x1797cb===undefined?-0x1:_0x1797cb==='-1'?-0x1:_0x1797cb*0x3e8;_0x538de1=_0x538de1===undefined?'':'s='+_0x538de1;_0x2b0857=_0x2b0857?_0x4ae0('0x42'):'';return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0x3838e9,_0x333395,_0x2d291c,_0x1797cb,_0x2b0857,_0x538de1));};AGIChannel['prototype'][_0x4ae0('0x43')]=function(_0x3c8714,_0x317fba){_0x317fba=_0x317fba||'';return this[_0x4ae0('0x23')](util[_0x4ae0('0x28')](_0x4ae0('0x44'),_0x3c8714,_0x317fba));};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x45')]=function(_0x23e442){return this[_0x4ae0('0x29')]('AGI',_0x23e442);};AGIChannel[_0x4ae0('0x21')][_0x4ae0('0x46')]=function(_0x3d5f92){return this[_0x4ae0('0x29')]('WAIT',_0x3d5f92);};AGIChannel[_0x4ae0('0x21')]['error']=function(_0x419372,_0x2b930e){this[_0x4ae0('0x26')](util[_0x4ae0('0x28')](_0x4ae0('0x47'),_0x419372['id'],_0x419372[_0x4ae0('0x48')],_0x2b930e));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x4ae0('0x49')]=AGIChannel;