4449fc9bf4c93575d7f303727597ebd93db1f4d0
[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 _0x76f5=['moment','../../../../config/logger','env','loggerCatch','inspect','info','loggerError','error','logger2','message','getCallerId','isUndefined','string','isEmpty','\x22%s\x22\x20<%s>','format','isActive','Queue','calleridnum','ContactId','VoiceQueueId','dialOriginateTimeout','dialQueueProject2','monitor_format','U(xcally-mixmonitor-context)','dialQueueProject','\x22agi://%s/square,%s\x22','NONE','originatecalleridnum','originatecalleridname','xcally-motion-preview','Call-Type:\x20PREVIEW','_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','Contact','hasOwnProperty','createdAt','updatedAt','%s%s','XMD-','toUpper','toLower','updateOriginated','isNil','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','YYYY-MM-DD\x20HH:mm:ss','statedesc','Blacklist','starttime','endtime','logAgent','state','responsetime','ringtime','logLookAgent','membername','logCustomer','getSeconds','talktime','answertime','isFailure','Failure','RECALL','calleridname','BOOKED','uniqueid','originate','from-sip','timeout','countbusyretry','countcongestionretry','countnoanswerretry','countagentrejectretry','cloneAction','clone','scheduledAt','active','add','minutes','ListId','decrementTalkink','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','[decrementTalkink]\x20is\x20null\x20or\x20undefined','lastevent','queue','interface','channelAgent','motionChannel','voice','mandatoryDisposition','buildObj','buildAcw','agentReadyId','not_inuse','status','reachable','push','getDiff','milliseconds','diff','seconds','createBody','CampaignId','filterKey','idContact','type','campaigntype','dialAnswer','scheduledat','countglobal','callback','callbackuniqueid','callbackat','recallme','UserId','sipcallid','xmd-voicequeueid','xmd-phone','xmd-listid','xmd-dialurl','xmd-dialoptions','xmd-dialchannel','xmd-contactid','xmd-callerid','xmd-agiafter','xmd-agi','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','rtpaudioqos','bridgepvtcallid','\x5cw{0,','pow','replace','random','extractCalleridName','extractCalleridNumber','match','noanswer','keys','variables','forEach','toLowerCase','util','lodash'];(function(_0x2c112a,_0x5815d4){var _0x5d22db=function(_0x3a2ea2){while(--_0x3a2ea2){_0x2c112a['push'](_0x2c112a['shift']());}};_0x5d22db(++_0x5815d4);}(_0x76f5,0x97));var _0x576f=function(_0x192f16,_0x454664){_0x192f16=_0x192f16-0x0;var _0x5b6b0b=_0x76f5[_0x192f16];return _0x5b6b0b;};'use strict';var util=require(_0x576f('0x0'));var _=require(_0x576f('0x1'));var moment=require(_0x576f('0x2'));var logger=require(_0x576f('0x3'))('preview');var ipAgi=process[_0x576f('0x4')]['XCALLY_IP_AGI']||'127.0.0.1';var utils=require('../../dialer/utils');exports[_0x576f('0x5')]=function(_0x281f2a){return function(_0x5547ad){logger['error'](_0x281f2a,util[_0x576f('0x6')](_0x5547ad,{'showHidden':![],'depth':null}));};};exports['logger']=function(_0x489ef7,_0x32cf7a){logger[_0x576f('0x7')](_0x489ef7,util['inspect'](_0x32cf7a,{'showHidden':![],'depth':null}));};exports[_0x576f('0x8')]=function(_0x556856,_0x1ba685){logger[_0x576f('0x9')](_0x556856,util[_0x576f('0x6')](_0x1ba685,{'showHidden':![],'depth':null}));};exports[_0x576f('0xa')]=function(_0x5e17df){return function(_0x1371ad){logger[_0x576f('0x7')](_0x5e17df,util[_0x576f('0x6')](_0x1371ad,{'showHidden':![],'depth':null}));};};exports[_0x576f('0xb')]=function(_0x1e01a4,_0x4ed9f,_0xbc2516){return{'message':_0x1e01a4,'unlock':_0x4ed9f,'active':_0xbc2516};};exports[_0x576f('0xc')]=function(_0xd9398b,_0x41c475,_0x1f7f02){if(!_[_0x576f('0xd')](_0x1f7f02)&&_0x576f('0xe')===typeof _0x1f7f02&&!_['isEmpty'](_0x1f7f02)){if(!_[_0x576f('0xd')](_0x41c475)&&_0x576f('0xe')===typeof _0x41c475&&!_[_0x576f('0xf')](_0x41c475)){return util['format'](_0x576f('0x10'),_0x41c475,_0x1f7f02);}return util[_0x576f('0x11')](_0x576f('0x10'),_0x1f7f02,_0x1f7f02);}if(!_['isUndefined'](_0xd9398b)&&_0x576f('0xe')===typeof _0xd9398b&&!_[_0x576f('0xf')](_0xd9398b)){return _0xd9398b;}return'\x22\x22\x20<>';};exports[_0x576f('0x12')]=function(_0xe51263){if(_['isNil'](_0xe51263)){return![];}return _0xe51263;};exports['addVariables']=function(_0x1c59d6,_0x431549,_0x44f551,_0x25ec24,_0x1effe7,_0x2ba79e){var _0x2ce909={'XMD-QUEUE':_0x431549[_0x576f('0x13')]?_0x431549['Queue']['name']:'','XMD-CALLERID':_0x25ec24,'XMD-CALLERID-PREVIEW':_0x2ba79e?util['format'](_0x576f('0x10'),_0x2ba79e['calleridname'],_0x2ba79e[_0x576f('0x14')]):_0x25ec24,'XMD-DIALID':_0x1effe7,'XMD-CONTACTID':_0x431549[_0x576f('0x15')],'XMD-CDRTYPE':'dialer','CALLERID(all)':_0x25ec24,'XMD-VOICEQUEUEID':_0x431549[_0x576f('0x16')],'XMD-DIALCHANNEL':_0x44f551,'XMD-DIALTIMEOUT':_0x1c59d6[_0x576f('0x17')]||0x1e,'XMD-DIALOPTIONS':util['format']('\x22rtTxX%s%s\x22',_0x1c59d6[_0x576f('0x18')]?'g':'',_[_0x576f('0xf')](_0x1c59d6[_0x576f('0x19')])?'':_0x576f('0x1a')),'XMD-DIALURL':_0x1c59d6['dialPreviewUrl']||'','XMD-AGI':_0x1c59d6[_0x576f('0x1b')]?util['format'](_0x576f('0x1c'),ipAgi,_0x1c59d6[_0x576f('0x1b')]):_0x576f('0x1d'),'XMD-AGIAFTER':_0x1c59d6['dialQueueProject2']?util[_0x576f('0x11')](_0x576f('0x1c'),ipAgi,_0x1c59d6['dialQueueProject2']):_0x576f('0x1d'),'XMD-ORIGINATECALLERIDNUM':_0x2ba79e?_0x2ba79e[_0x576f('0x1e')]:'','XMD-ORIGINATECALLERIDNAME':_0x2ba79e?_0x2ba79e[_0x576f('0x1f')]:'','XMD-DESTINATION':_0x576f('0x20'),'SIPADDHEADER':_0x576f('0x21')};if(!_[_0x576f('0xf')](_0x1c59d6['monitor_format'])){_0x2ce909[util['format']('%s',_0x576f('0x22'))]=_0x1c59d6[_0x576f('0x19')];_0x2ce909[util[_0x576f('0x11')]('%s',_0x576f('0x23'))]=_0x1effe7;}if(_0x431549&&_0x431549['Contact']){for(var _0x5371e8 in _0x431549['Contact']){if(_0x431549[_0x576f('0x24')][_0x576f('0x25')](_0x5371e8)){if(!_['isNil'](_0x431549[_0x576f('0x24')][_0x5371e8])&&_0x5371e8!=='id'&&_0x5371e8!=='tags'&&_0x5371e8!==_0x576f('0x26')&&_0x5371e8!==_0x576f('0x27')){_0x2ce909[util[_0x576f('0x11')](_0x576f('0x28'),_0x576f('0x29'),_[_0x576f('0x2a')](_0x5371e8))]=_0x431549[_0x576f('0x24')][_0x5371e8];}}}}return _0x2ce909;};exports['toLowerVariables']=function(_0x4b822f){var _0x2dce58={};for(var _0x56f04f in _0x4b822f){if(_0x4b822f['hasOwnProperty'](_0x56f04f)){_0x2dce58[util[_0x576f('0x11')]('%s',_[_0x576f('0x2b')](_0x56f04f))]=_0x4b822f[_0x56f04f];}}return{'variables':_0x2dce58};};exports[_0x576f('0x2c')]=function(_0x583186,_0x5d42c3){if(!_[_0x576f('0x2d')](_0x583186)){if(_0x583186[_0x576f('0x25')](_0x576f('0x2e'))){if(_0x583186['originated']>0x0){_0x583186['originated']-=0x1;}else{logger[_0x576f('0x9')](_0x576f('0x2f'),_0x5d42c3);}}}else{logger[_0x576f('0x9')](_0x576f('0x30'),_0x5d42c3);}};exports[_0x576f('0x31')]=function(_0x27769f){var _0xaabaa5=moment()[_0x576f('0x11')](_0x576f('0x32'));_0x27769f['state']=0xd;_0x27769f[_0x576f('0x33')]=_0x576f('0x34');_0x27769f[_0x576f('0x35')]=_0xaabaa5;_0x27769f['responsetime']=_0xaabaa5;_0x27769f[_0x576f('0x36')]=_0xaabaa5;};exports[_0x576f('0x37')]=function(_0x141323,_0x455806,_0x40b44c){var _0x18000e=moment()['format'](_0x576f('0x32'));_0x141323[_0x576f('0x38')]=_0x455806;_0x141323[_0x576f('0x33')]=_0x40b44c;_0x141323[_0x576f('0x39')]=_0x18000e;_0x141323[_0x576f('0x3a')]=utils['getSeconds'](_0x141323[_0x576f('0x39')],_0x141323['starttime']);};exports[_0x576f('0x3b')]=function(_0x293e7c,_0x85d6f5,_0x1f13c1){_0x293e7c[_0x576f('0x3c')]=_0x85d6f5;_0x293e7c['UserId']=_0x1f13c1;};exports[_0x576f('0x3d')]=function(_0x14c381,_0x18e792,_0x3faab8){var _0x18616d=moment()[_0x576f('0x11')](_0x576f('0x32'));_0x14c381['state']=_0x18e792;_0x14c381['statedesc']=_0x3faab8;_0x14c381[_0x576f('0x39')]=_0x14c381[_0x576f('0x39')]?_0x14c381['responsetime']:_0x18616d;_0x14c381[_0x576f('0x36')]=_0x14c381[_0x576f('0x36')]?_0x14c381['endtime']:_0x18616d;_0x14c381[_0x576f('0x3a')]=utils[_0x576f('0x3e')](_0x14c381['responsetime']||0x0,_0x14c381['starttime']||0x0);_0x14c381[_0x576f('0x3f')]=_0x14c381[_0x576f('0x40')]?utils['getSeconds'](_0x14c381[_0x576f('0x36')],_0x14c381[_0x576f('0x40')]):0x0;};exports[_0x576f('0x41')]=function(_0x46f5c4){return _0x46f5c4===_0x576f('0x42');};exports['variablesAction']=function(_0x361377,_0x44cc77,_0x2a959c,_0x422d1f,_0x327397){var _0x3ad0ff=_0x422d1f?_0x576f('0x43'):_0x361377[_0x576f('0x44')];_0x3ad0ff=_0x327397?_0x576f('0x45'):_0x3ad0ff;return{'actionid':_0x361377[_0x576f('0x46')],'action':_0x576f('0x47'),'channel':_0x361377['channelAgent'],'callerid':util[_0x576f('0x11')]('\x22%s\x22\x20<%s>',_0x3ad0ff,_0x361377[_0x576f('0x14')]),'Exten':'xcally-motion-preview','Context':_0x576f('0x48'),'Priority':'1','variable':_0x2a959c,'timeout':(_0x44cc77[_0x576f('0x49')]||0x1e)*0x3e8,'async':!![],'channelid':_0x361377[_0x576f('0x46')]};};exports['totalGlobal']=function(_0x3e4bcd){return _0x3e4bcd[_0x576f('0x4a')]+_0x3e4bcd[_0x576f('0x4b')]+_0x3e4bcd[_0x576f('0x4c')]+_0x3e4bcd[_0x576f('0x4d')]+_0x3e4bcd['countnosuchnumberretry'];};exports[_0x576f('0x4e')]=function(_0x195baf){var _0x427e4d=_[_0x576f('0x4f')](_0x195baf);_0x427e4d['state']=0xf;_0x427e4d[_0x576f('0x33')]='Global';return _0x427e4d;};exports[_0x576f('0x50')]=function(_0x2f2453,_0x370725,_0x4ee663){var _0x493c62={};_0x493c62[_0x370725]=_0x2f2453[_0x370725];_0x493c62[_0x576f('0x51')]=![];_0x493c62['scheduledat']=moment()[_0x576f('0x52')](_0x4ee663,_0x576f('0x53'))[_0x576f('0x11')](_0x576f('0x32'));_0x493c62[_0x576f('0x15')]=_0x2f2453['ContactId'];_0x493c62[_0x576f('0x54')]=_0x2f2453[_0x576f('0x54')];_0x493c62[_0x576f('0x16')]=_0x2f2453[_0x576f('0x16')]||undefined;return _0x493c62;};exports[_0x576f('0x55')]=function(_0x3d655f,_0x3fafdf){if(!_[_0x576f('0x2d')](_0x3d655f)){if(_0x3d655f['pTalking']>0x0){_0x3d655f[_0x576f('0x56')]-=0x1;}else{logger[_0x576f('0x9')](_0x3fafdf,_0x576f('0x57'));}}else{logger[_0x576f('0x9')](_0x3fafdf,_0x576f('0x58'));}};exports['IsNotLoggedIn']=function(_0x535a74){if(_0x535a74<=0x0){return!![];}return![];};function buildObj(_0x2a182d,_0x241c23,_0x17ae0b){_0x2a182d[_0x576f('0x59')]=_0x241c23;_0x2a182d['name']=_0x2a182d[_0x576f('0x5a')];_0x2a182d[_0x576f('0x5b')]=_0x2a182d[_0x576f('0x5c')];_0x2a182d[_0x576f('0x5d')]=_0x576f('0x5e');if(_0x17ae0b){_0x2a182d[_0x576f('0x5f')]=_0x17ae0b[_0x576f('0x5f')];}return _0x2a182d;}exports[_0x576f('0x60')]=buildObj;exports[_0x576f('0x61')]=function(_0x2a87f3){var _0x1999f4={};_0x1999f4[_0x576f('0x5a')]=_0x2a87f3['queue'];_0x1999f4['interface']=_0x2a87f3[_0x576f('0x5c')];_0x1999f4[_0x576f('0x46')]=_0x2a87f3['uniqueid'];return _0x1999f4;};exports[_0x576f('0x62')]=function(_0x574f5f){var _0x3d400c=[];for(var _0x2ab938 in _0x574f5f){if(_0x574f5f[_0x576f('0x25')](_0x2ab938)){if(!_[_0x576f('0x2d')](_0x574f5f[_0x2ab938])&&_0x574f5f[_0x2ab938][_0x576f('0x38')]===_0x576f('0x63')&&_0x574f5f[_0x2ab938][_0x576f('0x64')]===_0x576f('0x65')){_0x3d400c[_0x576f('0x66')](_0x574f5f[_0x2ab938]['id']);}}}return _0x3d400c;};exports[_0x576f('0x67')]=function(_0x3ed11d){var _0x15ab67=moment()[_0x576f('0x68')](0x0);var _0xcdb906=moment(_0x3ed11d)[_0x576f('0x68')](0x0);return _0x15ab67[_0x576f('0x69')](_0xcdb906,_0x576f('0x6a'));};exports[_0x576f('0x6b')]=function(_0x459471){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x459471[_0x576f('0x15')],'ListId':_0x459471['ListId'],'VoiceQueueId':_0x459471[_0x576f('0x16')]||undefined,'CampaignId':_0x459471[_0x576f('0x6c')]||undefined};};exports[_0x576f('0x6d')]=function(_0x15ae2e){if(_0x15ae2e===_0x576f('0x46')||_0x15ae2e===_0x576f('0x6e')||_0x15ae2e===_0x576f('0x5a')||_0x15ae2e===_0x576f('0x6f')||_0x15ae2e===_0x576f('0x70')||_0x15ae2e===_0x576f('0x71')||_0x15ae2e===_0x576f('0x3c')||_0x15ae2e==='channelAgent'||_0x15ae2e==='calleridname'||_0x15ae2e===_0x576f('0x51')||_0x15ae2e==='calleridnum'||_0x15ae2e===_0x576f('0x72')||_0x15ae2e==='countbusyretry'||_0x15ae2e==='countcongestionretry'||_0x15ae2e==='countnoanswerretry'||_0x15ae2e===_0x576f('0x73')||_0x15ae2e===_0x576f('0x74')||_0x15ae2e===_0x576f('0x75')||_0x15ae2e===_0x576f('0x76')||_0x15ae2e===_0x576f('0x77')||_0x15ae2e===_0x576f('0x15')||_0x15ae2e===_0x576f('0x54')||_0x15ae2e===_0x576f('0x78')||_0x15ae2e===_0x576f('0x16')||_0x15ae2e===_0x576f('0x79')||_0x15ae2e===_0x576f('0x7a')||_0x15ae2e==='xmd-queue'||_0x15ae2e===_0x576f('0x7b')||_0x15ae2e===_0x576f('0x7c')||_0x15ae2e===_0x576f('0x7d')||_0x15ae2e==='xmd-dialtimeout'||_0x15ae2e===_0x576f('0x7e')||_0x15ae2e==='xmd-dialid'||_0x15ae2e===_0x576f('0x7f')||_0x15ae2e===_0x576f('0x80')||_0x15ae2e==='xmd-cdrtype'||_0x15ae2e===_0x576f('0x81')||_0x15ae2e===_0x576f('0x82')||_0x15ae2e===_0x576f('0x83')||_0x15ae2e==='rtpaudioqos'||_0x15ae2e===_0x576f('0x84')||_0x15ae2e===_0x576f('0x85')||_0x15ae2e===_0x576f('0x86')||_0x15ae2e===_0x576f('0x87')||_0x15ae2e===_0x576f('0x88')||_0x15ae2e===_0x576f('0x89')||_0x15ae2e===_0x576f('0x8a')||_0x15ae2e===_0x576f('0x8b')||_0x15ae2e==='rtpaudioqosbridged'||_0x15ae2e===_0x576f('0x85')||_0x15ae2e===_0x576f('0x86')||_0x15ae2e===_0x576f('0x87')||_0x15ae2e===_0x576f('0x88')||_0x15ae2e==='rtpaudioqosrtt'||_0x15ae2e===_0x576f('0x8a')||_0x15ae2e==='bridgepeer'||_0x15ae2e===_0x576f('0x8c')||_0x15ae2e===_0x576f('0x38')||_0x15ae2e===_0x576f('0x33')){return![];}return!![];};exports['getCallerIdRandom']=function(_0x1a58a1,_0x32d334){var _0x3b142b,_0x52877a,_0x2ddbba;if(_0x32d334<=0x0){_0x32d334=0x1;}_0x3b142b=new RegExp(_0x576f('0x8d')+_0x32d334+'}$');_0x52877a=Math[_0x576f('0x8e')](0xa,_0x32d334-0x1);_0x2ddbba=Math['pow'](0xa,_0x32d334)-0x1;return util['format']('%s',_[_0x576f('0x8f')](_0x1a58a1,_0x3b142b,_[_0x576f('0x90')](_0x52877a,_0x2ddbba)));};exports[_0x576f('0x91')]=function(_0x332d32){var _0x3ea5c2=_0x332d32['match'](/"(.*?)"/);return _0x3ea5c2?_0x3ea5c2[0x1]:_0x332d32;};exports[_0x576f('0x92')]=function(_0x3f73d1){var _0x430d2d=_0x3f73d1[_0x576f('0x93')](/<(.*?)>/);return _0x430d2d?_0x430d2d[0x1]:_0x3f73d1;};function buildNoAnswerEventPayload(_0x37035f,_0x47cf97){var _0x338e37=buildObj(_0x37035f,_0x576f('0x94'));if(!_[_0x576f('0xf')](_0x47cf97['variables'])){Object[_0x576f('0x95')](_0x47cf97[_0x576f('0x96')])[_0x576f('0x97')](function(_0x30f903){_0x338e37[_0x30f903[_0x576f('0x98')]()]=_0x47cf97[_0x576f('0x96')][_0x30f903];});}return _0x338e37;}exports['buildNoAnswerEventPayload']=buildNoAnswerEventPayload;