b7580f123e10d4b63d5b30d57b5bea52882d1826
[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 _0x5f97=['Queue','calleridnum','dialer','VoiceQueueId','\x22rtTxX%s%s\x22','dialQueueProject2','monitor_format','\x22agi://%s/square,%s\x22','dialQueueProject','NONE','originatecalleridnum','originatecalleridname','xcally-motion-preview','_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','Contact','hasOwnProperty','tags','createdAt','updatedAt','%s%s','XMD-','toUpper','toLower','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','logBlacklist','YYYY-MM-DD\x20HH:mm:ss','state','Blacklist','starttime','endtime','logAgent','statedesc','responsetime','ringtime','logLookAgent','membername','UserId','talktime','answertime','isFailure','Failure','variablesAction','calleridname','BOOKED','originate','from-sip','timeout','uniqueid','totalGlobal','countbusyretry','countcongestionretry','countnoanswerretry','countagentrejectretry','countnosuchnumberretry','Global','active','add','minutes','ContactId','ListId','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','IsNotLoggedIn','buildObj','lastevent','name','queue','mandatoryDisposition','interface','channelAgent','agentReadyId','not_inuse','status','reachable','push','diff','createBody','CampaignId','filterKey','idContact','type','campaigntype','dialAnswer','scheduledat','countglobal','callback','callbackuniqueid','callbackat','recallme','sipcallid','xmd-voicequeueid','xmd-phone','xmd-listid','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-dialchannel','xmd-cdrtype','xmd-callerid','xmd-agiafter','xmd-agi','rtpaudioqos','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqoslossbridged','rtpaudioqosrttbridged','rtpaudioqosloss','rtpaudioqosrtt','bridgepeer','bridgepvtcallid','getCallerIdRandom','pow','random','extractCalleridName','extractCalleridNumber','match','util','lodash','moment','../../../../config/logger','preview','env','XCALLY_IP_AGI','127.0.0.1','milliseconds','seconds','loggerCatch','error','inspect','logger','info','loggerError','logger2','getCallerId','string','isEmpty','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isNil'];(function(_0x3e6acc,_0x38bccc){var _0x115e08=function(_0x2e8661){while(--_0x2e8661){_0x3e6acc['push'](_0x3e6acc['shift']());}};_0x115e08(++_0x38bccc);}(_0x5f97,0x192));var _0x75f9=function(_0xa464c9,_0x7c86d8){_0xa464c9=_0xa464c9-0x0;var _0x3d73c4=_0x5f97[_0xa464c9];return _0x3d73c4;};'use strict';var util=require(_0x75f9('0x0'));var _=require(_0x75f9('0x1'));var moment=require(_0x75f9('0x2'));var logger=require(_0x75f9('0x3'))(_0x75f9('0x4'));var ipAgi=process[_0x75f9('0x5')][_0x75f9('0x6')]||_0x75f9('0x7');function getSeconds(_0x1fd101,_0x1d36df){var _0x318eb3=moment(_0x1fd101)['milliseconds'](0x0);var _0x72e216=moment(_0x1d36df)[_0x75f9('0x8')](0x0);return _0x318eb3['diff'](_0x72e216,_0x75f9('0x9'));}exports[_0x75f9('0xa')]=function(_0x4ccf46){return function(_0x32deb0){logger[_0x75f9('0xb')](_0x4ccf46,util[_0x75f9('0xc')](_0x32deb0,{'showHidden':![],'depth':null}));};};exports[_0x75f9('0xd')]=function(_0x43c67c,_0x170cd3){logger[_0x75f9('0xe')](_0x43c67c,util['inspect'](_0x170cd3,{'showHidden':![],'depth':null}));};exports[_0x75f9('0xf')]=function(_0x4f1e8f,_0x3b0474){logger[_0x75f9('0xb')](_0x4f1e8f,util[_0x75f9('0xc')](_0x3b0474,{'showHidden':![],'depth':null}));};exports[_0x75f9('0x10')]=function(_0x4710a9){return function(_0x505d12){logger[_0x75f9('0xe')](_0x4710a9,util[_0x75f9('0xc')](_0x505d12,{'showHidden':![],'depth':null}));};};exports['message']=function(_0x2d69d1,_0x434d6a,_0x180df0){return{'message':_0x2d69d1,'unlock':_0x434d6a,'active':_0x180df0};};exports[_0x75f9('0x11')]=function(_0x3ef52f,_0x46d179,_0x34ec83){if(!_['isUndefined'](_0x34ec83)&&_0x75f9('0x12')===typeof _0x34ec83&&!_['isEmpty'](_0x34ec83)){if(!_['isUndefined'](_0x46d179)&&_0x75f9('0x12')===typeof _0x46d179&&!_[_0x75f9('0x13')](_0x46d179)){return util[_0x75f9('0x14')](_0x75f9('0x15'),_0x46d179,_0x34ec83);}return util['format'](_0x75f9('0x15'),_0x34ec83,_0x34ec83);}if(!_['isUndefined'](_0x3ef52f)&&_0x75f9('0x12')===typeof _0x3ef52f&&!_[_0x75f9('0x13')](_0x3ef52f)){return _0x3ef52f;}return _0x75f9('0x16');};exports['isActive']=function(_0x470574){if(_[_0x75f9('0x17')](_0x470574)){return![];}return _0x470574;};exports['addVariables']=function(_0x27cbb1,_0x454fb0,_0x36101b,_0x16deb7,_0xe5e1,_0x30e5b9){var _0x2f61d3={'XMD-QUEUE':_0x454fb0[_0x75f9('0x18')]?_0x454fb0[_0x75f9('0x18')]['name']:'','XMD-CALLERID':_0x16deb7,'XMD-CALLERID-PREVIEW':_0x30e5b9?util['format'](_0x75f9('0x15'),_0x30e5b9['calleridname'],_0x30e5b9[_0x75f9('0x19')]):_0x16deb7,'XMD-DIALID':_0xe5e1,'XMD-CONTACTID':_0x454fb0['ContactId'],'XMD-CDRTYPE':_0x75f9('0x1a'),'CALLERID(all)':_0x16deb7,'XMD-VOICEQUEUEID':_0x454fb0[_0x75f9('0x1b')],'XMD-DIALCHANNEL':_0x36101b,'XMD-DIALTIMEOUT':_0x27cbb1['dialOriginateTimeout']||0x1e,'XMD-DIALOPTIONS':util['format'](_0x75f9('0x1c'),_0x27cbb1[_0x75f9('0x1d')]?'g':'',_['isEmpty'](_0x27cbb1[_0x75f9('0x1e')])?'':'U(xcally-mixmonitor-context)'),'XMD-DIALURL':_0x27cbb1['dialPreviewUrl']||'','XMD-AGI':_0x27cbb1['dialQueueProject']?util['format'](_0x75f9('0x1f'),ipAgi,_0x27cbb1[_0x75f9('0x20')]):'NONE','XMD-AGIAFTER':_0x27cbb1['dialQueueProject2']?util[_0x75f9('0x14')](_0x75f9('0x1f'),ipAgi,_0x27cbb1[_0x75f9('0x1d')]):_0x75f9('0x21'),'XMD-ORIGINATECALLERIDNUM':_0x30e5b9?_0x30e5b9[_0x75f9('0x22')]:'','XMD-ORIGINATECALLERIDNAME':_0x30e5b9?_0x30e5b9[_0x75f9('0x23')]:'','XMD-DESTINATION':_0x75f9('0x24')};if(!_[_0x75f9('0x13')](_0x27cbb1[_0x75f9('0x1e')])){_0x2f61d3[util['format']('%s',_0x75f9('0x25'))]=_0x27cbb1[_0x75f9('0x1e')];_0x2f61d3[util[_0x75f9('0x14')]('%s',_0x75f9('0x26'))]=_0xe5e1;}if(_0x454fb0&&_0x454fb0[_0x75f9('0x27')]){for(var _0x1f2bde in _0x454fb0[_0x75f9('0x27')]){if(_0x454fb0['Contact'][_0x75f9('0x28')](_0x1f2bde)){if(!_[_0x75f9('0x17')](_0x454fb0[_0x75f9('0x27')][_0x1f2bde])&&_0x1f2bde!=='id'&&_0x1f2bde!==_0x75f9('0x29')&&_0x1f2bde!==_0x75f9('0x2a')&&_0x1f2bde!==_0x75f9('0x2b')){_0x2f61d3[util['format'](_0x75f9('0x2c'),_0x75f9('0x2d'),_[_0x75f9('0x2e')](_0x1f2bde))]=_0x454fb0[_0x75f9('0x27')][_0x1f2bde];}}}}return _0x2f61d3;};exports['toLowerVariables']=function(_0x1661d8){var _0x51d869={};for(var _0x159190 in _0x1661d8){if(_0x1661d8[_0x75f9('0x28')](_0x159190)){_0x51d869[util[_0x75f9('0x14')]('%s',_[_0x75f9('0x2f')](_0x159190))]=_0x1661d8[_0x159190];}}return{'variables':_0x51d869};};exports['updateOriginated']=function(_0x104fb8,_0x59e63b){if(!_['isNil'](_0x104fb8)){if(_0x104fb8[_0x75f9('0x28')](_0x75f9('0x30'))){if(_0x104fb8['originated']>0x0){_0x104fb8['originated']-=0x1;}else{logger[_0x75f9('0xb')](_0x75f9('0x31'),_0x59e63b);}}}else{logger[_0x75f9('0xb')]('[updateOriginated]\x20is\x20null\x20or\x20undefined',_0x59e63b);}};exports[_0x75f9('0x32')]=function(_0x35dca8){var _0x2427a7=moment()['format'](_0x75f9('0x33'));_0x35dca8[_0x75f9('0x34')]=0xd;_0x35dca8['statedesc']=_0x75f9('0x35');_0x35dca8[_0x75f9('0x36')]=_0x2427a7;_0x35dca8['responsetime']=_0x2427a7;_0x35dca8[_0x75f9('0x37')]=_0x2427a7;};exports[_0x75f9('0x38')]=function(_0x623a96,_0x129f1f,_0x44f459){var _0x121a08=moment()[_0x75f9('0x14')](_0x75f9('0x33'));_0x623a96[_0x75f9('0x34')]=_0x129f1f;_0x623a96[_0x75f9('0x39')]=_0x44f459;_0x623a96[_0x75f9('0x3a')]=_0x121a08;_0x623a96[_0x75f9('0x3b')]=getSeconds(_0x623a96['responsetime'],_0x623a96[_0x75f9('0x36')]);};exports[_0x75f9('0x3c')]=function(_0x5da9d9,_0x44b398,_0x4206c1){_0x5da9d9[_0x75f9('0x3d')]=_0x44b398;_0x5da9d9[_0x75f9('0x3e')]=_0x4206c1;};exports['logCustomer']=function(_0x4697bd,_0x144950,_0xb0203e){var _0x4d6992=moment()['format'](_0x75f9('0x33'));_0x4697bd[_0x75f9('0x34')]=_0x144950;_0x4697bd[_0x75f9('0x39')]=_0xb0203e;_0x4697bd[_0x75f9('0x3a')]=_0x4697bd['responsetime']?_0x4697bd['responsetime']:_0x4d6992;_0x4697bd[_0x75f9('0x37')]=_0x4697bd['endtime']?_0x4697bd[_0x75f9('0x37')]:_0x4d6992;_0x4697bd['ringtime']=getSeconds(_0x4697bd[_0x75f9('0x3a')]||0x0,_0x4697bd[_0x75f9('0x36')]||0x0);_0x4697bd[_0x75f9('0x3f')]=_0x4697bd[_0x75f9('0x40')]?getSeconds(_0x4697bd[_0x75f9('0x37')],_0x4697bd[_0x75f9('0x40')]):0x0;};exports[_0x75f9('0x41')]=function(_0x39665e){return _0x39665e===_0x75f9('0x42');};exports[_0x75f9('0x43')]=function(_0x35c6b8,_0x1f3189,_0x324d35,_0xa98c4b,_0x33960c){var _0x44a411=_0xa98c4b?'RECALL':_0x35c6b8[_0x75f9('0x44')];_0x44a411=_0x33960c?_0x75f9('0x45'):_0x44a411;return{'actionid':_0x35c6b8['uniqueid'],'action':_0x75f9('0x46'),'channel':_0x35c6b8['channelAgent'],'callerid':util[_0x75f9('0x14')](_0x75f9('0x15'),_0x44a411,_0x35c6b8['calleridnum']),'Exten':_0x75f9('0x24'),'Context':_0x75f9('0x47'),'Priority':'1','variable':_0x324d35,'timeout':(_0x1f3189[_0x75f9('0x48')]||0x1e)*0x3e8,'async':!![],'channelid':_0x35c6b8[_0x75f9('0x49')]};};exports[_0x75f9('0x4a')]=function(_0x1382c9){return _0x1382c9[_0x75f9('0x4b')]+_0x1382c9[_0x75f9('0x4c')]+_0x1382c9[_0x75f9('0x4d')]+_0x1382c9[_0x75f9('0x4e')]+_0x1382c9[_0x75f9('0x4f')];};exports['cloneAction']=function(_0x112f80){var _0x41c7b0=_['clone'](_0x112f80);_0x41c7b0[_0x75f9('0x34')]=0xf;_0x41c7b0[_0x75f9('0x39')]=_0x75f9('0x50');return _0x41c7b0;};exports['scheduledAt']=function(_0x4ea836,_0x31c06f,_0x4dd721){var _0x26830c={};_0x26830c[_0x31c06f]=_0x4ea836[_0x31c06f];_0x26830c[_0x75f9('0x51')]=![];_0x26830c['scheduledat']=moment()[_0x75f9('0x52')](_0x4dd721,_0x75f9('0x53'))['format']('YYYY-MM-DD\x20HH:mm:ss');_0x26830c['ContactId']=_0x4ea836[_0x75f9('0x54')];_0x26830c[_0x75f9('0x55')]=_0x4ea836[_0x75f9('0x55')];_0x26830c[_0x75f9('0x1b')]=_0x4ea836[_0x75f9('0x1b')]||undefined;return _0x26830c;};exports['decrementTalkink']=function(_0x1ae6b2,_0x5808a9){if(!_['isNil'](_0x1ae6b2)){if(_0x1ae6b2[_0x75f9('0x56')]>0x0){_0x1ae6b2[_0x75f9('0x56')]-=0x1;}else{logger[_0x75f9('0xb')](_0x5808a9,_0x75f9('0x57'));}}else{logger[_0x75f9('0xb')](_0x5808a9,'[decrementTalkink]\x20is\x20null\x20or\x20undefined');}};exports[_0x75f9('0x58')]=function(_0x244242){if(_0x244242<=0x0){return!![];}return![];};exports[_0x75f9('0x59')]=function(_0x525528,_0x1ea14c,_0x11653c){_0x525528[_0x75f9('0x5a')]=_0x1ea14c;_0x525528[_0x75f9('0x5b')]=_0x525528[_0x75f9('0x5c')];_0x525528['interface']=_0x525528['channelAgent'];if(_0x11653c){_0x525528[_0x75f9('0x5d')]=_0x11653c[_0x75f9('0x5d')];}return _0x525528;};exports['buildAcw']=function(_0x2a37c9){var _0x177133={};_0x177133['queue']=_0x2a37c9[_0x75f9('0x5c')];_0x177133[_0x75f9('0x5e')]=_0x2a37c9[_0x75f9('0x5f')];_0x177133[_0x75f9('0x49')]=_0x2a37c9[_0x75f9('0x49')];return _0x177133;};exports[_0x75f9('0x60')]=function(_0x38999d){var _0x14fdc6=[];for(var _0x21dd38 in _0x38999d){if(_0x38999d[_0x75f9('0x28')](_0x21dd38)){if(!_[_0x75f9('0x17')](_0x38999d[_0x21dd38])&&_0x38999d[_0x21dd38][_0x75f9('0x34')]===_0x75f9('0x61')&&_0x38999d[_0x21dd38][_0x75f9('0x62')]===_0x75f9('0x63')){_0x14fdc6[_0x75f9('0x64')](_0x38999d[_0x21dd38]['id']);}}}return _0x14fdc6;};exports['getDiff']=function(_0x143ffc){var _0x4f4d14=moment()[_0x75f9('0x8')](0x0);var _0x3f0970=moment(_0x143ffc)[_0x75f9('0x8')](0x0);return _0x4f4d14[_0x75f9('0x65')](_0x3f0970,_0x75f9('0x9'));};exports[_0x75f9('0x66')]=function(_0x1a0e70){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x1a0e70[_0x75f9('0x54')],'ListId':_0x1a0e70[_0x75f9('0x55')],'VoiceQueueId':_0x1a0e70[_0x75f9('0x1b')]||undefined,'CampaignId':_0x1a0e70[_0x75f9('0x67')]||undefined};};exports[_0x75f9('0x68')]=function(_0x765a3e){if(_0x765a3e===_0x75f9('0x49')||_0x765a3e===_0x75f9('0x69')||_0x765a3e==='queue'||_0x765a3e===_0x75f9('0x6a')||_0x765a3e===_0x75f9('0x6b')||_0x765a3e===_0x75f9('0x6c')||_0x765a3e==='membername'||_0x765a3e===_0x75f9('0x5f')||_0x765a3e===_0x75f9('0x44')||_0x765a3e==='active'||_0x765a3e===_0x75f9('0x19')||_0x765a3e===_0x75f9('0x6d')||_0x765a3e==='countbusyretry'||_0x765a3e===_0x75f9('0x4c')||_0x765a3e===_0x75f9('0x4d')||_0x765a3e===_0x75f9('0x6e')||_0x765a3e===_0x75f9('0x6f')||_0x765a3e===_0x75f9('0x70')||_0x765a3e===_0x75f9('0x71')||_0x765a3e===_0x75f9('0x72')||_0x765a3e===_0x75f9('0x54')||_0x765a3e==='ListId'||_0x765a3e===_0x75f9('0x3e')||_0x765a3e===_0x75f9('0x1b')||_0x765a3e===_0x75f9('0x73')||_0x765a3e===_0x75f9('0x74')||_0x765a3e==='xmd-queue'||_0x765a3e===_0x75f9('0x75')||_0x765a3e===_0x75f9('0x76')||_0x765a3e==='xmd-dialurl'||_0x765a3e===_0x75f9('0x77')||_0x765a3e===_0x75f9('0x78')||_0x765a3e===_0x75f9('0x79')||_0x765a3e===_0x75f9('0x7a')||_0x765a3e==='xmd-contactid'||_0x765a3e===_0x75f9('0x7b')||_0x765a3e===_0x75f9('0x7c')||_0x765a3e===_0x75f9('0x7d')||_0x765a3e===_0x75f9('0x7e')||_0x765a3e===_0x75f9('0x7f')||_0x765a3e==='rtpaudioqosbridged'||_0x765a3e===_0x75f9('0x80')||_0x765a3e===_0x75f9('0x81')||_0x765a3e==='rtpaudioqosloss'||_0x765a3e===_0x75f9('0x82')||_0x765a3e==='rtpaudioqosrtt'||_0x765a3e===_0x75f9('0x83')||_0x765a3e===_0x75f9('0x7f')||_0x765a3e==='rtpaudioqosbridged'||_0x765a3e===_0x75f9('0x80')||_0x765a3e===_0x75f9('0x81')||_0x765a3e===_0x75f9('0x84')||_0x765a3e===_0x75f9('0x82')||_0x765a3e===_0x75f9('0x85')||_0x765a3e===_0x75f9('0x83')||_0x765a3e===_0x75f9('0x86')||_0x765a3e===_0x75f9('0x87')||_0x765a3e===_0x75f9('0x34')||_0x765a3e===_0x75f9('0x39')){return![];}return!![];};exports[_0x75f9('0x88')]=function(_0x3a51b7,_0x23986f){var _0x793e4d,_0x4efb2b,_0x534907;if(_0x23986f<=0x0){_0x23986f=0x1;}_0x793e4d=new RegExp('\x5cw{0,'+_0x23986f+'}$');_0x4efb2b=Math[_0x75f9('0x89')](0xa,_0x23986f-0x1);_0x534907=Math['pow'](0xa,_0x23986f)-0x1;return util[_0x75f9('0x14')]('%s',_['replace'](_0x3a51b7,_0x793e4d,_[_0x75f9('0x8a')](_0x4efb2b,_0x534907)));};exports[_0x75f9('0x8b')]=function(_0xb74f73){var _0x3ecb56=_0xb74f73['match'](/"(.*?)"/);return _0x3ecb56?_0x3ecb56[0x1]:_0xb74f73;};exports[_0x75f9('0x8c')]=function(_0x491f0f){var _0x529f04=_0x491f0f[_0x75f9('0x8d')](/<(.*?)>/);return _0x529f04?_0x529f04[0x1]:_0x491f0f;};