Built motion from commit (unavailable).|2.5.6
[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 _0x0c19=['addVariables','Queue','calleridnum','VoiceQueueId','dialQueueProject2','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','hasOwnProperty','tags','createdAt','updatedAt','%s%s','XMD-','toUpper','toLowerVariables','toLower','updateOriginated','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','[updateOriginated]\x20is\x20null\x20or\x20undefined','YYYY-MM-DD\x20HH:mm:ss','state','starttime','responsetime','endtime','logAgent','logLookAgent','membername','UserId','logCustomer','statedesc','ringtime','talktime','answertime','isFailure','Failure','RECALL','calleridname','BOOKED','uniqueid','channelAgent','from-sip','timeout','totalGlobal','countbusyretry','countcongestionretry','countnoanswerretry','countnosuchnumberretry','clone','Global','scheduledAt','scheduledat','minutes','ContactId','ListId','decrementTalkink','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','[decrementTalkink]\x20is\x20null\x20or\x20undefined','buildObj','lastevent','queue','agentReadyId','not_inuse','status','reachable','getDiff','createBody','idContact','campaigntype','dialAnswer','callback','callbackuniqueid','recallme','sipcallid','xmd-voicequeueid','xmd-queue','xmd-phone','xmd-listid','xmd-dialurl','xmd-dialtimeout','xmd-dialchannel','xmd-contactid','xmd-callerid','xmd-agiafter','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','rtpaudioqosjitterbridged','rtpaudioqosloss','bridgepeer','bridgepvtcallid','replace','random','extractCalleridName','match','extractCalleridNumber','util','lodash','moment','../../../../config/logger','preview','env','127.0.0.1','milliseconds','diff','seconds','loggerCatch','error','inspect','logger2','message','isUndefined','string','isEmpty','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isActive','isNil'];(function(_0xf9295c,_0x544ef4){var _0x8cba0b=function(_0x47d3fb){while(--_0x47d3fb){_0xf9295c['push'](_0xf9295c['shift']());}};_0x8cba0b(++_0x544ef4);}(_0x0c19,0xf5));var _0x90c1=function(_0x41ede4,_0x4450a8){_0x41ede4=_0x41ede4-0x0;var _0x2aa511=_0x0c19[_0x41ede4];return _0x2aa511;};'use strict';var util=require(_0x90c1('0x0'));var _=require(_0x90c1('0x1'));var moment=require(_0x90c1('0x2'));var logger=require(_0x90c1('0x3'))(_0x90c1('0x4'));var ipAgi=process[_0x90c1('0x5')]['XCALLY_IP_AGI']||_0x90c1('0x6');function getSeconds(_0x16729e,_0x941f3){var _0x5a7a21=moment(_0x16729e)[_0x90c1('0x7')](0x0);var _0xb605b6=moment(_0x941f3)['milliseconds'](0x0);return _0x5a7a21[_0x90c1('0x8')](_0xb605b6,_0x90c1('0x9'));}exports[_0x90c1('0xa')]=function(_0x2ed328){return function(_0x351d07){logger[_0x90c1('0xb')](_0x2ed328,util[_0x90c1('0xc')](_0x351d07,{'showHidden':![],'depth':null}));};};exports['logger']=function(_0x1cca46,_0x31f5fd){logger['info'](_0x1cca46,util[_0x90c1('0xc')](_0x31f5fd,{'showHidden':![],'depth':null}));};exports['loggerError']=function(_0x5e1486,_0xfa88b3){logger['error'](_0x5e1486,util[_0x90c1('0xc')](_0xfa88b3,{'showHidden':![],'depth':null}));};exports[_0x90c1('0xd')]=function(_0x239342){return function(_0x2d9964){logger['info'](_0x239342,util['inspect'](_0x2d9964,{'showHidden':![],'depth':null}));};};exports[_0x90c1('0xe')]=function(_0x1e76ae,_0x3a49ec,_0x3a8b82){return{'message':_0x1e76ae,'unlock':_0x3a49ec,'active':_0x3a8b82};};exports['getCallerId']=function(_0xaaab35,_0x46b951,_0x154cde){if(!_[_0x90c1('0xf')](_0x154cde)&&_0x90c1('0x10')===typeof _0x154cde&&!_[_0x90c1('0x11')](_0x154cde)){if(!_['isUndefined'](_0x46b951)&&_0x90c1('0x10')===typeof _0x46b951&&!_[_0x90c1('0x11')](_0x46b951)){return util[_0x90c1('0x12')](_0x90c1('0x13'),_0x46b951,_0x154cde);}return util[_0x90c1('0x12')](_0x90c1('0x13'),_0x154cde,_0x154cde);}if(!_[_0x90c1('0xf')](_0xaaab35)&&_0x90c1('0x10')===typeof _0xaaab35&&!_[_0x90c1('0x11')](_0xaaab35)){return _0xaaab35;}return _0x90c1('0x14');};exports[_0x90c1('0x15')]=function(_0x5ddafe){if(_[_0x90c1('0x16')](_0x5ddafe)){return![];}return _0x5ddafe;};exports[_0x90c1('0x17')]=function(_0x37e21b,_0x1cd1f6,_0x242331,_0x3c8cc6,_0x5a8358,_0x412d9f){var _0x5bfe28={'XMD-QUEUE':_0x1cd1f6[_0x90c1('0x18')]?_0x1cd1f6['Queue']['name']:'','XMD-CALLERID':_0x3c8cc6,'XMD-CALLERID-PREVIEW':_0x412d9f?util[_0x90c1('0x12')]('\x22%s\x22\x20<%s>',_0x412d9f['calleridname'],_0x412d9f[_0x90c1('0x19')]):_0x3c8cc6,'XMD-DIALID':_0x5a8358,'XMD-CONTACTID':_0x1cd1f6['ContactId'],'XMD-CDRTYPE':'dialer','CALLERID(all)':_0x3c8cc6,'XMD-VOICEQUEUEID':_0x1cd1f6[_0x90c1('0x1a')],'XMD-DIALCHANNEL':_0x242331,'XMD-DIALTIMEOUT':_0x37e21b['dialOriginateTimeout']||0x1e,'XMD-DIALOPTIONS':util[_0x90c1('0x12')]('\x22rtTxX%s%s\x22',_0x37e21b[_0x90c1('0x1b')]?'g':'',_[_0x90c1('0x11')](_0x37e21b[_0x90c1('0x1c')])?'':_0x90c1('0x1d')),'XMD-DIALURL':_0x37e21b[_0x90c1('0x1e')]||'','XMD-AGI':_0x37e21b[_0x90c1('0x1f')]?util[_0x90c1('0x12')]('\x22agi://%s/square,%s\x22',ipAgi,_0x37e21b[_0x90c1('0x1f')]):_0x90c1('0x20'),'XMD-AGIAFTER':_0x37e21b[_0x90c1('0x1b')]?util[_0x90c1('0x12')](_0x90c1('0x21'),ipAgi,_0x37e21b[_0x90c1('0x1b')]):_0x90c1('0x20'),'XMD-ORIGINATECALLERIDNUM':_0x412d9f?_0x412d9f[_0x90c1('0x22')]:'','XMD-ORIGINATECALLERIDNAME':_0x412d9f?_0x412d9f[_0x90c1('0x23')]:'','XMD-DESTINATION':_0x90c1('0x24')};if(!_[_0x90c1('0x11')](_0x37e21b[_0x90c1('0x1c')])){_0x5bfe28[util[_0x90c1('0x12')]('%s',_0x90c1('0x25'))]=_0x37e21b[_0x90c1('0x1c')];_0x5bfe28[util['format']('%s',_0x90c1('0x26'))]=_0x5a8358;}if(_0x1cd1f6&&_0x1cd1f6[_0x90c1('0x27')]){for(var _0x40c2f1 in _0x1cd1f6[_0x90c1('0x27')]){if(_0x1cd1f6[_0x90c1('0x27')][_0x90c1('0x28')](_0x40c2f1)){if(!_[_0x90c1('0x16')](_0x1cd1f6[_0x90c1('0x27')][_0x40c2f1])&&_0x40c2f1!=='id'&&_0x40c2f1!==_0x90c1('0x29')&&_0x40c2f1!==_0x90c1('0x2a')&&_0x40c2f1!==_0x90c1('0x2b')){_0x5bfe28[util['format'](_0x90c1('0x2c'),_0x90c1('0x2d'),_[_0x90c1('0x2e')](_0x40c2f1))]=_0x1cd1f6['Contact'][_0x40c2f1];}}}}return _0x5bfe28;};exports[_0x90c1('0x2f')]=function(_0x3d96ba){var _0x145fc4={};for(var _0x45af0d in _0x3d96ba){if(_0x3d96ba[_0x90c1('0x28')](_0x45af0d)){_0x145fc4[util[_0x90c1('0x12')]('%s',_[_0x90c1('0x30')](_0x45af0d))]=_0x3d96ba[_0x45af0d];}}return{'variables':_0x145fc4};};exports[_0x90c1('0x31')]=function(_0x207e63,_0x17fd69){if(!_[_0x90c1('0x16')](_0x207e63)){if(_0x207e63[_0x90c1('0x28')](_0x90c1('0x32'))){if(_0x207e63[_0x90c1('0x32')]>0x0){_0x207e63['originated']-=0x1;}else{logger[_0x90c1('0xb')](_0x90c1('0x33'),_0x17fd69);}}}else{logger[_0x90c1('0xb')](_0x90c1('0x34'),_0x17fd69);}};exports['logBlacklist']=function(_0x5d9ec8){var _0x173dae=moment()[_0x90c1('0x12')](_0x90c1('0x35'));_0x5d9ec8[_0x90c1('0x36')]=0xd;_0x5d9ec8['statedesc']='Blacklist';_0x5d9ec8[_0x90c1('0x37')]=_0x173dae;_0x5d9ec8[_0x90c1('0x38')]=_0x173dae;_0x5d9ec8[_0x90c1('0x39')]=_0x173dae;};exports[_0x90c1('0x3a')]=function(_0x295b4b,_0x5a5ccd,_0x56cb35){var _0x5760bc=moment()[_0x90c1('0x12')](_0x90c1('0x35'));_0x295b4b[_0x90c1('0x36')]=_0x5a5ccd;_0x295b4b['statedesc']=_0x56cb35;_0x295b4b[_0x90c1('0x38')]=_0x5760bc;_0x295b4b['ringtime']=getSeconds(_0x295b4b['responsetime'],_0x295b4b[_0x90c1('0x37')]);};exports[_0x90c1('0x3b')]=function(_0x4c0f52,_0x3ace43,_0x320ecb){_0x4c0f52[_0x90c1('0x3c')]=_0x3ace43;_0x4c0f52[_0x90c1('0x3d')]=_0x320ecb;};exports[_0x90c1('0x3e')]=function(_0x275731,_0x55969f,_0x3fb4ed){var _0x4c9d22=moment()[_0x90c1('0x12')](_0x90c1('0x35'));_0x275731[_0x90c1('0x36')]=_0x55969f;_0x275731[_0x90c1('0x3f')]=_0x3fb4ed;_0x275731[_0x90c1('0x38')]=_0x275731[_0x90c1('0x38')]?_0x275731[_0x90c1('0x38')]:_0x4c9d22;_0x275731['endtime']=_0x275731['endtime']?_0x275731[_0x90c1('0x39')]:_0x4c9d22;_0x275731[_0x90c1('0x40')]=getSeconds(_0x275731[_0x90c1('0x38')]||0x0,_0x275731[_0x90c1('0x37')]||0x0);_0x275731[_0x90c1('0x41')]=_0x275731['answertime']?getSeconds(_0x275731['endtime'],_0x275731[_0x90c1('0x42')]):0x0;};exports[_0x90c1('0x43')]=function(_0x5b1787){return _0x5b1787===_0x90c1('0x44');};exports['variablesAction']=function(_0x4caea7,_0xb59c6d,_0x479318,_0x454d9a,_0x56cf50){var _0x5b9959=_0x454d9a?_0x90c1('0x45'):_0x4caea7[_0x90c1('0x46')];_0x5b9959=_0x56cf50?_0x90c1('0x47'):_0x5b9959;return{'actionid':_0x4caea7[_0x90c1('0x48')],'action':'originate','channel':_0x4caea7[_0x90c1('0x49')],'callerid':util[_0x90c1('0x12')](_0x90c1('0x13'),_0x5b9959,_0x4caea7[_0x90c1('0x19')]),'Exten':'xcally-motion-preview','Context':_0x90c1('0x4a'),'Priority':'1','variable':_0x479318,'timeout':(_0xb59c6d[_0x90c1('0x4b')]||0x1e)*0x3e8,'async':!![],'channelid':_0x4caea7['uniqueid']};};exports[_0x90c1('0x4c')]=function(_0x136749){return _0x136749[_0x90c1('0x4d')]+_0x136749[_0x90c1('0x4e')]+_0x136749[_0x90c1('0x4f')]+_0x136749['countagentrejectretry']+_0x136749[_0x90c1('0x50')];};exports['cloneAction']=function(_0x304011){var _0x4dfe8b=_[_0x90c1('0x51')](_0x304011);_0x4dfe8b[_0x90c1('0x36')]=0xf;_0x4dfe8b[_0x90c1('0x3f')]=_0x90c1('0x52');return _0x4dfe8b;};exports[_0x90c1('0x53')]=function(_0x3aa812,_0x1d00e4,_0x23359c){var _0x38a3c1={};_0x38a3c1[_0x1d00e4]=_0x3aa812[_0x1d00e4];_0x38a3c1['active']=![];_0x38a3c1[_0x90c1('0x54')]=moment()['add'](_0x23359c,_0x90c1('0x55'))[_0x90c1('0x12')](_0x90c1('0x35'));_0x38a3c1[_0x90c1('0x56')]=_0x3aa812[_0x90c1('0x56')];_0x38a3c1[_0x90c1('0x57')]=_0x3aa812[_0x90c1('0x57')];_0x38a3c1[_0x90c1('0x1a')]=_0x3aa812[_0x90c1('0x1a')]||undefined;return _0x38a3c1;};exports[_0x90c1('0x58')]=function(_0x1d3c9c,_0x50e6d9){if(!_[_0x90c1('0x16')](_0x1d3c9c)){if(_0x1d3c9c[_0x90c1('0x59')]>0x0){_0x1d3c9c[_0x90c1('0x59')]-=0x1;}else{logger['error'](_0x50e6d9,_0x90c1('0x5a'));}}else{logger[_0x90c1('0xb')](_0x50e6d9,_0x90c1('0x5b'));}};exports['IsNotLoggedIn']=function(_0x48c7da){if(_0x48c7da<=0x0){return!![];}return![];};exports[_0x90c1('0x5c')]=function(_0x1d5723,_0x5a4940){_0x1d5723[_0x90c1('0x5d')]=_0x5a4940;_0x1d5723['name']=_0x1d5723['queue'];_0x1d5723['interface']=_0x1d5723[_0x90c1('0x49')];return _0x1d5723;};exports['buildAcw']=function(_0x38f50a){var _0x886cf0={};_0x886cf0[_0x90c1('0x5e')]=_0x38f50a[_0x90c1('0x5e')];_0x886cf0['interface']=_0x38f50a['channelAgent'];_0x886cf0[_0x90c1('0x48')]=_0x38f50a[_0x90c1('0x48')];return _0x886cf0;};exports[_0x90c1('0x5f')]=function(_0x12c67b){var _0x47fb9b=[];for(var _0x4a78ca in _0x12c67b){if(_0x12c67b[_0x90c1('0x28')](_0x4a78ca)){if(!_['isNil'](_0x12c67b[_0x4a78ca])&&_0x12c67b[_0x4a78ca][_0x90c1('0x36')]===_0x90c1('0x60')&&_0x12c67b[_0x4a78ca][_0x90c1('0x61')]===_0x90c1('0x62')){_0x47fb9b['push'](_0x12c67b[_0x4a78ca]['id']);}}}return _0x47fb9b;};exports[_0x90c1('0x63')]=function(_0x34fb7a){var _0x6a208f=moment()[_0x90c1('0x7')](0x0);var _0x3c6efb=moment(_0x34fb7a)[_0x90c1('0x7')](0x0);return _0x6a208f['diff'](_0x3c6efb,_0x90c1('0x9'));};exports[_0x90c1('0x64')]=function(_0xfcde43){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0xfcde43['ContactId'],'ListId':_0xfcde43[_0x90c1('0x57')],'VoiceQueueId':_0xfcde43[_0x90c1('0x1a')]||undefined,'CampaignId':_0xfcde43['CampaignId']||undefined};};exports['filterKey']=function(_0x1e82b5){if(_0x1e82b5===_0x90c1('0x48')||_0x1e82b5===_0x90c1('0x65')||_0x1e82b5===_0x90c1('0x5e')||_0x1e82b5==='type'||_0x1e82b5===_0x90c1('0x66')||_0x1e82b5===_0x90c1('0x67')||_0x1e82b5===_0x90c1('0x3c')||_0x1e82b5===_0x90c1('0x49')||_0x1e82b5==='calleridname'||_0x1e82b5==='active'||_0x1e82b5===_0x90c1('0x19')||_0x1e82b5===_0x90c1('0x54')||_0x1e82b5===_0x90c1('0x4d')||_0x1e82b5===_0x90c1('0x4e')||_0x1e82b5===_0x90c1('0x4f')||_0x1e82b5==='countglobal'||_0x1e82b5===_0x90c1('0x68')||_0x1e82b5===_0x90c1('0x69')||_0x1e82b5==='callbackat'||_0x1e82b5===_0x90c1('0x6a')||_0x1e82b5===_0x90c1('0x56')||_0x1e82b5===_0x90c1('0x57')||_0x1e82b5===_0x90c1('0x3d')||_0x1e82b5==='VoiceQueueId'||_0x1e82b5===_0x90c1('0x6b')||_0x1e82b5===_0x90c1('0x6c')||_0x1e82b5===_0x90c1('0x6d')||_0x1e82b5===_0x90c1('0x6e')||_0x1e82b5===_0x90c1('0x6f')||_0x1e82b5===_0x90c1('0x70')||_0x1e82b5===_0x90c1('0x71')||_0x1e82b5==='xmd-dialoptions'||_0x1e82b5==='xmd-dialid'||_0x1e82b5===_0x90c1('0x72')||_0x1e82b5===_0x90c1('0x73')||_0x1e82b5==='xmd-cdrtype'||_0x1e82b5===_0x90c1('0x74')||_0x1e82b5===_0x90c1('0x75')||_0x1e82b5===_0x90c1('0x76')||_0x1e82b5===_0x90c1('0x77')||_0x1e82b5===_0x90c1('0x78')||_0x1e82b5===_0x90c1('0x79')||_0x1e82b5==='rtpaudioqosjitterbridged'||_0x1e82b5==='rtpaudioqosloss'||_0x1e82b5===_0x90c1('0x7a')||_0x1e82b5===_0x90c1('0x7b')||_0x1e82b5===_0x90c1('0x7c')||_0x1e82b5===_0x90c1('0x77')||_0x1e82b5==='rtpaudioqosbridged'||_0x1e82b5==='rtpaudioqosjitter'||_0x1e82b5===_0x90c1('0x7d')||_0x1e82b5===_0x90c1('0x7e')||_0x1e82b5==='rtpaudioqoslossbridged'||_0x1e82b5===_0x90c1('0x7b')||_0x1e82b5===_0x90c1('0x7c')||_0x1e82b5===_0x90c1('0x7f')||_0x1e82b5===_0x90c1('0x80')||_0x1e82b5===_0x90c1('0x36')||_0x1e82b5===_0x90c1('0x3f')){return![];}return!![];};exports['getCallerIdRandom']=function(_0x4707da,_0x4834dd){var _0x7963d8,_0x1939a6,_0x13d9bb;if(_0x4834dd<=0x0){_0x4834dd=0x1;}_0x7963d8=new RegExp('\x5cw{0,'+_0x4834dd+'}$');_0x1939a6=Math['pow'](0xa,_0x4834dd-0x1);_0x13d9bb=Math['pow'](0xa,_0x4834dd)-0x1;return util[_0x90c1('0x12')]('%s',_[_0x90c1('0x81')](_0x4707da,_0x7963d8,_[_0x90c1('0x82')](_0x1939a6,_0x13d9bb)));};exports[_0x90c1('0x83')]=function(_0xda2a32){var _0x2a7a16=_0xda2a32[_0x90c1('0x84')](/"(.*?)"/);return _0x2a7a16?_0x2a7a16[0x1]:_0xda2a32;};exports[_0x90c1('0x85')]=function(_0xa4806d){var _0x12589a=_0xa4806d[_0x90c1('0x84')](/<(.*?)>/);return _0x12589a?_0x12589a[0x1]:_0xa4806d;};