6a24b8d5f655709be8c596b2e01810e11135fb84
[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 _0xf032=['no\x20code','replace','indexOf','substr','startsWith','split','length','match','error','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','write','inherits','prototype','answer','sendRequest','ANSWER','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','exec','isArray','EXEC\x20%s\x20%s','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','noop','GOTO\x20%s\x20%s\x20%s','getVariable','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','streamFile','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','agi','AGI','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','events','./reply','./error','utf8','setTimeout','headers','emit','ready','line','toLowerCase','hangup','substring','520-Invalid','function'];(function(_0x3fce62,_0x2b78f0){var _0x3a04cf=function(_0xbcf4e4){while(--_0xbcf4e4){_0x3fce62['push'](_0x3fce62['shift']());}};_0x3a04cf(++_0x2b78f0);}(_0xf032,0x131));var _0x2f03=function(_0x245cc4,_0x1ce370){_0x245cc4=_0x245cc4-0x0;var _0x137104=_0xf032[_0x245cc4];return _0x137104;};'use strict';var util=require(_0x2f03('0x0'));var _=require('lodash');var EventEmitter=require(_0x2f03('0x1'))['EventEmitter'];var AGIReply=require(_0x2f03('0x2'));var AGIError=require(_0x2f03('0x3'));function AGIChannel(_0xdf3e59){var _0x3eb879=this,_0x43f5d1=new AGIReply(),_0x165c78=![],_0x2977a5={};EventEmitter['call'](_0x3eb879);_0xdf3e59['setEncoding'](_0x2f03('0x4'));_0xdf3e59[_0x2f03('0x5')](0x8*0x3c*0x3c*0x3e8);_0x43f5d1['setEncoding']('utf8');_0x43f5d1['on'](_0x2f03('0x6'),function(_0x17f978){for(var _0x3d24a2 in _0x17f978){_0x3eb879[_0x3d24a2]=_0x17f978[_0x3d24a2];}_0x3eb879[_0x2f03('0x7')](_0x2f03('0x8'));});_0x43f5d1['on'](_0x2f03('0x9'),function(_0x2b9531){if(_0x2b9531[_0x2f03('0xa')]()=='hangup'){_0x3eb879['emit'](_0x2f03('0xb'));return;}if(_0x2b9531[_0x2f03('0xc')](0x0,0xb)==_0x2f03('0xd')){_0x165c78=!![];}if(_0x165c78){_0x2977a5['rx']+=_0x2b9531+'\x0a';if(_0x2b9531['search']('520\x20End\x20of\x20proper')!=-0x1){_0x165c78=![];}}else{_0x2977a5['rx']=_0x2b9531;}if(_0x165c78){return;}if(typeof _0x2977a5['cb']==_0x2f03('0xe')){var _0xa93dad=_0x2977a5['rx'][_0x2f03('0xc')](0x0,0x3),_0x5bcaf0=null,_0xa6ffa=null;_0xa93dad=parseInt(_0xa93dad);if(isNaN(_0xa93dad)){_0x2977a5['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x2f03('0xf')});return;}if(_0xa93dad!=0xc8){_0x2977a5['cb'](null,{'code':_0xa93dad,'result':-0x1,'extra':'KO'});return;}_0x5bcaf0=_0x2977a5['rx'][_0x2f03('0xc')](0x4)[_0x2f03('0x10')]('result=','');if(_0x5bcaf0[_0x2f03('0x11')]('\x20')!=-0x1){_0x5bcaf0=_0x5bcaf0[_0x2f03('0x12')](0x0,_0x5bcaf0['indexOf']('\x20'));}if(_[_0x2f03('0x13')](_0x5bcaf0,'-1')){_0x5bcaf0=parseInt(_0x5bcaf0);}_0xa6ffa=_0x2977a5['rx'][_0x2f03('0x14')]('\x20');if(_0xa6ffa[_0x2f03('0x15')]==0x3){_0xa6ffa=_0xa6ffa[0x2]['substring'](0x1,_0xa6ffa[0x2][_0x2f03('0x15')]-0x1);}else if(_0xa6ffa['length']>0x3){var _0x30e136=/\((.+)\)/;var _0x1aa89b=_0x2977a5['rx'][_0x2f03('0x16')](_0x30e136);if(_0x1aa89b){_0xa6ffa=_0x1aa89b[0x1];}else{_0xa6ffa=null;}}else{_0xa6ffa=null;}_0x2977a5['cb'](null,{'code':_0xa93dad,'result':_0x5bcaf0,'extra':_0xa6ffa});}});_0xdf3e59['on']('error',function(_0x480751){_0x3eb879['emit'](_0x2f03('0x17'),new AGIError('E_AGI_SOCKET_ERROR',_0x480751['code']));});_0xdf3e59['on'](_0x2f03('0x18'),function(){_0x3eb879[_0x2f03('0x7')](_0x2f03('0x18'),new AGIError(_0x2f03('0x19')));});_0xdf3e59['on'](_0x2f03('0x1a'),function(){_0x3eb879[_0x2f03('0x7')]('timeout',new AGIError(_0x2f03('0x1b')));_0xdf3e59[_0x2f03('0x1c')]();});_0xdf3e59[_0x2f03('0x1d')](_0x43f5d1);this['command']=function(_0x5ad27a,_0x22c3e3){var _0x5ad27a=_0x5ad27a||'',_0x22c3e3=typeof _0x22c3e3==_0x2f03('0xe')?_0x22c3e3:new Function();_0x2977a5={'tx':_0x5ad27a,'rx':'','cb':_0x22c3e3};_0xdf3e59[_0x2f03('0x1e')](_0x5ad27a+'\x0a');},this[_0x2f03('0x18')]=function(){_0xdf3e59['destroy']();};}util[_0x2f03('0x1f')](AGIChannel,EventEmitter);AGIChannel[_0x2f03('0x20')]['sendRequest']=function(_0x19b1ea){return this['command']['sync'](this,_0x19b1ea);};AGIChannel[_0x2f03('0x20')][_0x2f03('0x21')]=function(){return this[_0x2f03('0x22')](_0x2f03('0x23'));};AGIChannel['prototype']['getData']=function(_0xe025a9,_0x527a28,_0x559956){_0xe025a9=_0xe025a9===undefined?_0x2f03('0x24'):_0xe025a9;_0x527a28=_0x527a28===undefined?'5':_0x527a28;_0x559956=_0x559956===undefined?'1':_0x559956;return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x26'),_0xe025a9,_0x527a28*0x3e8,_0x559956));};AGIChannel[_0x2f03('0x20')]['noop']=function(_0x24c427){_0x24c427=_0x24c427||_0x2f03('0x27');return this[_0x2f03('0x22')](util[_0x2f03('0x25')]('VERBOSE\x20\x22%s\x22',_0x24c427));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x28')]=function(_0x40f402,_0x34eef4){if(_[_0x2f03('0x29')](_0x34eef4)){return this[_0x2f03('0x22')](util['format'](_0x2f03('0x2a'),_0x40f402,_0x34eef4[_0x2f03('0x2b')](',')));}return this['sendRequest'](util[_0x2f03('0x25')](_0x2f03('0x2a'),_0x40f402,_0x34eef4));};AGIChannel['prototype'][_0x2f03('0x2c')]=function(_0x2cfeb8){return this['sendRequest'](util[_0x2f03('0x25')](_0x2f03('0x2d'),_0x2cfeb8));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x2e')]=function(_0x2be5ff){return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x2f'),_0x2be5ff));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x30')]=function(_0x4dbcc5){return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x31'),_0x4dbcc5));};AGIChannel[_0x2f03('0x20')][_0x2f03('0xb')]=function(){return this[_0x2f03('0x22')](_0x2f03('0x32'));};AGIChannel['prototype'][_0x2f03('0x33')]=function(_0x3197cb,_0x272b6e){var _0xfc274e=_[_0x2f03('0x34')](_0x272b6e)||_[_0x2f03('0x35')](_0x272b6e)?_0x272b6e['toString']():_0x272b6e;return this['sendRequest'](util[_0x2f03('0x25')](_0x2f03('0x36'),_0x3197cb,_0xfc274e?_0xfc274e[_0x2f03('0x37')]()[_0x2f03('0x10')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x38')]=function(_0x49e7f0,_0x1f9239){return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x39'),_0x49e7f0,_0x1f9239));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x3a')]=function(_0x12de2a,_0x5c0424){return this['sendRequest'](util['format'](_0x2f03('0x3b'),_0x12de2a,_0x5c0424));};AGIChannel['prototype'][_0x2f03('0x3c')]=function(_0x180280,_0xe93a1a){return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x3d'),_0x180280,_0xe93a1a));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x3e')]=function(_0x13e032,_0x2e53bf,_0x35a846){_0x2e53bf=_0x2e53bf||this[_0x2f03('0x3f')];_0x35a846=_0x35a846||0x1;this[_0x2f03('0x2c')](_0x13e032);this[_0x2f03('0x2e')](_0x2e53bf);this[_0x2f03('0x30')](_0x35a846);return this[_0x2f03('0x40')](util['format'](_0x2f03('0x41'),_0x13e032,_0x2e53bf,_0x35a846));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x42')]=function(_0x3c36c5){return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x43'),_0x3c36c5));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x44')]=function(_0xc93a8a,_0x5b560d,_0x322ea0,_0x661a6a,_0x42ea2c,_0x54fcca){_0x5b560d=_0x5b560d||_0x2f03('0x45');_0x322ea0=_0x322ea0||'';_0x661a6a=_0x661a6a===undefined?-0x1:_0x661a6a==='-1'?-0x1:_0x661a6a*0x3e8;_0x42ea2c=_0x42ea2c===undefined?'':'s='+_0x42ea2c;_0x54fcca=_0x54fcca?_0x2f03('0x46'):'';return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x47'),_0xc93a8a,_0x5b560d,_0x322ea0,_0x661a6a,_0x54fcca,_0x42ea2c));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x48')]=function(_0x3639e1,_0x5f0235){_0x5f0235=_0x5f0235||'';return this[_0x2f03('0x22')](util[_0x2f03('0x25')](_0x2f03('0x49'),_0x3639e1,_0x5f0235));};AGIChannel[_0x2f03('0x20')][_0x2f03('0x4a')]=function(_0x495654){return this[_0x2f03('0x28')](_0x2f03('0x4b'),_0x495654);};AGIChannel[_0x2f03('0x20')]['wait']=function(_0x2ac49c){return this[_0x2f03('0x28')](_0x2f03('0x4c'),_0x2ac49c);};AGIChannel['prototype'][_0x2f03('0x17')]=function(_0x31941d,_0x2263d0){this[_0x2f03('0x40')](util[_0x2f03('0x25')](_0x2f03('0x4d'),_0x31941d['id'],_0x31941d[_0x2f03('0x4e')],_0x2263d0));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x2f03('0x4f')]=AGIChannel;