84de36b7a3ecb989d654d4d4f8e940b22959119c
[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 _0xe685=['events','EventEmitter','./reply','./error','call','setEncoding','utf8','setTimeout','headers','emit','toLowerCase','hangup','520-Invalid','search','520\x20End\x20of\x20proper','function','substring','no\x20code','replace','result=','indexOf','substr','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','write','inherits','sendRequest','prototype','ANSWER','beep','format','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isNumber','SET\x20VARIABLE\x20%s\x20\x22%s\x22','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','extension','setPriority','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','agi','wait','label','exports','lodash'];(function(_0x41e434,_0x30cf78){var _0x2956b2=function(_0xa19a26){while(--_0xa19a26){_0x41e434['push'](_0x41e434['shift']());}};_0x2956b2(++_0x30cf78);}(_0xe685,0xe0));var _0x5e68=function(_0x579d8a,_0x1b8acd){_0x579d8a=_0x579d8a-0x0;var _0x45a91a=_0xe685[_0x579d8a];return _0x45a91a;};'use strict';var util=require('util');var _=require(_0x5e68('0x0'));var EventEmitter=require(_0x5e68('0x1'))[_0x5e68('0x2')];var AGIReply=require(_0x5e68('0x3'));var AGIError=require(_0x5e68('0x4'));function AGIChannel(_0xd1426){var _0x126247=this,_0xb3a1d0=new AGIReply(),_0x36653c=![],_0x478f3a={};EventEmitter[_0x5e68('0x5')](_0x126247);_0xd1426[_0x5e68('0x6')](_0x5e68('0x7'));_0xd1426[_0x5e68('0x8')](0x8*0x3c*0x3c*0x3e8);_0xb3a1d0['setEncoding'](_0x5e68('0x7'));_0xb3a1d0['on'](_0x5e68('0x9'),function(_0x12cf24){for(var _0x31d03c in _0x12cf24){_0x126247[_0x31d03c]=_0x12cf24[_0x31d03c];}_0x126247[_0x5e68('0xa')]('ready');});_0xb3a1d0['on']('line',function(_0x13077c){if(_0x13077c[_0x5e68('0xb')]()==_0x5e68('0xc')){_0x126247[_0x5e68('0xa')](_0x5e68('0xc'));return;}if(_0x13077c['substring'](0x0,0xb)==_0x5e68('0xd')){_0x36653c=!![];}if(_0x36653c){_0x478f3a['rx']+=_0x13077c+'\x0a';if(_0x13077c[_0x5e68('0xe')](_0x5e68('0xf'))!=-0x1){_0x36653c=![];}}else{_0x478f3a['rx']=_0x13077c;}if(_0x36653c){return;}if(typeof _0x478f3a['cb']==_0x5e68('0x10')){var _0x5a32cd=_0x478f3a['rx'][_0x5e68('0x11')](0x0,0x3),_0x187516=null,_0x32e995=null;_0x5a32cd=parseInt(_0x5a32cd);if(isNaN(_0x5a32cd)){_0x478f3a['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x5e68('0x12')});return;}if(_0x5a32cd!=0xc8){_0x478f3a['cb'](null,{'code':_0x5a32cd,'result':-0x1,'extra':'KO'});return;}_0x187516=_0x478f3a['rx'][_0x5e68('0x11')](0x4)[_0x5e68('0x13')](_0x5e68('0x14'),'');if(_0x187516[_0x5e68('0x15')]('\x20')!=-0x1){_0x187516=_0x187516[_0x5e68('0x16')](0x0,_0x187516['indexOf']('\x20'));}if(_[_0x5e68('0x17')](_0x187516,'-1')){_0x187516=parseInt(_0x187516);}_0x32e995=_0x478f3a['rx'][_0x5e68('0x18')]('\x20');if(_0x32e995['length']==0x3){_0x32e995=_0x32e995[0x2][_0x5e68('0x11')](0x1,_0x32e995[0x2]['length']-0x1);}else if(_0x32e995[_0x5e68('0x19')]>0x3){var _0xd82104=/\((.+)\)/;var _0x3e5bfb=_0x478f3a['rx'][_0x5e68('0x1a')](_0xd82104);if(_0x3e5bfb){_0x32e995=_0x3e5bfb[0x1];}else{_0x32e995=null;}}else{_0x32e995=null;}_0x478f3a['cb'](null,{'code':_0x5a32cd,'result':_0x187516,'extra':_0x32e995});}});_0xd1426['on'](_0x5e68('0x1b'),function(_0x334fb1){_0x126247['emit'](_0x5e68('0x1b'),new AGIError(_0x5e68('0x1c'),_0x334fb1[_0x5e68('0x1d')]));});_0xd1426['on'](_0x5e68('0x1e'),function(){_0x126247['emit'](_0x5e68('0x1e'),new AGIError('E_AGI_SOCKET_CLOSE'));});_0xd1426['on'](_0x5e68('0x1f'),function(){_0x126247[_0x5e68('0xa')](_0x5e68('0x1f'),new AGIError(_0x5e68('0x20')));_0xd1426[_0x5e68('0x21')]();});_0xd1426[_0x5e68('0x22')](_0xb3a1d0);this[_0x5e68('0x23')]=function(_0xe54e47,_0x59eb61){var _0xe54e47=_0xe54e47||'',_0x59eb61=typeof _0x59eb61==_0x5e68('0x10')?_0x59eb61:new Function();_0x478f3a={'tx':_0xe54e47,'rx':'','cb':_0x59eb61};_0xd1426[_0x5e68('0x24')](_0xe54e47+'\x0a');},this[_0x5e68('0x1e')]=function(){_0xd1426[_0x5e68('0x21')]();};}util[_0x5e68('0x25')](AGIChannel,EventEmitter);AGIChannel['prototype'][_0x5e68('0x26')]=function(_0x45fac8){return this[_0x5e68('0x23')]['sync'](this,_0x45fac8);};AGIChannel[_0x5e68('0x27')]['answer']=function(){return this[_0x5e68('0x26')](_0x5e68('0x28'));};AGIChannel[_0x5e68('0x27')]['getData']=function(_0xa9ccb6,_0x3a0f13,_0x3f4f08){_0xa9ccb6=_0xa9ccb6===undefined?_0x5e68('0x29'):_0xa9ccb6;_0x3a0f13=_0x3a0f13===undefined?'5':_0x3a0f13;_0x3f4f08=_0x3f4f08===undefined?'1':_0x3f4f08;return this[_0x5e68('0x26')](util[_0x5e68('0x2a')]('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0xa9ccb6,_0x3a0f13*0x3e8,_0x3f4f08));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x2b')]=function(_0x1de093){_0x1de093=_0x1de093||_0x5e68('0x2c');return this['sendRequest'](util[_0x5e68('0x2a')](_0x5e68('0x2d'),_0x1de093));};AGIChannel['prototype'][_0x5e68('0x2e')]=function(_0x43c7f6,_0x4e5538){if(_['isArray'](_0x4e5538)){return this['sendRequest'](util[_0x5e68('0x2a')](_0x5e68('0x2f'),_0x43c7f6,_0x4e5538[_0x5e68('0x30')](',')));}return this[_0x5e68('0x26')](util[_0x5e68('0x2a')](_0x5e68('0x2f'),_0x43c7f6,_0x4e5538));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x31')]=function(_0x2eada6){return this[_0x5e68('0x26')](util['format'](_0x5e68('0x32'),_0x2eada6));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x33')]=function(_0x4fe757){return this[_0x5e68('0x26')](util[_0x5e68('0x2a')](_0x5e68('0x34'),_0x4fe757));};AGIChannel[_0x5e68('0x27')]['setPriority']=function(_0x11884b){return this[_0x5e68('0x26')](util[_0x5e68('0x2a')](_0x5e68('0x35'),_0x11884b));};AGIChannel[_0x5e68('0x27')]['hangup']=function(){return this[_0x5e68('0x26')](_0x5e68('0x36'));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x37')]=function(_0x2165c0,_0x1521b0){var _0x5c2dcf=_['isBoolean'](_0x1521b0)||_[_0x5e68('0x38')](_0x1521b0)?_0x1521b0['toString']():_0x1521b0;return this[_0x5e68('0x26')](util[_0x5e68('0x2a')](_0x5e68('0x39'),_0x2165c0,_0x5c2dcf?_0x5c2dcf['toString']()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel['prototype']['sayNumber']=function(_0x1e979e,_0x306946){return this['sendRequest'](util['format']('SAY\x20NUMBER\x20%s\x20%s',_0x1e979e,_0x306946));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x3a')]=function(_0x733ae2,_0xecfe74){return this['sendRequest'](util[_0x5e68('0x2a')](_0x5e68('0x3b'),_0x733ae2,_0xecfe74));};AGIChannel['prototype'][_0x5e68('0x3c')]=function(_0x419615,_0x3039fc){return this['sendRequest'](util['format'](_0x5e68('0x3d'),_0x419615,_0x3039fc));};AGIChannel[_0x5e68('0x27')]['continueAt']=function(_0x382384,_0x54ae44,_0x104303){_0x54ae44=_0x54ae44||this[_0x5e68('0x3e')];_0x104303=_0x104303||0x1;this['setContext'](_0x382384);this[_0x5e68('0x33')](_0x54ae44);this[_0x5e68('0x3f')](_0x104303);return this[_0x5e68('0x2b')](util[_0x5e68('0x2a')](_0x5e68('0x40'),_0x382384,_0x54ae44,_0x104303));};AGIChannel['prototype'][_0x5e68('0x41')]=function(_0x492c6c){return this['sendRequest'](util[_0x5e68('0x2a')](_0x5e68('0x42'),_0x492c6c));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x43')]=function(_0x23b337,_0x5132b6,_0x17c8fd,_0x1b5ef2,_0x1cf466,_0x3c8e00){_0x5132b6=_0x5132b6||_0x5e68('0x44');_0x17c8fd=_0x17c8fd||'';_0x1b5ef2=_0x1b5ef2===undefined?-0x1:_0x1b5ef2==='-1'?-0x1:_0x1b5ef2*0x3e8;_0x1cf466=_0x1cf466===undefined?'':'s='+_0x1cf466;_0x3c8e00=_0x3c8e00?'BEEP':'';return this[_0x5e68('0x26')](util[_0x5e68('0x2a')](_0x5e68('0x45'),_0x23b337,_0x5132b6,_0x17c8fd,_0x1b5ef2,_0x3c8e00,_0x1cf466));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x46')]=function(_0x156856,_0x1e56ed){_0x1e56ed=_0x1e56ed||'';return this['sendRequest'](util[_0x5e68('0x2a')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x156856,_0x1e56ed));};AGIChannel[_0x5e68('0x27')][_0x5e68('0x47')]=function(_0x452a04){return this['exec']('AGI',_0x452a04);};AGIChannel['prototype'][_0x5e68('0x48')]=function(_0xf9c2d6){return this[_0x5e68('0x2e')]('WAIT',_0xf9c2d6);};AGIChannel[_0x5e68('0x27')]['error']=function(_0x34cbb0,_0x5f0cb4){this[_0x5e68('0x2b')](util[_0x5e68('0x2a')]('ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s',_0x34cbb0['id'],_0x34cbb0[_0x5e68('0x49')],_0x5f0cb4));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x5e68('0x4a')]=AGIChannel;