Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / services / ami / preview / util / util.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 _0x07ec=['logger','info','logger2','message','getCallerId','string','isUndefined','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isActive','isNil','addVariables','Queue','name','calleridnum','ContactId','dialer','VoiceQueueId','dialOriginateTimeout','\x22rtTxX%s%s\x22','dialQueueProject2','isEmpty','monitor_format','U(xcally-mixmonitor-context)','dialPreviewUrl','dialQueueProject','NONE','\x22agi://%s/square,%s\x22','originatecalleridnum','originatecalleridname','xcally-motion-preview','_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','Contact','createdAt','XMD-','toUpper','toLowerVariables','hasOwnProperty','updateOriginated','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','statedesc','Blacklist','starttime','responsetime','endtime','logAgent','YYYY-MM-DD\x20HH:mm:ss','state','ringtime','logLookAgent','membername','UserId','logCustomer','talktime','answertime','isFailure','Failure','RECALL','calleridname','uniqueid','originate','channelAgent','timeout','totalGlobal','countbusyretry','countcongestionretry','countnoanswerretry','countnosuchnumberretry','cloneAction','clone','Global','scheduledAt','active','add','ListId','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','[decrementTalkink]\x20is\x20null\x20or\x20undefined','lastevent','queue','interface','mandatoryDisposition','buildAcw','agentReadyId','not_inuse','status','reachable','getDiff','createBody','CampaignId','filterKey','idContact','type','campaigntype','scheduledat','countglobal','recallme','sipcallid','xmd-voicequeueid','xmd-queue','xmd-dialurl','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-cdrtype','xmd-callerid','xmd-agiafter','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','rtpaudioqosloss','bridgepeer','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','pow','replace','random','extractCalleridName','match','extractCalleridNumber','util','lodash','moment','../../../../config/logger','preview','env','127.0.0.1','milliseconds','diff','seconds','loggerCatch','error','inspect'];(function(_0xd2e2ab,_0x2440cf){var _0x1703a2=function(_0x23deba){while(--_0x23deba){_0xd2e2ab['push'](_0xd2e2ab['shift']());}};_0x1703a2(++_0x2440cf);}(_0x07ec,0x1a0));var _0xc07e=function(_0x5235dd,_0x3f91cf){_0x5235dd=_0x5235dd-0x0;var _0x13059d=_0x07ec[_0x5235dd];return _0x13059d;};'use strict';var util=require(_0xc07e('0x0'));var _=require(_0xc07e('0x1'));var moment=require(_0xc07e('0x2'));var logger=require(_0xc07e('0x3'))(_0xc07e('0x4'));var ipAgi=process[_0xc07e('0x5')]['XCALLY_IP_AGI']||_0xc07e('0x6');function getSeconds(_0x57db14,_0x28feb2){var _0x4fd3be=moment(_0x57db14)[_0xc07e('0x7')](0x0);var _0x5f14e5=moment(_0x28feb2)['milliseconds'](0x0);return _0x4fd3be[_0xc07e('0x8')](_0x5f14e5,_0xc07e('0x9'));}exports[_0xc07e('0xa')]=function(_0x42d723){return function(_0x43a8bf){logger[_0xc07e('0xb')](_0x42d723,util[_0xc07e('0xc')](_0x43a8bf,{'showHidden':![],'depth':null}));};};exports[_0xc07e('0xd')]=function(_0x13f4d5,_0x1cff5d){logger[_0xc07e('0xe')](_0x13f4d5,util[_0xc07e('0xc')](_0x1cff5d,{'showHidden':![],'depth':null}));};exports['loggerError']=function(_0x537e37,_0x3a3f98){logger['error'](_0x537e37,util[_0xc07e('0xc')](_0x3a3f98,{'showHidden':![],'depth':null}));};exports[_0xc07e('0xf')]=function(_0x3e4dce){return function(_0x213ae0){logger[_0xc07e('0xe')](_0x3e4dce,util[_0xc07e('0xc')](_0x213ae0,{'showHidden':![],'depth':null}));};};exports[_0xc07e('0x10')]=function(_0x485d3c,_0x1fbfa1,_0x4eaf7a){return{'message':_0x485d3c,'unlock':_0x1fbfa1,'active':_0x4eaf7a};};exports[_0xc07e('0x11')]=function(_0x3bacde,_0x2ab387,_0x178724){if(!_['isUndefined'](_0x178724)&&_0xc07e('0x12')===typeof _0x178724&&!_['isEmpty'](_0x178724)){if(!_[_0xc07e('0x13')](_0x2ab387)&&_0xc07e('0x12')===typeof _0x2ab387&&!_['isEmpty'](_0x2ab387)){return util[_0xc07e('0x14')](_0xc07e('0x15'),_0x2ab387,_0x178724);}return util[_0xc07e('0x14')](_0xc07e('0x15'),_0x178724,_0x178724);}if(!_[_0xc07e('0x13')](_0x3bacde)&&_0xc07e('0x12')===typeof _0x3bacde&&!_['isEmpty'](_0x3bacde)){return _0x3bacde;}return _0xc07e('0x16');};exports[_0xc07e('0x17')]=function(_0x1238a3){if(_[_0xc07e('0x18')](_0x1238a3)){return![];}return _0x1238a3;};exports[_0xc07e('0x19')]=function(_0x3b48d6,_0x357626,_0x51d05c,_0x1e0b7e,_0x2b39c0,_0x2d3870){var _0x1158e8={'XMD-QUEUE':_0x357626[_0xc07e('0x1a')]?_0x357626['Queue'][_0xc07e('0x1b')]:'','XMD-CALLERID':_0x1e0b7e,'XMD-CALLERID-PREVIEW':_0x2d3870?util['format'](_0xc07e('0x15'),_0x2d3870['calleridname'],_0x2d3870[_0xc07e('0x1c')]):_0x1e0b7e,'XMD-DIALID':_0x2b39c0,'XMD-CONTACTID':_0x357626[_0xc07e('0x1d')],'XMD-CDRTYPE':_0xc07e('0x1e'),'CALLERID(all)':_0x1e0b7e,'XMD-VOICEQUEUEID':_0x357626[_0xc07e('0x1f')],'XMD-DIALCHANNEL':_0x51d05c,'XMD-DIALTIMEOUT':_0x3b48d6[_0xc07e('0x20')]||0x1e,'XMD-DIALOPTIONS':util[_0xc07e('0x14')](_0xc07e('0x21'),_0x3b48d6[_0xc07e('0x22')]?'g':'',_[_0xc07e('0x23')](_0x3b48d6[_0xc07e('0x24')])?'':_0xc07e('0x25')),'XMD-DIALURL':_0x3b48d6[_0xc07e('0x26')]||'','XMD-AGI':_0x3b48d6[_0xc07e('0x27')]?util[_0xc07e('0x14')]('\x22agi://%s/square,%s\x22',ipAgi,_0x3b48d6['dialQueueProject']):_0xc07e('0x28'),'XMD-AGIAFTER':_0x3b48d6['dialQueueProject2']?util[_0xc07e('0x14')](_0xc07e('0x29'),ipAgi,_0x3b48d6[_0xc07e('0x22')]):_0xc07e('0x28'),'XMD-ORIGINATECALLERIDNUM':_0x2d3870?_0x2d3870[_0xc07e('0x2a')]:'','XMD-ORIGINATECALLERIDNAME':_0x2d3870?_0x2d3870[_0xc07e('0x2b')]:'','XMD-DESTINATION':_0xc07e('0x2c')};if(!_[_0xc07e('0x23')](_0x3b48d6[_0xc07e('0x24')])){_0x1158e8[util[_0xc07e('0x14')]('%s',_0xc07e('0x2d'))]=_0x3b48d6[_0xc07e('0x24')];_0x1158e8[util['format']('%s',_0xc07e('0x2e'))]=_0x2b39c0;}if(_0x357626&&_0x357626['Contact']){for(var _0x4a98b6 in _0x357626[_0xc07e('0x2f')]){if(_0x357626[_0xc07e('0x2f')]['hasOwnProperty'](_0x4a98b6)){if(!_[_0xc07e('0x18')](_0x357626['Contact'][_0x4a98b6])&&_0x4a98b6!=='id'&&_0x4a98b6!=='tags'&&_0x4a98b6!==_0xc07e('0x30')&&_0x4a98b6!=='updatedAt'){_0x1158e8[util[_0xc07e('0x14')]('%s%s',_0xc07e('0x31'),_[_0xc07e('0x32')](_0x4a98b6))]=_0x357626[_0xc07e('0x2f')][_0x4a98b6];}}}}return _0x1158e8;};exports[_0xc07e('0x33')]=function(_0x586a43){var _0x63b216={};for(var _0x3ddb4e in _0x586a43){if(_0x586a43[_0xc07e('0x34')](_0x3ddb4e)){_0x63b216[util[_0xc07e('0x14')]('%s',_['toLower'](_0x3ddb4e))]=_0x586a43[_0x3ddb4e];}}return{'variables':_0x63b216};};exports[_0xc07e('0x35')]=function(_0x267020,_0x1255cf){if(!_['isNil'](_0x267020)){if(_0x267020[_0xc07e('0x34')](_0xc07e('0x36'))){if(_0x267020[_0xc07e('0x36')]>0x0){_0x267020[_0xc07e('0x36')]-=0x1;}else{logger['error'](_0xc07e('0x37'),_0x1255cf);}}}else{logger[_0xc07e('0xb')](_0xc07e('0x38'),_0x1255cf);}};exports[_0xc07e('0x39')]=function(_0x1e530e){var _0x3d2149=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x1e530e['state']=0xd;_0x1e530e[_0xc07e('0x3a')]=_0xc07e('0x3b');_0x1e530e[_0xc07e('0x3c')]=_0x3d2149;_0x1e530e[_0xc07e('0x3d')]=_0x3d2149;_0x1e530e[_0xc07e('0x3e')]=_0x3d2149;};exports[_0xc07e('0x3f')]=function(_0x3c7be0,_0x103829,_0x5643e0){var _0x79fdd3=moment()['format'](_0xc07e('0x40'));_0x3c7be0[_0xc07e('0x41')]=_0x103829;_0x3c7be0[_0xc07e('0x3a')]=_0x5643e0;_0x3c7be0[_0xc07e('0x3d')]=_0x79fdd3;_0x3c7be0[_0xc07e('0x42')]=getSeconds(_0x3c7be0[_0xc07e('0x3d')],_0x3c7be0[_0xc07e('0x3c')]);};exports[_0xc07e('0x43')]=function(_0x7b8b03,_0x14e96f,_0xbf8cd7){_0x7b8b03[_0xc07e('0x44')]=_0x14e96f;_0x7b8b03[_0xc07e('0x45')]=_0xbf8cd7;};exports[_0xc07e('0x46')]=function(_0x2c988,_0x28ddc8,_0x58b00b){var _0x5c7bc3=moment()['format'](_0xc07e('0x40'));_0x2c988[_0xc07e('0x41')]=_0x28ddc8;_0x2c988[_0xc07e('0x3a')]=_0x58b00b;_0x2c988['responsetime']=_0x2c988[_0xc07e('0x3d')]?_0x2c988[_0xc07e('0x3d')]:_0x5c7bc3;_0x2c988[_0xc07e('0x3e')]=_0x2c988[_0xc07e('0x3e')]?_0x2c988['endtime']:_0x5c7bc3;_0x2c988[_0xc07e('0x42')]=getSeconds(_0x2c988['responsetime']||0x0,_0x2c988[_0xc07e('0x3c')]||0x0);_0x2c988[_0xc07e('0x47')]=_0x2c988[_0xc07e('0x48')]?getSeconds(_0x2c988[_0xc07e('0x3e')],_0x2c988[_0xc07e('0x48')]):0x0;};exports[_0xc07e('0x49')]=function(_0x33e1fd){return _0x33e1fd===_0xc07e('0x4a');};exports['variablesAction']=function(_0x554f44,_0xde50a5,_0x5d52a1,_0xd4793c,_0x1a7594){var _0x166876=_0xd4793c?_0xc07e('0x4b'):_0x554f44[_0xc07e('0x4c')];_0x166876=_0x1a7594?'BOOKED':_0x166876;return{'actionid':_0x554f44[_0xc07e('0x4d')],'action':_0xc07e('0x4e'),'channel':_0x554f44[_0xc07e('0x4f')],'callerid':util[_0xc07e('0x14')](_0xc07e('0x15'),_0x166876,_0x554f44[_0xc07e('0x1c')]),'Exten':'xcally-motion-preview','Context':'from-sip','Priority':'1','variable':_0x5d52a1,'timeout':(_0xde50a5[_0xc07e('0x50')]||0x1e)*0x3e8,'async':!![],'channelid':_0x554f44[_0xc07e('0x4d')]};};exports[_0xc07e('0x51')]=function(_0x3f6998){return _0x3f6998[_0xc07e('0x52')]+_0x3f6998[_0xc07e('0x53')]+_0x3f6998[_0xc07e('0x54')]+_0x3f6998['countagentrejectretry']+_0x3f6998[_0xc07e('0x55')];};exports[_0xc07e('0x56')]=function(_0x468670){var _0x4fdfad=_[_0xc07e('0x57')](_0x468670);_0x4fdfad[_0xc07e('0x41')]=0xf;_0x4fdfad[_0xc07e('0x3a')]=_0xc07e('0x58');return _0x4fdfad;};exports[_0xc07e('0x59')]=function(_0x1b650b,_0x86c66b,_0x29e005){var _0x35d7e7={};_0x35d7e7[_0x86c66b]=_0x1b650b[_0x86c66b];_0x35d7e7[_0xc07e('0x5a')]=![];_0x35d7e7['scheduledat']=moment()[_0xc07e('0x5b')](_0x29e005,'minutes')[_0xc07e('0x14')](_0xc07e('0x40'));_0x35d7e7[_0xc07e('0x1d')]=_0x1b650b['ContactId'];_0x35d7e7[_0xc07e('0x5c')]=_0x1b650b[_0xc07e('0x5c')];_0x35d7e7[_0xc07e('0x1f')]=_0x1b650b['VoiceQueueId']||undefined;return _0x35d7e7;};exports['decrementTalkink']=function(_0x125e28,_0x354dd3){if(!_[_0xc07e('0x18')](_0x125e28)){if(_0x125e28['pTalking']>0x0){_0x125e28[_0xc07e('0x5d')]-=0x1;}else{logger[_0xc07e('0xb')](_0x354dd3,_0xc07e('0x5e'));}}else{logger[_0xc07e('0xb')](_0x354dd3,_0xc07e('0x5f'));}};exports['IsNotLoggedIn']=function(_0x41819b){if(_0x41819b<=0x0){return!![];}return![];};exports['buildObj']=function(_0x2cc302,_0x3e232e,_0x1d5a7c){_0x2cc302[_0xc07e('0x60')]=_0x3e232e;_0x2cc302[_0xc07e('0x1b')]=_0x2cc302[_0xc07e('0x61')];_0x2cc302[_0xc07e('0x62')]=_0x2cc302[_0xc07e('0x4f')];if(_0x1d5a7c){_0x2cc302[_0xc07e('0x63')]=_0x1d5a7c[_0xc07e('0x63')];}return _0x2cc302;};exports[_0xc07e('0x64')]=function(_0x21e1e7){var _0x5670c8={};_0x5670c8[_0xc07e('0x61')]=_0x21e1e7[_0xc07e('0x61')];_0x5670c8[_0xc07e('0x62')]=_0x21e1e7[_0xc07e('0x4f')];_0x5670c8[_0xc07e('0x4d')]=_0x21e1e7['uniqueid'];return _0x5670c8;};exports[_0xc07e('0x65')]=function(_0x4385d0){var _0x797c6a=[];for(var _0x3303e2 in _0x4385d0){if(_0x4385d0[_0xc07e('0x34')](_0x3303e2)){if(!_[_0xc07e('0x18')](_0x4385d0[_0x3303e2])&&_0x4385d0[_0x3303e2][_0xc07e('0x41')]===_0xc07e('0x66')&&_0x4385d0[_0x3303e2][_0xc07e('0x67')]===_0xc07e('0x68')){_0x797c6a['push'](_0x4385d0[_0x3303e2]['id']);}}}return _0x797c6a;};exports[_0xc07e('0x69')]=function(_0x40d13b){var _0x3b27fd=moment()['milliseconds'](0x0);var _0x25f7b4=moment(_0x40d13b)['milliseconds'](0x0);return _0x3b27fd[_0xc07e('0x8')](_0x25f7b4,_0xc07e('0x9'));};exports[_0xc07e('0x6a')]=function(_0x1a6aa3){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x1a6aa3['ContactId'],'ListId':_0x1a6aa3[_0xc07e('0x5c')],'VoiceQueueId':_0x1a6aa3[_0xc07e('0x1f')]||undefined,'CampaignId':_0x1a6aa3[_0xc07e('0x6b')]||undefined};};exports[_0xc07e('0x6c')]=function(_0x2e1c45){if(_0x2e1c45===_0xc07e('0x4d')||_0x2e1c45===_0xc07e('0x6d')||_0x2e1c45===_0xc07e('0x61')||_0x2e1c45===_0xc07e('0x6e')||_0x2e1c45===_0xc07e('0x6f')||_0x2e1c45==='dialAnswer'||_0x2e1c45==='membername'||_0x2e1c45===_0xc07e('0x4f')||_0x2e1c45==='calleridname'||_0x2e1c45===_0xc07e('0x5a')||_0x2e1c45==='calleridnum'||_0x2e1c45===_0xc07e('0x70')||_0x2e1c45===_0xc07e('0x52')||_0x2e1c45===_0xc07e('0x53')||_0x2e1c45===_0xc07e('0x54')||_0x2e1c45===_0xc07e('0x71')||_0x2e1c45==='callback'||_0x2e1c45==='callbackuniqueid'||_0x2e1c45==='callbackat'||_0x2e1c45===_0xc07e('0x72')||_0x2e1c45==='ContactId'||_0x2e1c45==='ListId'||_0x2e1c45===_0xc07e('0x45')||_0x2e1c45===_0xc07e('0x1f')||_0x2e1c45===_0xc07e('0x73')||_0x2e1c45===_0xc07e('0x74')||_0x2e1c45===_0xc07e('0x75')||_0x2e1c45==='xmd-phone'||_0x2e1c45==='xmd-listid'||_0x2e1c45===_0xc07e('0x76')||_0x2e1c45===_0xc07e('0x77')||_0x2e1c45===_0xc07e('0x78')||_0x2e1c45===_0xc07e('0x79')||_0x2e1c45==='xmd-dialchannel'||_0x2e1c45==='xmd-contactid'||_0x2e1c45===_0xc07e('0x7a')||_0x2e1c45===_0xc07e('0x7b')||_0x2e1c45===_0xc07e('0x7c')||_0x2e1c45==='xmd-agi'||_0x2e1c45===_0xc07e('0x7d')||_0x2e1c45===_0xc07e('0x7e')||_0x2e1c45===_0xc07e('0x7f')||_0x2e1c45===_0xc07e('0x80')||_0x2e1c45==='rtpaudioqosloss'||_0x2e1c45===_0xc07e('0x81')||_0x2e1c45===_0xc07e('0x82')||_0x2e1c45===_0xc07e('0x83')||_0x2e1c45==='rtpaudioqos'||_0x2e1c45==='rtpaudioqosbridged'||_0x2e1c45==='rtpaudioqosjitter'||_0x2e1c45===_0xc07e('0x80')||_0x2e1c45===_0xc07e('0x84')||_0x2e1c45===_0xc07e('0x81')||_0x2e1c45===_0xc07e('0x82')||_0x2e1c45===_0xc07e('0x83')||_0x2e1c45===_0xc07e('0x85')||_0x2e1c45===_0xc07e('0x86')||_0x2e1c45===_0xc07e('0x41')||_0x2e1c45===_0xc07e('0x3a')){return![];}return!![];};exports[_0xc07e('0x87')]=function(_0x3df5c7,_0x11375a){var _0x5eacf0,_0x4c9efb,_0x19e760;if(_0x11375a<=0x0){_0x11375a=0x1;}_0x5eacf0=new RegExp(_0xc07e('0x88')+_0x11375a+'}$');_0x4c9efb=Math[_0xc07e('0x89')](0xa,_0x11375a-0x1);_0x19e760=Math[_0xc07e('0x89')](0xa,_0x11375a)-0x1;return util[_0xc07e('0x14')]('%s',_[_0xc07e('0x8a')](_0x3df5c7,_0x5eacf0,_[_0xc07e('0x8b')](_0x4c9efb,_0x19e760)));};exports[_0xc07e('0x8c')]=function(_0x3d0fb2){var _0x34e8fe=_0x3d0fb2[_0xc07e('0x8d')](/"(.*?)"/);return _0x34e8fe?_0x34e8fe[0x1]:_0x3d0fb2;};exports[_0xc07e('0x8e')]=function(_0xf3798b){var _0x21d2a5=_0xf3798b[_0xc07e('0x8d')](/<(.*?)>/);return _0x21d2a5?_0x21d2a5[0x1]:_0xf3798b;};