6c0d0786239bde568f0fdeab796e95be2eb5c682
[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 _0xf922=['name','calleridnum','ContactId','dialer','VoiceQueueId','dialOriginateTimeout','\x22rtTxX%s%s\x22','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','Contact','hasOwnProperty','tags','createdAt','updatedAt','%s%s','toLowerVariables','toLower','updateOriginated','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','YYYY-MM-DD\x20HH:mm:ss','state','statedesc','Blacklist','starttime','responsetime','endtime','logAgent','ringtime','logLookAgent','UserId','logCustomer','talktime','answertime','isFailure','Failure','variablesAction','RECALL','calleridname','BOOKED','uniqueid','originate','channelAgent','from-sip','totalGlobal','countnoanswerretry','countnosuchnumberretry','clone','Global','minutes','ListId','decrementTalkink','pTalking','[decrementTalkink]\x20is\x20null\x20or\x20undefined','IsNotLoggedIn','buildObj','lastevent','queue','interface','voice','mandatoryDisposition','buildAcw','agentReadyId','not_inuse','reachable','push','getDiff','CampaignId','filterKey','idContact','campaigntype','dialAnswer','membername','scheduledat','countbusyretry','countcongestionretry','callback','callbackuniqueid','callbackat','recallme','xmd-phone','xmd-listid','xmd-dialurl','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-contactid','xmd-cdrtype','xmd-callerid','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosrtt','rtpaudioqosrttbridged','rtpaudioqosloss','rtpaudioqoslossbridged','bridgepeer','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','pow','replace','random','extractCalleridNumber','util','moment','../../../../config/logger','preview','env','XCALLY_IP_AGI','127.0.0.1','milliseconds','diff','seconds','loggerCatch','error','inspect','logger','loggerError','logger2','info','message','getCallerId','string','isEmpty','isUndefined','format','\x22%s\x22\x20<%s>','isActive','isNil','Queue'];(function(_0x4c03c3,_0x1c7bc1){var _0x5925e1=function(_0x7a2283){while(--_0x7a2283){_0x4c03c3['push'](_0x4c03c3['shift']());}};_0x5925e1(++_0x1c7bc1);}(_0xf922,0x18c));var _0x2f92=function(_0x3aab7f,_0x18d72c){_0x3aab7f=_0x3aab7f-0x0;var _0x3c2be6=_0xf922[_0x3aab7f];return _0x3c2be6;};'use strict';var util=require(_0x2f92('0x0'));var _=require('lodash');var moment=require(_0x2f92('0x1'));var logger=require(_0x2f92('0x2'))(_0x2f92('0x3'));var ipAgi=process[_0x2f92('0x4')][_0x2f92('0x5')]||_0x2f92('0x6');function getSeconds(_0xb6ff02,_0xe2f9a6){var _0xb76ba2=moment(_0xb6ff02)[_0x2f92('0x7')](0x0);var _0x5859dc=moment(_0xe2f9a6)[_0x2f92('0x7')](0x0);return _0xb76ba2[_0x2f92('0x8')](_0x5859dc,_0x2f92('0x9'));}exports[_0x2f92('0xa')]=function(_0x16e941){return function(_0xe35f46){logger[_0x2f92('0xb')](_0x16e941,util[_0x2f92('0xc')](_0xe35f46,{'showHidden':![],'depth':null}));};};exports[_0x2f92('0xd')]=function(_0x41fea4,_0x5075a0){logger['info'](_0x41fea4,util[_0x2f92('0xc')](_0x5075a0,{'showHidden':![],'depth':null}));};exports[_0x2f92('0xe')]=function(_0x4f8668,_0x74725e){logger[_0x2f92('0xb')](_0x4f8668,util[_0x2f92('0xc')](_0x74725e,{'showHidden':![],'depth':null}));};exports[_0x2f92('0xf')]=function(_0x1f29a7){return function(_0x166b90){logger[_0x2f92('0x10')](_0x1f29a7,util[_0x2f92('0xc')](_0x166b90,{'showHidden':![],'depth':null}));};};exports[_0x2f92('0x11')]=function(_0x41a26b,_0x3835bc,_0x14120b){return{'message':_0x41a26b,'unlock':_0x3835bc,'active':_0x14120b};};exports[_0x2f92('0x12')]=function(_0x37675a,_0x379213,_0x6cc798){if(!_['isUndefined'](_0x6cc798)&&_0x2f92('0x13')===typeof _0x6cc798&&!_[_0x2f92('0x14')](_0x6cc798)){if(!_[_0x2f92('0x15')](_0x379213)&&_0x2f92('0x13')===typeof _0x379213&&!_[_0x2f92('0x14')](_0x379213)){return util[_0x2f92('0x16')](_0x2f92('0x17'),_0x379213,_0x6cc798);}return util[_0x2f92('0x16')](_0x2f92('0x17'),_0x6cc798,_0x6cc798);}if(!_[_0x2f92('0x15')](_0x37675a)&&_0x2f92('0x13')===typeof _0x37675a&&!_[_0x2f92('0x14')](_0x37675a)){return _0x37675a;}return'\x22\x22\x20<>';};exports[_0x2f92('0x18')]=function(_0x5d927e){if(_[_0x2f92('0x19')](_0x5d927e)){return![];}return _0x5d927e;};exports['addVariables']=function(_0x5a10aa,_0x256b92,_0x175d2d,_0x13cb61,_0x340151,_0x23662c){var _0x207f1e={'XMD-QUEUE':_0x256b92[_0x2f92('0x1a')]?_0x256b92['Queue'][_0x2f92('0x1b')]:'','XMD-CALLERID':_0x13cb61,'XMD-CALLERID-PREVIEW':_0x23662c?util[_0x2f92('0x16')]('\x22%s\x22\x20<%s>',_0x23662c['calleridname'],_0x23662c[_0x2f92('0x1c')]):_0x13cb61,'XMD-DIALID':_0x340151,'XMD-CONTACTID':_0x256b92[_0x2f92('0x1d')],'XMD-CDRTYPE':_0x2f92('0x1e'),'CALLERID(all)':_0x13cb61,'XMD-VOICEQUEUEID':_0x256b92[_0x2f92('0x1f')],'XMD-DIALCHANNEL':_0x175d2d,'XMD-DIALTIMEOUT':_0x5a10aa[_0x2f92('0x20')]||0x1e,'XMD-DIALOPTIONS':util['format'](_0x2f92('0x21'),_0x5a10aa[_0x2f92('0x22')]?'g':'',_['isEmpty'](_0x5a10aa[_0x2f92('0x23')])?'':_0x2f92('0x24')),'XMD-DIALURL':_0x5a10aa['dialPreviewUrl']||'','XMD-AGI':_0x5a10aa[_0x2f92('0x25')]?util[_0x2f92('0x16')](_0x2f92('0x26'),ipAgi,_0x5a10aa[_0x2f92('0x25')]):'NONE','XMD-AGIAFTER':_0x5a10aa[_0x2f92('0x22')]?util['format']('\x22agi://%s/square,%s\x22',ipAgi,_0x5a10aa[_0x2f92('0x22')]):_0x2f92('0x27'),'XMD-ORIGINATECALLERIDNUM':_0x23662c?_0x23662c[_0x2f92('0x28')]:'','XMD-ORIGINATECALLERIDNAME':_0x23662c?_0x23662c[_0x2f92('0x29')]:'','XMD-DESTINATION':_0x2f92('0x2a'),'SIPADDHEADER':_0x2f92('0x2b')};if(!_['isEmpty'](_0x5a10aa['monitor_format'])){_0x207f1e[util[_0x2f92('0x16')]('%s',_0x2f92('0x2c'))]=_0x5a10aa['monitor_format'];_0x207f1e[util['format']('%s','_XCALLY_MIXMONITOR_UNIQUEID')]=_0x340151;}if(_0x256b92&&_0x256b92[_0x2f92('0x2d')]){for(var _0x7aa153 in _0x256b92['Contact']){if(_0x256b92[_0x2f92('0x2d')][_0x2f92('0x2e')](_0x7aa153)){if(!_['isNil'](_0x256b92[_0x2f92('0x2d')][_0x7aa153])&&_0x7aa153!=='id'&&_0x7aa153!==_0x2f92('0x2f')&&_0x7aa153!==_0x2f92('0x30')&&_0x7aa153!==_0x2f92('0x31')){_0x207f1e[util[_0x2f92('0x16')](_0x2f92('0x32'),'XMD-',_['toUpper'](_0x7aa153))]=_0x256b92[_0x2f92('0x2d')][_0x7aa153];}}}}return _0x207f1e;};exports[_0x2f92('0x33')]=function(_0x556ff7){var _0x18ad9d={};for(var _0xa86c8 in _0x556ff7){if(_0x556ff7[_0x2f92('0x2e')](_0xa86c8)){_0x18ad9d[util['format']('%s',_[_0x2f92('0x34')](_0xa86c8))]=_0x556ff7[_0xa86c8];}}return{'variables':_0x18ad9d};};exports[_0x2f92('0x35')]=function(_0x3807ce,_0x2f3486){if(!_['isNil'](_0x3807ce)){if(_0x3807ce[_0x2f92('0x2e')](_0x2f92('0x36'))){if(_0x3807ce['originated']>0x0){_0x3807ce['originated']-=0x1;}else{logger[_0x2f92('0xb')](_0x2f92('0x37'),_0x2f3486);}}}else{logger[_0x2f92('0xb')]('[updateOriginated]\x20is\x20null\x20or\x20undefined',_0x2f3486);}};exports['logBlacklist']=function(_0x21bf19){var _0xec03ea=moment()[_0x2f92('0x16')](_0x2f92('0x38'));_0x21bf19[_0x2f92('0x39')]=0xd;_0x21bf19[_0x2f92('0x3a')]=_0x2f92('0x3b');_0x21bf19[_0x2f92('0x3c')]=_0xec03ea;_0x21bf19[_0x2f92('0x3d')]=_0xec03ea;_0x21bf19[_0x2f92('0x3e')]=_0xec03ea;};exports[_0x2f92('0x3f')]=function(_0x27b28c,_0x50740c,_0x1caaa6){var _0x3f8154=moment()['format'](_0x2f92('0x38'));_0x27b28c['state']=_0x50740c;_0x27b28c['statedesc']=_0x1caaa6;_0x27b28c[_0x2f92('0x3d')]=_0x3f8154;_0x27b28c[_0x2f92('0x40')]=getSeconds(_0x27b28c[_0x2f92('0x3d')],_0x27b28c[_0x2f92('0x3c')]);};exports[_0x2f92('0x41')]=function(_0x24f01d,_0xa3d52a,_0x182002){_0x24f01d['membername']=_0xa3d52a;_0x24f01d[_0x2f92('0x42')]=_0x182002;};exports[_0x2f92('0x43')]=function(_0xf5ff90,_0x39dd10,_0x3ebda3){var _0x133e0c=moment()[_0x2f92('0x16')]('YYYY-MM-DD\x20HH:mm:ss');_0xf5ff90[_0x2f92('0x39')]=_0x39dd10;_0xf5ff90[_0x2f92('0x3a')]=_0x3ebda3;_0xf5ff90[_0x2f92('0x3d')]=_0xf5ff90['responsetime']?_0xf5ff90[_0x2f92('0x3d')]:_0x133e0c;_0xf5ff90[_0x2f92('0x3e')]=_0xf5ff90[_0x2f92('0x3e')]?_0xf5ff90[_0x2f92('0x3e')]:_0x133e0c;_0xf5ff90['ringtime']=getSeconds(_0xf5ff90[_0x2f92('0x3d')]||0x0,_0xf5ff90[_0x2f92('0x3c')]||0x0);_0xf5ff90[_0x2f92('0x44')]=_0xf5ff90[_0x2f92('0x45')]?getSeconds(_0xf5ff90[_0x2f92('0x3e')],_0xf5ff90[_0x2f92('0x45')]):0x0;};exports[_0x2f92('0x46')]=function(_0x40c406){return _0x40c406===_0x2f92('0x47');};exports[_0x2f92('0x48')]=function(_0x2274f5,_0x28bbdd,_0x47dc8a,_0x32ef5c,_0x9481f7){var _0x3abf04=_0x32ef5c?_0x2f92('0x49'):_0x2274f5[_0x2f92('0x4a')];_0x3abf04=_0x9481f7?_0x2f92('0x4b'):_0x3abf04;return{'actionid':_0x2274f5[_0x2f92('0x4c')],'action':_0x2f92('0x4d'),'channel':_0x2274f5[_0x2f92('0x4e')],'callerid':util[_0x2f92('0x16')]('\x22%s\x22\x20<%s>',_0x3abf04,_0x2274f5[_0x2f92('0x1c')]),'Exten':_0x2f92('0x2a'),'Context':_0x2f92('0x4f'),'Priority':'1','variable':_0x47dc8a,'timeout':(_0x28bbdd['timeout']||0x1e)*0x3e8,'async':!![],'channelid':_0x2274f5[_0x2f92('0x4c')]};};exports[_0x2f92('0x50')]=function(_0xa12ef0){return _0xa12ef0['countbusyretry']+_0xa12ef0['countcongestionretry']+_0xa12ef0[_0x2f92('0x51')]+_0xa12ef0['countagentrejectretry']+_0xa12ef0[_0x2f92('0x52')];};exports['cloneAction']=function(_0x33fcf7){var _0x5eb083=_[_0x2f92('0x53')](_0x33fcf7);_0x5eb083['state']=0xf;_0x5eb083[_0x2f92('0x3a')]=_0x2f92('0x54');return _0x5eb083;};exports['scheduledAt']=function(_0x3b693e,_0x281407,_0x575bbb){var _0x5d8b8f={};_0x5d8b8f[_0x281407]=_0x3b693e[_0x281407];_0x5d8b8f['active']=![];_0x5d8b8f['scheduledat']=moment()['add'](_0x575bbb,_0x2f92('0x55'))[_0x2f92('0x16')](_0x2f92('0x38'));_0x5d8b8f[_0x2f92('0x1d')]=_0x3b693e['ContactId'];_0x5d8b8f[_0x2f92('0x56')]=_0x3b693e[_0x2f92('0x56')];_0x5d8b8f[_0x2f92('0x1f')]=_0x3b693e[_0x2f92('0x1f')]||undefined;return _0x5d8b8f;};exports[_0x2f92('0x57')]=function(_0x5aaba3,_0x27f15c){if(!_[_0x2f92('0x19')](_0x5aaba3)){if(_0x5aaba3['pTalking']>0x0){_0x5aaba3[_0x2f92('0x58')]-=0x1;}else{logger[_0x2f92('0xb')](_0x27f15c,'[decrementTalkink]\x20object\x20talking\x20is\x20negative');}}else{logger[_0x2f92('0xb')](_0x27f15c,_0x2f92('0x59'));}};exports[_0x2f92('0x5a')]=function(_0x7b52d0){if(_0x7b52d0<=0x0){return!![];}return![];};exports[_0x2f92('0x5b')]=function(_0x46f280,_0x5549aa,_0x7f0133){_0x46f280[_0x2f92('0x5c')]=_0x5549aa;_0x46f280[_0x2f92('0x1b')]=_0x46f280[_0x2f92('0x5d')];_0x46f280[_0x2f92('0x5e')]=_0x46f280[_0x2f92('0x4e')];_0x46f280['motionChannel']=_0x2f92('0x5f');if(_0x7f0133){_0x46f280[_0x2f92('0x60')]=_0x7f0133[_0x2f92('0x60')];}return _0x46f280;};exports[_0x2f92('0x61')]=function(_0x350545){var _0x5a89ed={};_0x5a89ed[_0x2f92('0x5d')]=_0x350545['queue'];_0x5a89ed['interface']=_0x350545[_0x2f92('0x4e')];_0x5a89ed[_0x2f92('0x4c')]=_0x350545[_0x2f92('0x4c')];return _0x5a89ed;};exports[_0x2f92('0x62')]=function(_0x5612e1){var _0x5591e5=[];for(var _0x32b640 in _0x5612e1){if(_0x5612e1[_0x2f92('0x2e')](_0x32b640)){if(!_[_0x2f92('0x19')](_0x5612e1[_0x32b640])&&_0x5612e1[_0x32b640][_0x2f92('0x39')]===_0x2f92('0x63')&&_0x5612e1[_0x32b640]['status']===_0x2f92('0x64')){_0x5591e5[_0x2f92('0x65')](_0x5612e1[_0x32b640]['id']);}}}return _0x5591e5;};exports[_0x2f92('0x66')]=function(_0x2dcf65){var _0x38c7a7=moment()[_0x2f92('0x7')](0x0);var _0x18cca6=moment(_0x2dcf65)[_0x2f92('0x7')](0x0);return _0x38c7a7['diff'](_0x18cca6,_0x2f92('0x9'));};exports['createBody']=function(_0x115fef){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x115fef[_0x2f92('0x1d')],'ListId':_0x115fef[_0x2f92('0x56')],'VoiceQueueId':_0x115fef[_0x2f92('0x1f')]||undefined,'CampaignId':_0x115fef[_0x2f92('0x67')]||undefined};};exports[_0x2f92('0x68')]=function(_0x4d602e){if(_0x4d602e===_0x2f92('0x4c')||_0x4d602e===_0x2f92('0x69')||_0x4d602e===_0x2f92('0x5d')||_0x4d602e==='type'||_0x4d602e===_0x2f92('0x6a')||_0x4d602e===_0x2f92('0x6b')||_0x4d602e===_0x2f92('0x6c')||_0x4d602e==='channelAgent'||_0x4d602e===_0x2f92('0x4a')||_0x4d602e==='active'||_0x4d602e==='calleridnum'||_0x4d602e===_0x2f92('0x6d')||_0x4d602e===_0x2f92('0x6e')||_0x4d602e===_0x2f92('0x6f')||_0x4d602e===_0x2f92('0x51')||_0x4d602e==='countglobal'||_0x4d602e===_0x2f92('0x70')||_0x4d602e===_0x2f92('0x71')||_0x4d602e===_0x2f92('0x72')||_0x4d602e===_0x2f92('0x73')||_0x4d602e===_0x2f92('0x1d')||_0x4d602e===_0x2f92('0x56')||_0x4d602e===_0x2f92('0x42')||_0x4d602e==='VoiceQueueId'||_0x4d602e==='sipcallid'||_0x4d602e==='xmd-voicequeueid'||_0x4d602e==='xmd-queue'||_0x4d602e===_0x2f92('0x74')||_0x4d602e===_0x2f92('0x75')||_0x4d602e===_0x2f92('0x76')||_0x4d602e===_0x2f92('0x77')||_0x4d602e===_0x2f92('0x78')||_0x4d602e===_0x2f92('0x79')||_0x4d602e==='xmd-dialchannel'||_0x4d602e===_0x2f92('0x7a')||_0x4d602e===_0x2f92('0x7b')||_0x4d602e===_0x2f92('0x7c')||_0x4d602e==='xmd-agiafter'||_0x4d602e===_0x2f92('0x7d')||_0x4d602e===_0x2f92('0x7e')||_0x4d602e===_0x2f92('0x7f')||_0x4d602e===_0x2f92('0x80')||_0x4d602e==='rtpaudioqosjitterbridged'||_0x4d602e==='rtpaudioqosloss'||_0x4d602e==='rtpaudioqoslossbridged'||_0x4d602e===_0x2f92('0x81')||_0x4d602e===_0x2f92('0x82')||_0x4d602e==='rtpaudioqos'||_0x4d602e===_0x2f92('0x7f')||_0x4d602e===_0x2f92('0x80')||_0x4d602e==='rtpaudioqosjitterbridged'||_0x4d602e===_0x2f92('0x83')||_0x4d602e===_0x2f92('0x84')||_0x4d602e==='rtpaudioqosrtt'||_0x4d602e===_0x2f92('0x82')||_0x4d602e===_0x2f92('0x85')||_0x4d602e===_0x2f92('0x86')||_0x4d602e===_0x2f92('0x39')||_0x4d602e==='statedesc'){return![];}return!![];};exports[_0x2f92('0x87')]=function(_0x59beac,_0x3e147a){var _0x159cad,_0xe8a9bf,_0x57f837;if(_0x3e147a<=0x0){_0x3e147a=0x1;}_0x159cad=new RegExp(_0x2f92('0x88')+_0x3e147a+'}$');_0xe8a9bf=Math[_0x2f92('0x89')](0xa,_0x3e147a-0x1);_0x57f837=Math[_0x2f92('0x89')](0xa,_0x3e147a)-0x1;return util[_0x2f92('0x16')]('%s',_[_0x2f92('0x8a')](_0x59beac,_0x159cad,_[_0x2f92('0x8b')](_0xe8a9bf,_0x57f837)));};exports['extractCalleridName']=function(_0x288a3f){var _0x2deab5=_0x288a3f['match'](/"(.*?)"/);return _0x2deab5?_0x2deab5[0x1]:_0x288a3f;};exports[_0x2f92('0x8c')]=function(_0x8620e9){var _0x1feb21=_0x8620e9['match'](/<(.*?)>/);return _0x1feb21?_0x1feb21[0x1]:_0x8620e9;};