d342a4ae1c875cc18b0327f675c68481865c9e70
[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 _0xdfff=['pow','replace','random','extractCalleridName','match','extractCalleridNumber','util','lodash','moment','../../../../config/logger','env','127.0.0.1','milliseconds','diff','seconds','error','inspect','logger','loggerError','logger2','info','message','isUndefined','isEmpty','string','format','\x22\x22\x20<>','isNil','addVariables','Queue','name','\x22%s\x22\x20<%s>','calleridname','ContactId','dialer','VoiceQueueId','dialOriginateTimeout','dialQueueProject2','monitor_format','dialPreviewUrl','dialQueueProject','\x22agi://%s/square,%s\x22','NONE','xcally-motion-preview','Call-Type:\x20PREVIEW','_XCALLY_MIXMONITOR_FORMAT','Contact','hasOwnProperty','tags','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','Blacklist','starttime','responsetime','statedesc','ringtime','logLookAgent','membername','UserId','endtime','talktime','answertime','isFailure','Failure','variablesAction','RECALL','BOOKED','uniqueid','originate','channelAgent','calleridnum','countbusyretry','countnoanswerretry','countagentrejectretry','cloneAction','clone','scheduledAt','active','scheduledat','add','minutes','ListId','[decrementTalkink]\x20object\x20talking\x20is\x20negative','[decrementTalkink]\x20is\x20null\x20or\x20undefined','IsNotLoggedIn','lastevent','queue','interface','motionChannel','voice','mandatoryDisposition','agentReadyId','not_inuse','status','reachable','push','getDiff','CampaignId','idContact','campaigntype','dialAnswer','countcongestionretry','countglobal','callback','callbackuniqueid','callbackat','xmd-voicequeueid','xmd-phone','xmd-dialurl','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-dialchannel','xmd-callerid','xmd-agiafter','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrttbridged','bridgepvtcallid','\x5cw{0,'];(function(_0x32f26d,_0x2c0b5d){var _0x5d9ddc=function(_0x1f0e26){while(--_0x1f0e26){_0x32f26d['push'](_0x32f26d['shift']());}};_0x5d9ddc(++_0x2c0b5d);}(_0xdfff,0x19b));var _0xfdff=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xdfff[_0x3dd15e];return _0x231fd0;};'use strict';var util=require(_0xfdff('0x0'));var _=require(_0xfdff('0x1'));var moment=require(_0xfdff('0x2'));var logger=require(_0xfdff('0x3'))('preview');var ipAgi=process[_0xfdff('0x4')]['XCALLY_IP_AGI']||_0xfdff('0x5');function getSeconds(_0x5cb799,_0x5f5060){var _0x3c5afb=moment(_0x5cb799)['milliseconds'](0x0);var _0x185d31=moment(_0x5f5060)[_0xfdff('0x6')](0x0);return _0x3c5afb[_0xfdff('0x7')](_0x185d31,_0xfdff('0x8'));}exports['loggerCatch']=function(_0x518b8e){return function(_0x478a7c){logger[_0xfdff('0x9')](_0x518b8e,util[_0xfdff('0xa')](_0x478a7c,{'showHidden':![],'depth':null}));};};exports[_0xfdff('0xb')]=function(_0x35b2f7,_0x27bb4f){logger['info'](_0x35b2f7,util[_0xfdff('0xa')](_0x27bb4f,{'showHidden':![],'depth':null}));};exports[_0xfdff('0xc')]=function(_0x1a217f,_0x319f15){logger['error'](_0x1a217f,util[_0xfdff('0xa')](_0x319f15,{'showHidden':![],'depth':null}));};exports[_0xfdff('0xd')]=function(_0x36bf4b){return function(_0x1a08c3){logger[_0xfdff('0xe')](_0x36bf4b,util[_0xfdff('0xa')](_0x1a08c3,{'showHidden':![],'depth':null}));};};exports[_0xfdff('0xf')]=function(_0x3cb150,_0x5b0b22,_0x3737d8){return{'message':_0x3cb150,'unlock':_0x5b0b22,'active':_0x3737d8};};exports['getCallerId']=function(_0x3673c4,_0x49e6c8,_0x4bff46){if(!_[_0xfdff('0x10')](_0x4bff46)&&'string'===typeof _0x4bff46&&!_[_0xfdff('0x11')](_0x4bff46)){if(!_[_0xfdff('0x10')](_0x49e6c8)&&_0xfdff('0x12')===typeof _0x49e6c8&&!_[_0xfdff('0x11')](_0x49e6c8)){return util[_0xfdff('0x13')]('\x22%s\x22\x20<%s>',_0x49e6c8,_0x4bff46);}return util[_0xfdff('0x13')]('\x22%s\x22\x20<%s>',_0x4bff46,_0x4bff46);}if(!_[_0xfdff('0x10')](_0x3673c4)&&_0xfdff('0x12')===typeof _0x3673c4&&!_[_0xfdff('0x11')](_0x3673c4)){return _0x3673c4;}return _0xfdff('0x14');};exports['isActive']=function(_0x1b6e28){if(_[_0xfdff('0x15')](_0x1b6e28)){return![];}return _0x1b6e28;};exports[_0xfdff('0x16')]=function(_0x6025d,_0x3b4892,_0x4aac2f,_0x107979,_0x5081fb,_0x322881){var _0x38c417={'XMD-QUEUE':_0x3b4892[_0xfdff('0x17')]?_0x3b4892[_0xfdff('0x17')][_0xfdff('0x18')]:'','XMD-CALLERID':_0x107979,'XMD-CALLERID-PREVIEW':_0x322881?util[_0xfdff('0x13')](_0xfdff('0x19'),_0x322881[_0xfdff('0x1a')],_0x322881['calleridnum']):_0x107979,'XMD-DIALID':_0x5081fb,'XMD-CONTACTID':_0x3b4892[_0xfdff('0x1b')],'XMD-CDRTYPE':_0xfdff('0x1c'),'CALLERID(all)':_0x107979,'XMD-VOICEQUEUEID':_0x3b4892[_0xfdff('0x1d')],'XMD-DIALCHANNEL':_0x4aac2f,'XMD-DIALTIMEOUT':_0x6025d[_0xfdff('0x1e')]||0x1e,'XMD-DIALOPTIONS':util['format']('\x22rtTxX%s%s\x22',_0x6025d[_0xfdff('0x1f')]?'g':'',_[_0xfdff('0x11')](_0x6025d[_0xfdff('0x20')])?'':'U(xcally-mixmonitor-context)'),'XMD-DIALURL':_0x6025d[_0xfdff('0x21')]||'','XMD-AGI':_0x6025d[_0xfdff('0x22')]?util['format'](_0xfdff('0x23'),ipAgi,_0x6025d[_0xfdff('0x22')]):_0xfdff('0x24'),'XMD-AGIAFTER':_0x6025d[_0xfdff('0x1f')]?util[_0xfdff('0x13')](_0xfdff('0x23'),ipAgi,_0x6025d[_0xfdff('0x1f')]):_0xfdff('0x24'),'XMD-ORIGINATECALLERIDNUM':_0x322881?_0x322881['originatecalleridnum']:'','XMD-ORIGINATECALLERIDNAME':_0x322881?_0x322881['originatecalleridname']:'','XMD-DESTINATION':_0xfdff('0x25'),'SIPADDHEADER':_0xfdff('0x26')};if(!_[_0xfdff('0x11')](_0x6025d[_0xfdff('0x20')])){_0x38c417[util[_0xfdff('0x13')]('%s',_0xfdff('0x27'))]=_0x6025d[_0xfdff('0x20')];_0x38c417[util['format']('%s','_XCALLY_MIXMONITOR_UNIQUEID')]=_0x5081fb;}if(_0x3b4892&&_0x3b4892[_0xfdff('0x28')]){for(var _0x237e39 in _0x3b4892[_0xfdff('0x28')]){if(_0x3b4892[_0xfdff('0x28')][_0xfdff('0x29')](_0x237e39)){if(!_[_0xfdff('0x15')](_0x3b4892[_0xfdff('0x28')][_0x237e39])&&_0x237e39!=='id'&&_0x237e39!==_0xfdff('0x2a')&&_0x237e39!=='createdAt'&&_0x237e39!==_0xfdff('0x2b')){_0x38c417[util[_0xfdff('0x13')](_0xfdff('0x2c'),_0xfdff('0x2d'),_[_0xfdff('0x2e')](_0x237e39))]=_0x3b4892['Contact'][_0x237e39];}}}}return _0x38c417;};exports[_0xfdff('0x2f')]=function(_0x14524b){var _0x423fca={};for(var _0x2d4d1b in _0x14524b){if(_0x14524b[_0xfdff('0x29')](_0x2d4d1b)){_0x423fca[util[_0xfdff('0x13')]('%s',_[_0xfdff('0x30')](_0x2d4d1b))]=_0x14524b[_0x2d4d1b];}}return{'variables':_0x423fca};};exports[_0xfdff('0x31')]=function(_0x23ca4f,_0x3b04f2){if(!_[_0xfdff('0x15')](_0x23ca4f)){if(_0x23ca4f['hasOwnProperty'](_0xfdff('0x32'))){if(_0x23ca4f['originated']>0x0){_0x23ca4f['originated']-=0x1;}else{logger['error'](_0xfdff('0x33'),_0x3b04f2);}}}else{logger[_0xfdff('0x9')](_0xfdff('0x34'),_0x3b04f2);}};exports['logBlacklist']=function(_0x3829fd){var _0x3a7dfc=moment()[_0xfdff('0x13')](_0xfdff('0x35'));_0x3829fd[_0xfdff('0x36')]=0xd;_0x3829fd['statedesc']=_0xfdff('0x37');_0x3829fd[_0xfdff('0x38')]=_0x3a7dfc;_0x3829fd[_0xfdff('0x39')]=_0x3a7dfc;_0x3829fd['endtime']=_0x3a7dfc;};exports['logAgent']=function(_0x5085b3,_0x360f0d,_0x21636e){var _0x2640da=moment()[_0xfdff('0x13')](_0xfdff('0x35'));_0x5085b3[_0xfdff('0x36')]=_0x360f0d;_0x5085b3[_0xfdff('0x3a')]=_0x21636e;_0x5085b3[_0xfdff('0x39')]=_0x2640da;_0x5085b3[_0xfdff('0x3b')]=getSeconds(_0x5085b3['responsetime'],_0x5085b3[_0xfdff('0x38')]);};exports[_0xfdff('0x3c')]=function(_0x2af75b,_0x55eaa6,_0x5b1d1a){_0x2af75b[_0xfdff('0x3d')]=_0x55eaa6;_0x2af75b[_0xfdff('0x3e')]=_0x5b1d1a;};exports['logCustomer']=function(_0x2c1800,_0x5b66c4,_0x4bf111){var _0x4d720a=moment()['format'](_0xfdff('0x35'));_0x2c1800[_0xfdff('0x36')]=_0x5b66c4;_0x2c1800[_0xfdff('0x3a')]=_0x4bf111;_0x2c1800['responsetime']=_0x2c1800[_0xfdff('0x39')]?_0x2c1800[_0xfdff('0x39')]:_0x4d720a;_0x2c1800[_0xfdff('0x3f')]=_0x2c1800[_0xfdff('0x3f')]?_0x2c1800['endtime']:_0x4d720a;_0x2c1800[_0xfdff('0x3b')]=getSeconds(_0x2c1800['responsetime']||0x0,_0x2c1800['starttime']||0x0);_0x2c1800[_0xfdff('0x40')]=_0x2c1800['answertime']?getSeconds(_0x2c1800['endtime'],_0x2c1800[_0xfdff('0x41')]):0x0;};exports[_0xfdff('0x42')]=function(_0x458b17){return _0x458b17===_0xfdff('0x43');};exports[_0xfdff('0x44')]=function(_0x479143,_0x199535,_0x27c1ea,_0x14c108,_0x55eb9d){var _0x24de87=_0x14c108?_0xfdff('0x45'):_0x479143[_0xfdff('0x1a')];_0x24de87=_0x55eb9d?_0xfdff('0x46'):_0x24de87;return{'actionid':_0x479143[_0xfdff('0x47')],'action':_0xfdff('0x48'),'channel':_0x479143[_0xfdff('0x49')],'callerid':util['format'](_0xfdff('0x19'),_0x24de87,_0x479143[_0xfdff('0x4a')]),'Exten':_0xfdff('0x25'),'Context':'from-sip','Priority':'1','variable':_0x27c1ea,'timeout':(_0x199535['timeout']||0x1e)*0x3e8,'async':!![],'channelid':_0x479143[_0xfdff('0x47')]};};exports['totalGlobal']=function(_0xf95384){return _0xf95384[_0xfdff('0x4b')]+_0xf95384['countcongestionretry']+_0xf95384[_0xfdff('0x4c')]+_0xf95384[_0xfdff('0x4d')]+_0xf95384['countnosuchnumberretry'];};exports[_0xfdff('0x4e')]=function(_0x4a4843){var _0x1f195c=_[_0xfdff('0x4f')](_0x4a4843);_0x1f195c[_0xfdff('0x36')]=0xf;_0x1f195c[_0xfdff('0x3a')]='Global';return _0x1f195c;};exports[_0xfdff('0x50')]=function(_0x4b9a92,_0x250f75,_0x9f1b99){var _0x493bdf={};_0x493bdf[_0x250f75]=_0x4b9a92[_0x250f75];_0x493bdf[_0xfdff('0x51')]=![];_0x493bdf[_0xfdff('0x52')]=moment()[_0xfdff('0x53')](_0x9f1b99,_0xfdff('0x54'))[_0xfdff('0x13')](_0xfdff('0x35'));_0x493bdf['ContactId']=_0x4b9a92[_0xfdff('0x1b')];_0x493bdf[_0xfdff('0x55')]=_0x4b9a92['ListId'];_0x493bdf['VoiceQueueId']=_0x4b9a92[_0xfdff('0x1d')]||undefined;return _0x493bdf;};exports['decrementTalkink']=function(_0x478cf9,_0x575255){if(!_[_0xfdff('0x15')](_0x478cf9)){if(_0x478cf9['pTalking']>0x0){_0x478cf9['pTalking']-=0x1;}else{logger['error'](_0x575255,_0xfdff('0x56'));}}else{logger[_0xfdff('0x9')](_0x575255,_0xfdff('0x57'));}};exports[_0xfdff('0x58')]=function(_0x23af16){if(_0x23af16<=0x0){return!![];}return![];};exports['buildObj']=function(_0x2ecf5b,_0xfa65e2,_0xff078c){_0x2ecf5b[_0xfdff('0x59')]=_0xfa65e2;_0x2ecf5b['name']=_0x2ecf5b[_0xfdff('0x5a')];_0x2ecf5b[_0xfdff('0x5b')]=_0x2ecf5b[_0xfdff('0x49')];_0x2ecf5b[_0xfdff('0x5c')]=_0xfdff('0x5d');if(_0xff078c){_0x2ecf5b[_0xfdff('0x5e')]=_0xff078c[_0xfdff('0x5e')];}return _0x2ecf5b;};exports['buildAcw']=function(_0x464bf5){var _0x23b409={};_0x23b409[_0xfdff('0x5a')]=_0x464bf5[_0xfdff('0x5a')];_0x23b409[_0xfdff('0x5b')]=_0x464bf5[_0xfdff('0x49')];_0x23b409[_0xfdff('0x47')]=_0x464bf5[_0xfdff('0x47')];return _0x23b409;};exports[_0xfdff('0x5f')]=function(_0x33ccf7){var _0x183529=[];for(var _0x5393d8 in _0x33ccf7){if(_0x33ccf7[_0xfdff('0x29')](_0x5393d8)){if(!_[_0xfdff('0x15')](_0x33ccf7[_0x5393d8])&&_0x33ccf7[_0x5393d8][_0xfdff('0x36')]===_0xfdff('0x60')&&_0x33ccf7[_0x5393d8][_0xfdff('0x61')]===_0xfdff('0x62')){_0x183529[_0xfdff('0x63')](_0x33ccf7[_0x5393d8]['id']);}}}return _0x183529;};exports[_0xfdff('0x64')]=function(_0x3ae2e1){var _0x4e7304=moment()[_0xfdff('0x6')](0x0);var _0x2b6e46=moment(_0x3ae2e1)[_0xfdff('0x6')](0x0);return _0x4e7304[_0xfdff('0x7')](_0x2b6e46,_0xfdff('0x8'));};exports['createBody']=function(_0x4180f7){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x4180f7[_0xfdff('0x1b')],'ListId':_0x4180f7['ListId'],'VoiceQueueId':_0x4180f7[_0xfdff('0x1d')]||undefined,'CampaignId':_0x4180f7[_0xfdff('0x65')]||undefined};};exports['filterKey']=function(_0x408b73){if(_0x408b73===_0xfdff('0x47')||_0x408b73===_0xfdff('0x66')||_0x408b73===_0xfdff('0x5a')||_0x408b73==='type'||_0x408b73===_0xfdff('0x67')||_0x408b73===_0xfdff('0x68')||_0x408b73===_0xfdff('0x3d')||_0x408b73===_0xfdff('0x49')||_0x408b73==='calleridname'||_0x408b73==='active'||_0x408b73===_0xfdff('0x4a')||_0x408b73===_0xfdff('0x52')||_0x408b73===_0xfdff('0x4b')||_0x408b73===_0xfdff('0x69')||_0x408b73==='countnoanswerretry'||_0x408b73===_0xfdff('0x6a')||_0x408b73===_0xfdff('0x6b')||_0x408b73===_0xfdff('0x6c')||_0x408b73===_0xfdff('0x6d')||_0x408b73==='recallme'||_0x408b73===_0xfdff('0x1b')||_0x408b73===_0xfdff('0x55')||_0x408b73===_0xfdff('0x3e')||_0x408b73===_0xfdff('0x1d')||_0x408b73==='sipcallid'||_0x408b73===_0xfdff('0x6e')||_0x408b73==='xmd-queue'||_0x408b73===_0xfdff('0x6f')||_0x408b73==='xmd-listid'||_0x408b73===_0xfdff('0x70')||_0x408b73===_0xfdff('0x71')||_0x408b73===_0xfdff('0x72')||_0x408b73===_0xfdff('0x73')||_0x408b73===_0xfdff('0x74')||_0x408b73==='xmd-contactid'||_0x408b73==='xmd-cdrtype'||_0x408b73===_0xfdff('0x75')||_0x408b73===_0xfdff('0x76')||_0x408b73===_0xfdff('0x77')||_0x408b73===_0xfdff('0x78')||_0x408b73===_0xfdff('0x79')||_0x408b73===_0xfdff('0x7a')||_0x408b73===_0xfdff('0x7b')||_0x408b73===_0xfdff('0x7c')||_0x408b73===_0xfdff('0x7d')||_0x408b73==='rtpaudioqosrtt'||_0x408b73==='rtpaudioqosrttbridged'||_0x408b73===_0xfdff('0x78')||_0x408b73===_0xfdff('0x79')||_0x408b73==='rtpaudioqosjitter'||_0x408b73===_0xfdff('0x7b')||_0x408b73===_0xfdff('0x7c')||_0x408b73===_0xfdff('0x7d')||_0x408b73==='rtpaudioqosrtt'||_0x408b73===_0xfdff('0x7e')||_0x408b73==='bridgepeer'||_0x408b73===_0xfdff('0x7f')||_0x408b73===_0xfdff('0x36')||_0x408b73===_0xfdff('0x3a')){return![];}return!![];};exports['getCallerIdRandom']=function(_0x5e6ce5,_0x19412f){var _0xbcd965,_0x408ab0,_0x5b102b;if(_0x19412f<=0x0){_0x19412f=0x1;}_0xbcd965=new RegExp(_0xfdff('0x80')+_0x19412f+'}$');_0x408ab0=Math[_0xfdff('0x81')](0xa,_0x19412f-0x1);_0x5b102b=Math[_0xfdff('0x81')](0xa,_0x19412f)-0x1;return util[_0xfdff('0x13')]('%s',_[_0xfdff('0x82')](_0x5e6ce5,_0xbcd965,_[_0xfdff('0x83')](_0x408ab0,_0x5b102b)));};exports[_0xfdff('0x84')]=function(_0x241892){var _0x10f260=_0x241892[_0xfdff('0x85')](/"(.*?)"/);return _0x10f260?_0x10f260[0x1]:_0x241892;};exports[_0xfdff('0x86')]=function(_0x589745){var _0x5df725=_0x589745[_0xfdff('0x85')](/<(.*?)>/);return _0x5df725?_0x5df725[0x1]:_0x589745;};