Built motion from commit d1eab355.|2.6.28
[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 _0x8915=['_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','toLowerVariables','hasOwnProperty','toLower','updateOriginated','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','YYYY-MM-DD\x20HH:mm:ss','state','statedesc','endtime','logAgent','getSeconds','responsetime','starttime','logLookAgent','membername','UserId','answertime','isFailure','Failure','RECALL','BOOKED','uniqueid','originate','channelAgent','from-sip','timeout','countbusyretry','countcongestionretry','countnoanswerretry','countagentrejectretry','countnosuchnumberretry','cloneAction','clone','Global','scheduledAt','active','scheduledat','minutes','ListId','decrementTalkink','isNil','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','[decrementTalkink]\x20is\x20null\x20or\x20undefined','lastevent','queue','interface','motionChannel','voice','mandatoryDisposition','status','reachable','push','getDiff','milliseconds','createBody','CampaignId','filterKey','campaigntype','dialAnswer','callback','callbackuniqueid','callbackat','sipcallid','xmd-voicequeueid','xmd-phone','xmd-listid','xmd-dialtimeout','xmd-dialoptions','xmd-callerid','xmd-agiafter','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosloss','rtpaudioqosrtt','rtpaudioqosrttbridged','rtpaudioqosjitterbridged','bridgepeer','bridgepvtcallid','\x5cw{0,','pow','replace','extractCalleridName','match','noanswer','variables','keys','forEach','toLowerCase','buildNoAnswerEventPayload','util','lodash','../../../../config/logger','preview','env','../../dialer/utils','loggerCatch','error','inspect','loggerError','logger2','getCallerId','isUndefined','isEmpty','string','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isActive','addVariables','Queue','name','calleridname','calleridnum','ContactId','VoiceQueueId','dialOriginateTimeout','\x22rtTxX%s%s\x22','monitor_format','U(xcally-mixmonitor-context)','dialPreviewUrl','dialQueueProject','NONE','dialQueueProject2','\x22agi://%s/square,%s\x22','originatecalleridname','xcally-motion-preview'];(function(_0x491a7f,_0x28bb80){var _0x3d8f44=function(_0xdaa716){while(--_0xdaa716){_0x491a7f['push'](_0x491a7f['shift']());}};_0x3d8f44(++_0x28bb80);}(_0x8915,0xe7));var _0x5891=function(_0x3aaf0a,_0x450970){_0x3aaf0a=_0x3aaf0a-0x0;var _0x33e6bc=_0x8915[_0x3aaf0a];return _0x33e6bc;};'use strict';var util=require(_0x5891('0x0'));var _=require(_0x5891('0x1'));var moment=require('moment');var logger=require(_0x5891('0x2'))(_0x5891('0x3'));var ipAgi=process[_0x5891('0x4')]['XCALLY_IP_AGI']||'127.0.0.1';var utils=require(_0x5891('0x5'));exports[_0x5891('0x6')]=function(_0x4ff7c2){return function(_0x3add23){logger[_0x5891('0x7')](_0x4ff7c2,util[_0x5891('0x8')](_0x3add23,{'showHidden':![],'depth':null}));};};exports['logger']=function(_0xe27a16,_0x140b22){logger['info'](_0xe27a16,util['inspect'](_0x140b22,{'showHidden':![],'depth':null}));};exports[_0x5891('0x9')]=function(_0x14ed05,_0x4ff187){logger[_0x5891('0x7')](_0x14ed05,util[_0x5891('0x8')](_0x4ff187,{'showHidden':![],'depth':null}));};exports[_0x5891('0xa')]=function(_0x5e488e){return function(_0x3b8e84){logger['info'](_0x5e488e,util['inspect'](_0x3b8e84,{'showHidden':![],'depth':null}));};};exports['message']=function(_0xeb1b7d,_0xa7c689,_0x88179a){return{'message':_0xeb1b7d,'unlock':_0xa7c689,'active':_0x88179a};};exports[_0x5891('0xb')]=function(_0x807292,_0x3c32c0,_0x4d096c){if(!_[_0x5891('0xc')](_0x4d096c)&&'string'===typeof _0x4d096c&&!_[_0x5891('0xd')](_0x4d096c)){if(!_[_0x5891('0xc')](_0x3c32c0)&&_0x5891('0xe')===typeof _0x3c32c0&&!_[_0x5891('0xd')](_0x3c32c0)){return util[_0x5891('0xf')](_0x5891('0x10'),_0x3c32c0,_0x4d096c);}return util[_0x5891('0xf')](_0x5891('0x10'),_0x4d096c,_0x4d096c);}if(!_[_0x5891('0xc')](_0x807292)&&_0x5891('0xe')===typeof _0x807292&&!_[_0x5891('0xd')](_0x807292)){return _0x807292;}return _0x5891('0x11');};exports[_0x5891('0x12')]=function(_0x2a053f){if(_['isNil'](_0x2a053f)){return![];}return _0x2a053f;};exports[_0x5891('0x13')]=function(_0xd80814,_0x83ce21,_0x45c646,_0x8b34f6,_0x1fcff3,_0x116fb1){var _0x53ed6b={'XMD-QUEUE':_0x83ce21[_0x5891('0x14')]?_0x83ce21[_0x5891('0x14')][_0x5891('0x15')]:'','XMD-CALLERID':_0x8b34f6,'XMD-CALLERID-PREVIEW':_0x116fb1?util[_0x5891('0xf')](_0x5891('0x10'),_0x116fb1[_0x5891('0x16')],_0x116fb1[_0x5891('0x17')]):_0x8b34f6,'XMD-DIALID':_0x1fcff3,'XMD-CONTACTID':_0x83ce21[_0x5891('0x18')],'XMD-CDRTYPE':'dialer','CALLERID(all)':_0x8b34f6,'XMD-VOICEQUEUEID':_0x83ce21[_0x5891('0x19')],'XMD-DIALCHANNEL':_0x45c646,'XMD-DIALTIMEOUT':_0xd80814[_0x5891('0x1a')]||0x1e,'XMD-DIALOPTIONS':util[_0x5891('0xf')](_0x5891('0x1b'),_0xd80814['dialQueueProject2']?'g':'',_[_0x5891('0xd')](_0xd80814[_0x5891('0x1c')])?'':_0x5891('0x1d')),'XMD-DIALURL':_0xd80814[_0x5891('0x1e')]||'','XMD-AGI':_0xd80814['dialQueueProject']?util[_0x5891('0xf')]('\x22agi://%s/square,%s\x22',ipAgi,_0xd80814[_0x5891('0x1f')]):_0x5891('0x20'),'XMD-AGIAFTER':_0xd80814[_0x5891('0x21')]?util[_0x5891('0xf')](_0x5891('0x22'),ipAgi,_0xd80814[_0x5891('0x21')]):'NONE','XMD-ORIGINATECALLERIDNUM':_0x116fb1?_0x116fb1['originatecalleridnum']:'','XMD-ORIGINATECALLERIDNAME':_0x116fb1?_0x116fb1[_0x5891('0x23')]:'','XMD-DESTINATION':_0x5891('0x24'),'SIPADDHEADER':'Call-Type:\x20PREVIEW'};if(!_['isEmpty'](_0xd80814[_0x5891('0x1c')])){_0x53ed6b[util[_0x5891('0xf')]('%s',_0x5891('0x25'))]=_0xd80814[_0x5891('0x1c')];_0x53ed6b[util['format']('%s',_0x5891('0x26'))]=_0x1fcff3;}return _0x53ed6b;};exports[_0x5891('0x27')]=function(_0x21c0cf){var _0x23b7da={};for(var _0x100dfa in _0x21c0cf){if(_0x21c0cf[_0x5891('0x28')](_0x100dfa)){_0x23b7da[util[_0x5891('0xf')]('%s',_[_0x5891('0x29')](_0x100dfa))]=_0x21c0cf[_0x100dfa];}}return{'variables':_0x23b7da};};exports[_0x5891('0x2a')]=function(_0x2508cb,_0x4250bb){if(!_['isNil'](_0x2508cb)){if(_0x2508cb[_0x5891('0x28')](_0x5891('0x2b'))){if(_0x2508cb[_0x5891('0x2b')]>0x0){_0x2508cb[_0x5891('0x2b')]-=0x1;}else{logger[_0x5891('0x7')](_0x5891('0x2c'),_0x4250bb);}}}else{logger[_0x5891('0x7')](_0x5891('0x2d'),_0x4250bb);}};exports[_0x5891('0x2e')]=function(_0x127af9){var _0x4eaac5=moment()[_0x5891('0xf')](_0x5891('0x2f'));_0x127af9[_0x5891('0x30')]=0xd;_0x127af9[_0x5891('0x31')]='Blacklist';_0x127af9['starttime']=_0x4eaac5;_0x127af9['responsetime']=_0x4eaac5;_0x127af9[_0x5891('0x32')]=_0x4eaac5;};exports[_0x5891('0x33')]=function(_0x44e1b2,_0x541c06,_0x1b6cb2){var _0x1750d4=moment()[_0x5891('0xf')]('YYYY-MM-DD\x20HH:mm:ss');_0x44e1b2[_0x5891('0x30')]=_0x541c06;_0x44e1b2[_0x5891('0x31')]=_0x1b6cb2;_0x44e1b2['responsetime']=_0x1750d4;_0x44e1b2['ringtime']=utils[_0x5891('0x34')](_0x44e1b2[_0x5891('0x35')],_0x44e1b2[_0x5891('0x36')]);};exports[_0x5891('0x37')]=function(_0x5513ce,_0x49c1c9,_0xf08e76){_0x5513ce[_0x5891('0x38')]=_0x49c1c9;_0x5513ce[_0x5891('0x39')]=_0xf08e76;};exports['logCustomer']=function(_0x226812,_0x40750d,_0x371787){var _0x32d781=moment()['format'](_0x5891('0x2f'));_0x226812[_0x5891('0x30')]=_0x40750d;_0x226812[_0x5891('0x31')]=_0x371787;_0x226812[_0x5891('0x35')]=_0x226812[_0x5891('0x35')]?_0x226812[_0x5891('0x35')]:_0x32d781;_0x226812[_0x5891('0x32')]=_0x226812[_0x5891('0x32')]?_0x226812['endtime']:_0x32d781;_0x226812['ringtime']=utils[_0x5891('0x34')](_0x226812[_0x5891('0x35')]||0x0,_0x226812[_0x5891('0x36')]||0x0);_0x226812['talktime']=_0x226812['answertime']?utils[_0x5891('0x34')](_0x226812[_0x5891('0x32')],_0x226812[_0x5891('0x3a')]):0x0;};exports[_0x5891('0x3b')]=function(_0xd0c614){return _0xd0c614===_0x5891('0x3c');};exports['variablesAction']=function(_0x18e836,_0x2b10bd,_0x309513,_0x184912,_0x199b41){var _0x11905b=_0x184912?_0x5891('0x3d'):_0x18e836['calleridname'];_0x11905b=_0x199b41?_0x5891('0x3e'):_0x11905b;return{'actionid':_0x18e836[_0x5891('0x3f')],'action':_0x5891('0x40'),'channel':_0x18e836[_0x5891('0x41')],'callerid':util[_0x5891('0xf')]('\x22%s\x22\x20<%s>',_0x11905b,_0x18e836['calleridnum']),'Exten':_0x5891('0x24'),'Context':_0x5891('0x42'),'Priority':'1','variable':_0x309513,'timeout':(_0x2b10bd[_0x5891('0x43')]||0x1e)*0x3e8,'async':!![],'channelid':_0x18e836[_0x5891('0x3f')]};};exports['totalGlobal']=function(_0x25e9b4){return _0x25e9b4[_0x5891('0x44')]+_0x25e9b4[_0x5891('0x45')]+_0x25e9b4[_0x5891('0x46')]+_0x25e9b4[_0x5891('0x47')]+_0x25e9b4[_0x5891('0x48')];};exports[_0x5891('0x49')]=function(_0xe42e95){var _0x24dad6=_[_0x5891('0x4a')](_0xe42e95);_0x24dad6[_0x5891('0x30')]=0xf;_0x24dad6['statedesc']=_0x5891('0x4b');return _0x24dad6;};exports[_0x5891('0x4c')]=function(_0x276d63,_0x6e708e,_0x193981){var _0x28659e={};_0x28659e[_0x6e708e]=_0x276d63[_0x6e708e];_0x28659e[_0x5891('0x4d')]=![];_0x28659e[_0x5891('0x4e')]=moment()['add'](_0x193981,_0x5891('0x4f'))['format'](_0x5891('0x2f'));_0x28659e[_0x5891('0x18')]=_0x276d63[_0x5891('0x18')];_0x28659e[_0x5891('0x50')]=_0x276d63[_0x5891('0x50')];_0x28659e['VoiceQueueId']=_0x276d63[_0x5891('0x19')]||undefined;return _0x28659e;};exports[_0x5891('0x51')]=function(_0x1f7d3a,_0x40978e){if(!_[_0x5891('0x52')](_0x1f7d3a)){if(_0x1f7d3a[_0x5891('0x53')]>0x0){_0x1f7d3a[_0x5891('0x53')]-=0x1;}else{logger[_0x5891('0x7')](_0x40978e,_0x5891('0x54'));}}else{logger[_0x5891('0x7')](_0x40978e,_0x5891('0x55'));}};exports['IsNotLoggedIn']=function(_0x3b1055){if(_0x3b1055<=0x0){return!![];}return![];};function buildObj(_0x431a8e,_0xb51ebe,_0x43d76c){_0x431a8e[_0x5891('0x56')]=_0xb51ebe;_0x431a8e['name']=_0x431a8e[_0x5891('0x57')];_0x431a8e[_0x5891('0x58')]=_0x431a8e[_0x5891('0x41')];_0x431a8e[_0x5891('0x59')]=_0x5891('0x5a');if(_0x43d76c){_0x431a8e[_0x5891('0x5b')]=_0x43d76c[_0x5891('0x5b')];}return _0x431a8e;}exports['buildObj']=buildObj;exports['agentReadyId']=function(_0x468727){var _0x38497b=[];for(var _0x34aa26 in _0x468727){if(_0x468727[_0x5891('0x28')](_0x34aa26)){if(!_[_0x5891('0x52')](_0x468727[_0x34aa26])&&_0x468727[_0x34aa26][_0x5891('0x30')]==='not_inuse'&&_0x468727[_0x34aa26][_0x5891('0x5c')]===_0x5891('0x5d')){_0x38497b[_0x5891('0x5e')](_0x468727[_0x34aa26]['id']);}}}return _0x38497b;};exports[_0x5891('0x5f')]=function(_0xbe0f91){var _0x594e50=moment()[_0x5891('0x60')](0x0);var _0x155a9c=moment(_0xbe0f91)[_0x5891('0x60')](0x0);return _0x594e50['diff'](_0x155a9c,'seconds');};exports[_0x5891('0x61')]=function(_0x2c7691){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x2c7691['ContactId'],'ListId':_0x2c7691['ListId'],'VoiceQueueId':_0x2c7691[_0x5891('0x19')]||undefined,'CampaignId':_0x2c7691[_0x5891('0x62')]||undefined};};exports[_0x5891('0x63')]=function(_0x3094ed){if(_0x3094ed==='uniqueid'||_0x3094ed==='idContact'||_0x3094ed===_0x5891('0x57')||_0x3094ed==='type'||_0x3094ed===_0x5891('0x64')||_0x3094ed===_0x5891('0x65')||_0x3094ed===_0x5891('0x38')||_0x3094ed===_0x5891('0x41')||_0x3094ed===_0x5891('0x16')||_0x3094ed===_0x5891('0x4d')||_0x3094ed==='calleridnum'||_0x3094ed===_0x5891('0x4e')||_0x3094ed===_0x5891('0x44')||_0x3094ed===_0x5891('0x45')||_0x3094ed===_0x5891('0x46')||_0x3094ed==='countglobal'||_0x3094ed===_0x5891('0x66')||_0x3094ed===_0x5891('0x67')||_0x3094ed===_0x5891('0x68')||_0x3094ed==='recallme'||_0x3094ed===_0x5891('0x18')||_0x3094ed===_0x5891('0x50')||_0x3094ed===_0x5891('0x39')||_0x3094ed===_0x5891('0x19')||_0x3094ed===_0x5891('0x69')||_0x3094ed===_0x5891('0x6a')||_0x3094ed==='xmd-queue'||_0x3094ed===_0x5891('0x6b')||_0x3094ed===_0x5891('0x6c')||_0x3094ed==='xmd-dialurl'||_0x3094ed===_0x5891('0x6d')||_0x3094ed===_0x5891('0x6e')||_0x3094ed==='xmd-dialid'||_0x3094ed==='xmd-dialchannel'||_0x3094ed==='xmd-contactid'||_0x3094ed==='xmd-cdrtype'||_0x3094ed===_0x5891('0x6f')||_0x3094ed===_0x5891('0x70')||_0x3094ed===_0x5891('0x71')||_0x3094ed===_0x5891('0x72')||_0x3094ed===_0x5891('0x73')||_0x3094ed===_0x5891('0x74')||_0x3094ed==='rtpaudioqosjitterbridged'||_0x3094ed===_0x5891('0x75')||_0x3094ed==='rtpaudioqoslossbridged'||_0x3094ed===_0x5891('0x76')||_0x3094ed===_0x5891('0x77')||_0x3094ed===_0x5891('0x72')||_0x3094ed===_0x5891('0x73')||_0x3094ed===_0x5891('0x74')||_0x3094ed===_0x5891('0x78')||_0x3094ed==='rtpaudioqosloss'||_0x3094ed==='rtpaudioqoslossbridged'||_0x3094ed===_0x5891('0x76')||_0x3094ed==='rtpaudioqosrttbridged'||_0x3094ed===_0x5891('0x79')||_0x3094ed===_0x5891('0x7a')||_0x3094ed===_0x5891('0x30')||_0x3094ed===_0x5891('0x31')){return![];}return!![];};exports['getCallerIdRandom']=function(_0x2b71b2,_0x1a8075){var _0x34be97,_0x2da4f4,_0x3929c8;if(_0x1a8075<=0x0){_0x1a8075=0x1;}_0x34be97=new RegExp(_0x5891('0x7b')+_0x1a8075+'}$');_0x2da4f4=Math[_0x5891('0x7c')](0xa,_0x1a8075-0x1);_0x3929c8=Math[_0x5891('0x7c')](0xa,_0x1a8075)-0x1;return util[_0x5891('0xf')]('%s',_[_0x5891('0x7d')](_0x2b71b2,_0x34be97,_['random'](_0x2da4f4,_0x3929c8)));};exports[_0x5891('0x7e')]=function(_0x7b10f2){var _0x4df5a3=_0x7b10f2[_0x5891('0x7f')](/"(.*?)"/);return _0x4df5a3?_0x4df5a3[0x1]:_0x7b10f2;};exports['extractCalleridNumber']=function(_0x198990){var _0x591c77=_0x198990[_0x5891('0x7f')](/<(.*?)>/);return _0x591c77?_0x591c77[0x1]:_0x198990;};function buildNoAnswerEventPayload(_0x359659,_0x25a324){var _0x15ba6a=buildObj(_0x359659,_0x5891('0x80'));if(!_[_0x5891('0xd')](_0x25a324[_0x5891('0x81')])){Object[_0x5891('0x82')](_0x25a324['variables'])[_0x5891('0x83')](function(_0x3bfec7){_0x15ba6a[_0x3bfec7[_0x5891('0x84')]()]=_0x25a324[_0x5891('0x81')][_0x3bfec7];});}return _0x15ba6a;}exports[_0x5891('0x85')]=buildNoAnswerEventPayload;