257598b55f453e13a383d9c3c63051926c6f97ef
[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 _0xf073=['countcongestionretry','countnoanswerretry','countagentrejectretry','countnosuchnumberretry','cloneAction','clone','Global','scheduledAt','active','add','minutes','ListId','VoiceQueueId','pTalking','[decrementTalkink]\x20is\x20null\x20or\x20undefined','IsNotLoggedIn','queue','mandatoryDisposition','buildAcw','interface','status','reachable','push','getDiff','createBody','CampaignId','idContact','type','campaigntype','dialAnswer','scheduledat','countglobal','callback','callbackuniqueid','callbackat','recallme','sipcallid','xmd-queue','xmd-phone','xmd-dialurl','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-dialchannel','xmd-contactid','xmd-cdrtype','rtpaudioqosbridged','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosjitter','rtpaudioqosrtt','rtpaudioqosrttbridged','bridgepeer','getCallerIdRandom','\x5cw{0,','pow','replace','random','extractCalleridName','match','util','lodash','preview','env','127.0.0.1','milliseconds','diff','seconds','loggerCatch','error','inspect','info','loggerError','logger2','message','string','isEmpty','format','\x22%s\x22\x20<%s>','isUndefined','\x22\x22\x20<>','isNil','Queue','name','calleridname','ContactId','dialer','\x22rtTxX%s%s\x22','dialQueueProject2','monitor_format','U(xcally-mixmonitor-context)','dialPreviewUrl','dialQueueProject','NONE','\x22agi://%s/square,%s\x22','originatecalleridnum','originatecalleridname','_XCALLY_MIXMONITOR_FORMAT','Contact','hasOwnProperty','createdAt','updatedAt','%s%s','XMD-','toUpper','toLowerVariables','toLower','updateOriginated','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','statedesc','starttime','responsetime','endtime','logAgent','YYYY-MM-DD\x20HH:mm:ss','state','ringtime','membername','UserId','talktime','answertime','isFailure','Failure','variablesAction','RECALL','BOOKED','uniqueid','originate','channelAgent','calleridnum','xcally-motion-preview','from-sip','timeout','totalGlobal','countbusyretry'];(function(_0x1cc259,_0xfee44c){var _0x5c9c14=function(_0x24e4b2){while(--_0x24e4b2){_0x1cc259['push'](_0x1cc259['shift']());}};_0x5c9c14(++_0xfee44c);}(_0xf073,0x153));var _0x3f07=function(_0x39c25a,_0x469ae0){_0x39c25a=_0x39c25a-0x0;var _0x16c1d3=_0xf073[_0x39c25a];return _0x16c1d3;};'use strict';var util=require(_0x3f07('0x0'));var _=require(_0x3f07('0x1'));var moment=require('moment');var logger=require('../../../../config/logger')(_0x3f07('0x2'));var ipAgi=process[_0x3f07('0x3')]['XCALLY_IP_AGI']||_0x3f07('0x4');function getSeconds(_0x3d320f,_0x4ff24a){var _0x5bf995=moment(_0x3d320f)[_0x3f07('0x5')](0x0);var _0x3bfc8f=moment(_0x4ff24a)[_0x3f07('0x5')](0x0);return _0x5bf995[_0x3f07('0x6')](_0x3bfc8f,_0x3f07('0x7'));}exports[_0x3f07('0x8')]=function(_0x4aff1f){return function(_0x3e5cc0){logger[_0x3f07('0x9')](_0x4aff1f,util[_0x3f07('0xa')](_0x3e5cc0,{'showHidden':![],'depth':null}));};};exports['logger']=function(_0x43510c,_0x31dd64){logger[_0x3f07('0xb')](_0x43510c,util[_0x3f07('0xa')](_0x31dd64,{'showHidden':![],'depth':null}));};exports[_0x3f07('0xc')]=function(_0x51058f,_0x2654d1){logger[_0x3f07('0x9')](_0x51058f,util['inspect'](_0x2654d1,{'showHidden':![],'depth':null}));};exports[_0x3f07('0xd')]=function(_0x2a0b57){return function(_0x3d787d){logger[_0x3f07('0xb')](_0x2a0b57,util[_0x3f07('0xa')](_0x3d787d,{'showHidden':![],'depth':null}));};};exports[_0x3f07('0xe')]=function(_0xbea223,_0x2f79ee,_0x13acf2){return{'message':_0xbea223,'unlock':_0x2f79ee,'active':_0x13acf2};};exports['getCallerId']=function(_0x2acfe5,_0x40ef6e,_0x636172){if(!_['isUndefined'](_0x636172)&&_0x3f07('0xf')===typeof _0x636172&&!_[_0x3f07('0x10')](_0x636172)){if(!_['isUndefined'](_0x40ef6e)&&_0x3f07('0xf')===typeof _0x40ef6e&&!_['isEmpty'](_0x40ef6e)){return util['format']('\x22%s\x22\x20<%s>',_0x40ef6e,_0x636172);}return util[_0x3f07('0x11')](_0x3f07('0x12'),_0x636172,_0x636172);}if(!_[_0x3f07('0x13')](_0x2acfe5)&&'string'===typeof _0x2acfe5&&!_['isEmpty'](_0x2acfe5)){return _0x2acfe5;}return _0x3f07('0x14');};exports['isActive']=function(_0x2de3bb){if(_[_0x3f07('0x15')](_0x2de3bb)){return![];}return _0x2de3bb;};exports['addVariables']=function(_0x1f502c,_0xed21f9,_0x45021a,_0x2af897,_0xa90609,_0x48d2c5){var _0x1af7f5={'XMD-QUEUE':_0xed21f9[_0x3f07('0x16')]?_0xed21f9[_0x3f07('0x16')][_0x3f07('0x17')]:'','XMD-CALLERID':_0x2af897,'XMD-CALLERID-PREVIEW':_0x48d2c5?util[_0x3f07('0x11')]('\x22%s\x22\x20<%s>',_0x48d2c5[_0x3f07('0x18')],_0x48d2c5['calleridnum']):_0x2af897,'XMD-DIALID':_0xa90609,'XMD-CONTACTID':_0xed21f9[_0x3f07('0x19')],'XMD-CDRTYPE':_0x3f07('0x1a'),'CALLERID(all)':_0x2af897,'XMD-VOICEQUEUEID':_0xed21f9['VoiceQueueId'],'XMD-DIALCHANNEL':_0x45021a,'XMD-DIALTIMEOUT':_0x1f502c['dialOriginateTimeout']||0x1e,'XMD-DIALOPTIONS':util[_0x3f07('0x11')](_0x3f07('0x1b'),_0x1f502c[_0x3f07('0x1c')]?'g':'',_[_0x3f07('0x10')](_0x1f502c[_0x3f07('0x1d')])?'':_0x3f07('0x1e')),'XMD-DIALURL':_0x1f502c[_0x3f07('0x1f')]||'','XMD-AGI':_0x1f502c['dialQueueProject']?util[_0x3f07('0x11')]('\x22agi://%s/square,%s\x22',ipAgi,_0x1f502c[_0x3f07('0x20')]):_0x3f07('0x21'),'XMD-AGIAFTER':_0x1f502c[_0x3f07('0x1c')]?util[_0x3f07('0x11')](_0x3f07('0x22'),ipAgi,_0x1f502c[_0x3f07('0x1c')]):'NONE','XMD-ORIGINATECALLERIDNUM':_0x48d2c5?_0x48d2c5[_0x3f07('0x23')]:'','XMD-ORIGINATECALLERIDNAME':_0x48d2c5?_0x48d2c5[_0x3f07('0x24')]:'','XMD-DESTINATION':'xcally-motion-preview'};if(!_[_0x3f07('0x10')](_0x1f502c['monitor_format'])){_0x1af7f5[util[_0x3f07('0x11')]('%s',_0x3f07('0x25'))]=_0x1f502c[_0x3f07('0x1d')];_0x1af7f5[util[_0x3f07('0x11')]('%s','_XCALLY_MIXMONITOR_UNIQUEID')]=_0xa90609;}if(_0xed21f9&&_0xed21f9[_0x3f07('0x26')]){for(var _0x5b2034 in _0xed21f9[_0x3f07('0x26')]){if(_0xed21f9[_0x3f07('0x26')][_0x3f07('0x27')](_0x5b2034)){if(!_['isNil'](_0xed21f9[_0x3f07('0x26')][_0x5b2034])&&_0x5b2034!=='id'&&_0x5b2034!=='tags'&&_0x5b2034!==_0x3f07('0x28')&&_0x5b2034!==_0x3f07('0x29')){_0x1af7f5[util[_0x3f07('0x11')](_0x3f07('0x2a'),_0x3f07('0x2b'),_[_0x3f07('0x2c')](_0x5b2034))]=_0xed21f9[_0x3f07('0x26')][_0x5b2034];}}}}return _0x1af7f5;};exports[_0x3f07('0x2d')]=function(_0x541295){var _0x4457d2={};for(var _0xc146a9 in _0x541295){if(_0x541295[_0x3f07('0x27')](_0xc146a9)){_0x4457d2[util[_0x3f07('0x11')]('%s',_[_0x3f07('0x2e')](_0xc146a9))]=_0x541295[_0xc146a9];}}return{'variables':_0x4457d2};};exports[_0x3f07('0x2f')]=function(_0x2e97d7,_0x3df6db){if(!_[_0x3f07('0x15')](_0x2e97d7)){if(_0x2e97d7[_0x3f07('0x27')]('originated')){if(_0x2e97d7[_0x3f07('0x30')]>0x0){_0x2e97d7[_0x3f07('0x30')]-=0x1;}else{logger[_0x3f07('0x9')](_0x3f07('0x31'),_0x3df6db);}}}else{logger[_0x3f07('0x9')](_0x3f07('0x32'),_0x3df6db);}};exports[_0x3f07('0x33')]=function(_0x1a3ecf){var _0xe3388=moment()[_0x3f07('0x11')]('YYYY-MM-DD\x20HH:mm:ss');_0x1a3ecf['state']=0xd;_0x1a3ecf[_0x3f07('0x34')]='Blacklist';_0x1a3ecf[_0x3f07('0x35')]=_0xe3388;_0x1a3ecf[_0x3f07('0x36')]=_0xe3388;_0x1a3ecf[_0x3f07('0x37')]=_0xe3388;};exports[_0x3f07('0x38')]=function(_0x35b361,_0xfdf4d0,_0x1a29fb){var _0x58c4ec=moment()['format'](_0x3f07('0x39'));_0x35b361[_0x3f07('0x3a')]=_0xfdf4d0;_0x35b361['statedesc']=_0x1a29fb;_0x35b361['responsetime']=_0x58c4ec;_0x35b361[_0x3f07('0x3b')]=getSeconds(_0x35b361[_0x3f07('0x36')],_0x35b361[_0x3f07('0x35')]);};exports['logLookAgent']=function(_0x2f024f,_0xa46646,_0x5e3f78){_0x2f024f[_0x3f07('0x3c')]=_0xa46646;_0x2f024f[_0x3f07('0x3d')]=_0x5e3f78;};exports['logCustomer']=function(_0x3ad1ce,_0xa79ed1,_0x3e26b6){var _0x374d42=moment()[_0x3f07('0x11')](_0x3f07('0x39'));_0x3ad1ce[_0x3f07('0x3a')]=_0xa79ed1;_0x3ad1ce[_0x3f07('0x34')]=_0x3e26b6;_0x3ad1ce['responsetime']=_0x3ad1ce[_0x3f07('0x36')]?_0x3ad1ce[_0x3f07('0x36')]:_0x374d42;_0x3ad1ce['endtime']=_0x3ad1ce['endtime']?_0x3ad1ce[_0x3f07('0x37')]:_0x374d42;_0x3ad1ce[_0x3f07('0x3b')]=getSeconds(_0x3ad1ce['responsetime']||0x0,_0x3ad1ce[_0x3f07('0x35')]||0x0);_0x3ad1ce[_0x3f07('0x3e')]=_0x3ad1ce[_0x3f07('0x3f')]?getSeconds(_0x3ad1ce[_0x3f07('0x37')],_0x3ad1ce[_0x3f07('0x3f')]):0x0;};exports[_0x3f07('0x40')]=function(_0x2e7250){return _0x2e7250===_0x3f07('0x41');};exports[_0x3f07('0x42')]=function(_0x161615,_0x177c1e,_0x137e66,_0x2bf7fa,_0x138ce4){var _0x7a3079=_0x2bf7fa?_0x3f07('0x43'):_0x161615['calleridname'];_0x7a3079=_0x138ce4?_0x3f07('0x44'):_0x7a3079;return{'actionid':_0x161615[_0x3f07('0x45')],'action':_0x3f07('0x46'),'channel':_0x161615[_0x3f07('0x47')],'callerid':util['format'](_0x3f07('0x12'),_0x7a3079,_0x161615[_0x3f07('0x48')]),'Exten':_0x3f07('0x49'),'Context':_0x3f07('0x4a'),'Priority':'1','variable':_0x137e66,'timeout':(_0x177c1e[_0x3f07('0x4b')]||0x1e)*0x3e8,'async':!![],'channelid':_0x161615[_0x3f07('0x45')]};};exports[_0x3f07('0x4c')]=function(_0x29da89){return _0x29da89[_0x3f07('0x4d')]+_0x29da89[_0x3f07('0x4e')]+_0x29da89[_0x3f07('0x4f')]+_0x29da89[_0x3f07('0x50')]+_0x29da89[_0x3f07('0x51')];};exports[_0x3f07('0x52')]=function(_0x1cb260){var _0x3a9df8=_[_0x3f07('0x53')](_0x1cb260);_0x3a9df8[_0x3f07('0x3a')]=0xf;_0x3a9df8[_0x3f07('0x34')]=_0x3f07('0x54');return _0x3a9df8;};exports[_0x3f07('0x55')]=function(_0x3bb876,_0x35229a,_0x512ad7){var _0x500fc8={};_0x500fc8[_0x35229a]=_0x3bb876[_0x35229a];_0x500fc8[_0x3f07('0x56')]=![];_0x500fc8['scheduledat']=moment()[_0x3f07('0x57')](_0x512ad7,_0x3f07('0x58'))[_0x3f07('0x11')]('YYYY-MM-DD\x20HH:mm:ss');_0x500fc8[_0x3f07('0x19')]=_0x3bb876[_0x3f07('0x19')];_0x500fc8[_0x3f07('0x59')]=_0x3bb876[_0x3f07('0x59')];_0x500fc8[_0x3f07('0x5a')]=_0x3bb876['VoiceQueueId']||undefined;return _0x500fc8;};exports['decrementTalkink']=function(_0x4af835,_0x13a662){if(!_['isNil'](_0x4af835)){if(_0x4af835[_0x3f07('0x5b')]>0x0){_0x4af835[_0x3f07('0x5b')]-=0x1;}else{logger[_0x3f07('0x9')](_0x13a662,'[decrementTalkink]\x20object\x20talking\x20is\x20negative');}}else{logger[_0x3f07('0x9')](_0x13a662,_0x3f07('0x5c'));}};exports[_0x3f07('0x5d')]=function(_0x701797){if(_0x701797<=0x0){return!![];}return![];};exports['buildObj']=function(_0x1e54e5,_0x3ba5f5,_0x82af98){_0x1e54e5['lastevent']=_0x3ba5f5;_0x1e54e5[_0x3f07('0x17')]=_0x1e54e5[_0x3f07('0x5e')];_0x1e54e5['interface']=_0x1e54e5['channelAgent'];if(_0x82af98){_0x1e54e5[_0x3f07('0x5f')]=_0x82af98[_0x3f07('0x5f')];}return _0x1e54e5;};exports[_0x3f07('0x60')]=function(_0x1a92bd){var _0x19d469={};_0x19d469[_0x3f07('0x5e')]=_0x1a92bd[_0x3f07('0x5e')];_0x19d469[_0x3f07('0x61')]=_0x1a92bd[_0x3f07('0x47')];_0x19d469[_0x3f07('0x45')]=_0x1a92bd[_0x3f07('0x45')];return _0x19d469;};exports['agentReadyId']=function(_0x230ff2){var _0x39804c=[];for(var _0x429943 in _0x230ff2){if(_0x230ff2[_0x3f07('0x27')](_0x429943)){if(!_['isNil'](_0x230ff2[_0x429943])&&_0x230ff2[_0x429943][_0x3f07('0x3a')]==='not_inuse'&&_0x230ff2[_0x429943][_0x3f07('0x62')]===_0x3f07('0x63')){_0x39804c[_0x3f07('0x64')](_0x230ff2[_0x429943]['id']);}}}return _0x39804c;};exports[_0x3f07('0x65')]=function(_0x58d592){var _0x58281e=moment()['milliseconds'](0x0);var _0x423ea7=moment(_0x58d592)[_0x3f07('0x5')](0x0);return _0x58281e[_0x3f07('0x6')](_0x423ea7,'seconds');};exports[_0x3f07('0x66')]=function(_0x210547){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x210547[_0x3f07('0x19')],'ListId':_0x210547[_0x3f07('0x59')],'VoiceQueueId':_0x210547[_0x3f07('0x5a')]||undefined,'CampaignId':_0x210547[_0x3f07('0x67')]||undefined};};exports['filterKey']=function(_0x556759){if(_0x556759===_0x3f07('0x45')||_0x556759===_0x3f07('0x68')||_0x556759===_0x3f07('0x5e')||_0x556759===_0x3f07('0x69')||_0x556759===_0x3f07('0x6a')||_0x556759===_0x3f07('0x6b')||_0x556759===_0x3f07('0x3c')||_0x556759==='channelAgent'||_0x556759===_0x3f07('0x18')||_0x556759===_0x3f07('0x56')||_0x556759==='calleridnum'||_0x556759===_0x3f07('0x6c')||_0x556759===_0x3f07('0x4d')||_0x556759==='countcongestionretry'||_0x556759===_0x3f07('0x4f')||_0x556759===_0x3f07('0x6d')||_0x556759===_0x3f07('0x6e')||_0x556759===_0x3f07('0x6f')||_0x556759===_0x3f07('0x70')||_0x556759===_0x3f07('0x71')||_0x556759===_0x3f07('0x19')||_0x556759===_0x3f07('0x59')||_0x556759===_0x3f07('0x3d')||_0x556759==='VoiceQueueId'||_0x556759===_0x3f07('0x72')||_0x556759==='xmd-voicequeueid'||_0x556759===_0x3f07('0x73')||_0x556759===_0x3f07('0x74')||_0x556759==='xmd-listid'||_0x556759===_0x3f07('0x75')||_0x556759===_0x3f07('0x76')||_0x556759===_0x3f07('0x77')||_0x556759===_0x3f07('0x78')||_0x556759===_0x3f07('0x79')||_0x556759===_0x3f07('0x7a')||_0x556759===_0x3f07('0x7b')||_0x556759==='xmd-callerid'||_0x556759==='xmd-agiafter'||_0x556759==='xmd-agi'||_0x556759==='rtpaudioqos'||_0x556759===_0x3f07('0x7c')||_0x556759==='rtpaudioqosjitter'||_0x556759===_0x3f07('0x7d')||_0x556759===_0x3f07('0x7e')||_0x556759===_0x3f07('0x7f')||_0x556759==='rtpaudioqosrtt'||_0x556759==='rtpaudioqosrttbridged'||_0x556759==='rtpaudioqos'||_0x556759===_0x3f07('0x7c')||_0x556759===_0x3f07('0x80')||_0x556759===_0x3f07('0x7d')||_0x556759===_0x3f07('0x7e')||_0x556759==='rtpaudioqoslossbridged'||_0x556759===_0x3f07('0x81')||_0x556759===_0x3f07('0x82')||_0x556759===_0x3f07('0x83')||_0x556759==='bridgepvtcallid'||_0x556759===_0x3f07('0x3a')||_0x556759===_0x3f07('0x34')){return![];}return!![];};exports[_0x3f07('0x84')]=function(_0x1a14bf,_0x194a04){var _0xb2b8e3,_0x3d63b9,_0x5e34a3;if(_0x194a04<=0x0){_0x194a04=0x1;}_0xb2b8e3=new RegExp(_0x3f07('0x85')+_0x194a04+'}$');_0x3d63b9=Math[_0x3f07('0x86')](0xa,_0x194a04-0x1);_0x5e34a3=Math[_0x3f07('0x86')](0xa,_0x194a04)-0x1;return util['format']('%s',_[_0x3f07('0x87')](_0x1a14bf,_0xb2b8e3,_[_0x3f07('0x88')](_0x3d63b9,_0x5e34a3)));};exports[_0x3f07('0x89')]=function(_0x57b6f1){var _0x26862b=_0x57b6f1['match'](/"(.*?)"/);return _0x26862b?_0x26862b[0x1]:_0x57b6f1;};exports['extractCalleridNumber']=function(_0x2cbda3){var _0x1a1373=_0x2cbda3[_0x3f07('0x8a')](/<(.*?)>/);return _0x1a1373?_0x1a1373[0x1]:_0x2cbda3;};