89f97a1bc26626dead1de5b897407d508b251ccf
[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 _0xfb62=['rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqosrttbridged','rtpaudioqoslossbridged','rtpaudioqosrtt','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','pow','replace','random','extractCalleridName','match','extractCalleridNumber','lodash','moment','preview','env','XCALLY_IP_AGI','milliseconds','diff','seconds','loggerCatch','inspect','logger','info','loggerError','logger2','message','getCallerId','isUndefined','string','isEmpty','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isActive','addVariables','Queue','calleridname','calleridnum','ContactId','dialer','VoiceQueueId','\x22rtTxX%s%s\x22','dialPreviewUrl','\x22agi://%s/square,%s\x22','dialQueueProject','NONE','dialQueueProject2','originatecalleridnum','originatecalleridname','xcally-motion-preview','monitor_format','_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','Contact','hasOwnProperty','createdAt','updatedAt','%s%s','toUpper','toLowerVariables','updateOriginated','isNil','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','error','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','YYYY-MM-DD\x20HH:mm:ss','state','statedesc','Blacklist','starttime','responsetime','endtime','logAgent','ringtime','logLookAgent','membername','UserId','logCustomer','talktime','answertime','isFailure','Failure','variablesAction','RECALL','uniqueid','channelAgent','from-sip','timeout','countbusyretry','countcongestionretry','countnoanswerretry','countagentrejectretry','countnosuchnumberretry','cloneAction','clone','Global','scheduledAt','scheduledat','add','minutes','ListId','decrementTalkink','pTalking','[decrementTalkink]\x20is\x20null\x20or\x20undefined','IsNotLoggedIn','buildObj','lastevent','name','queue','interface','mandatoryDisposition','agentReadyId','not_inuse','reachable','push','getDiff','createBody','CampaignId','filterKey','type','dialAnswer','active','countglobal','callback','callbackat','recallme','sipcallid','xmd-queue','xmd-phone','xmd-listid','xmd-dialurl','xmd-dialoptions','xmd-dialid','xmd-contactid','xmd-cdrtype','xmd-callerid','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter'];(function(_0x8503e0,_0x38132a){var _0x433237=function(_0x2072db){while(--_0x2072db){_0x8503e0['push'](_0x8503e0['shift']());}};_0x433237(++_0x38132a);}(_0xfb62,0x1c1));var _0x2fb6=function(_0x199572,_0x33e667){_0x199572=_0x199572-0x0;var _0x13cfa3=_0xfb62[_0x199572];return _0x13cfa3;};'use strict';var util=require('util');var _=require(_0x2fb6('0x0'));var moment=require(_0x2fb6('0x1'));var logger=require('../../../../config/logger')(_0x2fb6('0x2'));var ipAgi=process[_0x2fb6('0x3')][_0x2fb6('0x4')]||'127.0.0.1';function getSeconds(_0x2b8dd9,_0x2da30e){var _0x36305f=moment(_0x2b8dd9)[_0x2fb6('0x5')](0x0);var _0x252999=moment(_0x2da30e)[_0x2fb6('0x5')](0x0);return _0x36305f[_0x2fb6('0x6')](_0x252999,_0x2fb6('0x7'));}exports[_0x2fb6('0x8')]=function(_0x47a6ca){return function(_0x478f70){logger['error'](_0x47a6ca,util[_0x2fb6('0x9')](_0x478f70,{'showHidden':![],'depth':null}));};};exports[_0x2fb6('0xa')]=function(_0x598b1b,_0x205ce5){logger[_0x2fb6('0xb')](_0x598b1b,util[_0x2fb6('0x9')](_0x205ce5,{'showHidden':![],'depth':null}));};exports[_0x2fb6('0xc')]=function(_0x39c4b9,_0x3e491a){logger['error'](_0x39c4b9,util['inspect'](_0x3e491a,{'showHidden':![],'depth':null}));};exports[_0x2fb6('0xd')]=function(_0x26b360){return function(_0x58fd4c){logger[_0x2fb6('0xb')](_0x26b360,util[_0x2fb6('0x9')](_0x58fd4c,{'showHidden':![],'depth':null}));};};exports[_0x2fb6('0xe')]=function(_0x14a747,_0xba0d0e,_0x238628){return{'message':_0x14a747,'unlock':_0xba0d0e,'active':_0x238628};};exports[_0x2fb6('0xf')]=function(_0x315166,_0x561b38,_0x420c22){if(!_[_0x2fb6('0x10')](_0x420c22)&&_0x2fb6('0x11')===typeof _0x420c22&&!_['isEmpty'](_0x420c22)){if(!_['isUndefined'](_0x561b38)&&_0x2fb6('0x11')===typeof _0x561b38&&!_[_0x2fb6('0x12')](_0x561b38)){return util[_0x2fb6('0x13')](_0x2fb6('0x14'),_0x561b38,_0x420c22);}return util[_0x2fb6('0x13')](_0x2fb6('0x14'),_0x420c22,_0x420c22);}if(!_[_0x2fb6('0x10')](_0x315166)&&_0x2fb6('0x11')===typeof _0x315166&&!_[_0x2fb6('0x12')](_0x315166)){return _0x315166;}return _0x2fb6('0x15');};exports[_0x2fb6('0x16')]=function(_0x1036e7){if(_['isNil'](_0x1036e7)){return![];}return _0x1036e7;};exports[_0x2fb6('0x17')]=function(_0x28dd91,_0x4a656f,_0x4b6dca,_0x32d5bb,_0x7ff4c0,_0x42520e){var _0x1d5814={'XMD-QUEUE':_0x4a656f[_0x2fb6('0x18')]?_0x4a656f[_0x2fb6('0x18')]['name']:'','XMD-CALLERID':_0x32d5bb,'XMD-CALLERID-PREVIEW':_0x42520e?util[_0x2fb6('0x13')](_0x2fb6('0x14'),_0x42520e[_0x2fb6('0x19')],_0x42520e[_0x2fb6('0x1a')]):_0x32d5bb,'XMD-DIALID':_0x7ff4c0,'XMD-CONTACTID':_0x4a656f[_0x2fb6('0x1b')],'XMD-CDRTYPE':_0x2fb6('0x1c'),'CALLERID(all)':_0x32d5bb,'XMD-VOICEQUEUEID':_0x4a656f[_0x2fb6('0x1d')],'XMD-DIALCHANNEL':_0x4b6dca,'XMD-DIALTIMEOUT':_0x28dd91['dialOriginateTimeout']||0x1e,'XMD-DIALOPTIONS':util[_0x2fb6('0x13')](_0x2fb6('0x1e'),_0x28dd91['dialQueueProject2']?'g':'',_[_0x2fb6('0x12')](_0x28dd91['monitor_format'])?'':'U(xcally-mixmonitor-context)'),'XMD-DIALURL':_0x28dd91[_0x2fb6('0x1f')]||'','XMD-AGI':_0x28dd91['dialQueueProject']?util[_0x2fb6('0x13')](_0x2fb6('0x20'),ipAgi,_0x28dd91[_0x2fb6('0x21')]):_0x2fb6('0x22'),'XMD-AGIAFTER':_0x28dd91[_0x2fb6('0x23')]?util[_0x2fb6('0x13')]('\x22agi://%s/square,%s\x22',ipAgi,_0x28dd91[_0x2fb6('0x23')]):_0x2fb6('0x22'),'XMD-ORIGINATECALLERIDNUM':_0x42520e?_0x42520e[_0x2fb6('0x24')]:'','XMD-ORIGINATECALLERIDNAME':_0x42520e?_0x42520e[_0x2fb6('0x25')]:'','XMD-DESTINATION':_0x2fb6('0x26')};if(!_[_0x2fb6('0x12')](_0x28dd91[_0x2fb6('0x27')])){_0x1d5814[util[_0x2fb6('0x13')]('%s',_0x2fb6('0x28'))]=_0x28dd91[_0x2fb6('0x27')];_0x1d5814[util[_0x2fb6('0x13')]('%s',_0x2fb6('0x29'))]=_0x7ff4c0;}if(_0x4a656f&&_0x4a656f[_0x2fb6('0x2a')]){for(var _0x464e6f in _0x4a656f['Contact']){if(_0x4a656f[_0x2fb6('0x2a')][_0x2fb6('0x2b')](_0x464e6f)){if(!_['isNil'](_0x4a656f[_0x2fb6('0x2a')][_0x464e6f])&&_0x464e6f!=='id'&&_0x464e6f!=='tags'&&_0x464e6f!==_0x2fb6('0x2c')&&_0x464e6f!==_0x2fb6('0x2d')){_0x1d5814[util['format'](_0x2fb6('0x2e'),'XMD-',_[_0x2fb6('0x2f')](_0x464e6f))]=_0x4a656f[_0x2fb6('0x2a')][_0x464e6f];}}}}return _0x1d5814;};exports[_0x2fb6('0x30')]=function(_0x2c1a6d){var _0x58278f={};for(var _0xde367b in _0x2c1a6d){if(_0x2c1a6d['hasOwnProperty'](_0xde367b)){_0x58278f[util['format']('%s',_['toLower'](_0xde367b))]=_0x2c1a6d[_0xde367b];}}return{'variables':_0x58278f};};exports[_0x2fb6('0x31')]=function(_0x4c3657,_0x24aec8){if(!_[_0x2fb6('0x32')](_0x4c3657)){if(_0x4c3657[_0x2fb6('0x2b')](_0x2fb6('0x33'))){if(_0x4c3657[_0x2fb6('0x33')]>0x0){_0x4c3657[_0x2fb6('0x33')]-=0x1;}else{logger['error'](_0x2fb6('0x34'),_0x24aec8);}}}else{logger[_0x2fb6('0x35')](_0x2fb6('0x36'),_0x24aec8);}};exports[_0x2fb6('0x37')]=function(_0x38448a){var _0x406dde=moment()['format'](_0x2fb6('0x38'));_0x38448a[_0x2fb6('0x39')]=0xd;_0x38448a[_0x2fb6('0x3a')]=_0x2fb6('0x3b');_0x38448a[_0x2fb6('0x3c')]=_0x406dde;_0x38448a[_0x2fb6('0x3d')]=_0x406dde;_0x38448a[_0x2fb6('0x3e')]=_0x406dde;};exports[_0x2fb6('0x3f')]=function(_0x476c75,_0x3f70b0,_0x18a290){var _0xa6a4b4=moment()['format'](_0x2fb6('0x38'));_0x476c75[_0x2fb6('0x39')]=_0x3f70b0;_0x476c75[_0x2fb6('0x3a')]=_0x18a290;_0x476c75['responsetime']=_0xa6a4b4;_0x476c75[_0x2fb6('0x40')]=getSeconds(_0x476c75[_0x2fb6('0x3d')],_0x476c75['starttime']);};exports[_0x2fb6('0x41')]=function(_0x3a9be8,_0x4b676f,_0x5bd5ba){_0x3a9be8[_0x2fb6('0x42')]=_0x4b676f;_0x3a9be8[_0x2fb6('0x43')]=_0x5bd5ba;};exports[_0x2fb6('0x44')]=function(_0x5a366e,_0x647d9b,_0x178e4b){var _0x31f94c=moment()['format'](_0x2fb6('0x38'));_0x5a366e[_0x2fb6('0x39')]=_0x647d9b;_0x5a366e[_0x2fb6('0x3a')]=_0x178e4b;_0x5a366e[_0x2fb6('0x3d')]=_0x5a366e[_0x2fb6('0x3d')]?_0x5a366e['responsetime']:_0x31f94c;_0x5a366e['endtime']=_0x5a366e[_0x2fb6('0x3e')]?_0x5a366e[_0x2fb6('0x3e')]:_0x31f94c;_0x5a366e[_0x2fb6('0x40')]=getSeconds(_0x5a366e[_0x2fb6('0x3d')]||0x0,_0x5a366e['starttime']||0x0);_0x5a366e[_0x2fb6('0x45')]=_0x5a366e[_0x2fb6('0x46')]?getSeconds(_0x5a366e[_0x2fb6('0x3e')],_0x5a366e[_0x2fb6('0x46')]):0x0;};exports[_0x2fb6('0x47')]=function(_0xb0d0d){return _0xb0d0d===_0x2fb6('0x48');};exports[_0x2fb6('0x49')]=function(_0x1f1e58,_0x17e704,_0x4919e9,_0x373601,_0x3aeb18){var _0x4957eb=_0x373601?_0x2fb6('0x4a'):_0x1f1e58[_0x2fb6('0x19')];_0x4957eb=_0x3aeb18?'BOOKED':_0x4957eb;return{'actionid':_0x1f1e58[_0x2fb6('0x4b')],'action':'originate','channel':_0x1f1e58[_0x2fb6('0x4c')],'callerid':util[_0x2fb6('0x13')](_0x2fb6('0x14'),_0x4957eb,_0x1f1e58[_0x2fb6('0x1a')]),'Exten':_0x2fb6('0x26'),'Context':_0x2fb6('0x4d'),'Priority':'1','variable':_0x4919e9,'timeout':(_0x17e704[_0x2fb6('0x4e')]||0x1e)*0x3e8,'async':!![],'channelid':_0x1f1e58['uniqueid']};};exports['totalGlobal']=function(_0x3e59ae){return _0x3e59ae[_0x2fb6('0x4f')]+_0x3e59ae[_0x2fb6('0x50')]+_0x3e59ae[_0x2fb6('0x51')]+_0x3e59ae[_0x2fb6('0x52')]+_0x3e59ae[_0x2fb6('0x53')];};exports[_0x2fb6('0x54')]=function(_0x109257){var _0xce92cf=_[_0x2fb6('0x55')](_0x109257);_0xce92cf[_0x2fb6('0x39')]=0xf;_0xce92cf[_0x2fb6('0x3a')]=_0x2fb6('0x56');return _0xce92cf;};exports[_0x2fb6('0x57')]=function(_0x161e4b,_0x474f85,_0x4e7fe9){var _0xe2c2fc={};_0xe2c2fc[_0x474f85]=_0x161e4b[_0x474f85];_0xe2c2fc['active']=![];_0xe2c2fc[_0x2fb6('0x58')]=moment()[_0x2fb6('0x59')](_0x4e7fe9,_0x2fb6('0x5a'))[_0x2fb6('0x13')](_0x2fb6('0x38'));_0xe2c2fc[_0x2fb6('0x1b')]=_0x161e4b[_0x2fb6('0x1b')];_0xe2c2fc[_0x2fb6('0x5b')]=_0x161e4b[_0x2fb6('0x5b')];_0xe2c2fc[_0x2fb6('0x1d')]=_0x161e4b[_0x2fb6('0x1d')]||undefined;return _0xe2c2fc;};exports[_0x2fb6('0x5c')]=function(_0x229629,_0x1e8772){if(!_[_0x2fb6('0x32')](_0x229629)){if(_0x229629['pTalking']>0x0){_0x229629[_0x2fb6('0x5d')]-=0x1;}else{logger[_0x2fb6('0x35')](_0x1e8772,'[decrementTalkink]\x20object\x20talking\x20is\x20negative');}}else{logger[_0x2fb6('0x35')](_0x1e8772,_0x2fb6('0x5e'));}};exports[_0x2fb6('0x5f')]=function(_0x35a932){if(_0x35a932<=0x0){return!![];}return![];};exports[_0x2fb6('0x60')]=function(_0x484f4b,_0xdccc56,_0x4334cc){_0x484f4b[_0x2fb6('0x61')]=_0xdccc56;_0x484f4b[_0x2fb6('0x62')]=_0x484f4b[_0x2fb6('0x63')];_0x484f4b[_0x2fb6('0x64')]=_0x484f4b['channelAgent'];if(_0x4334cc){_0x484f4b[_0x2fb6('0x65')]=_0x4334cc[_0x2fb6('0x65')];}return _0x484f4b;};exports['buildAcw']=function(_0x23c2c2){var _0x50ec20={};_0x50ec20[_0x2fb6('0x63')]=_0x23c2c2['queue'];_0x50ec20['interface']=_0x23c2c2[_0x2fb6('0x4c')];_0x50ec20['uniqueid']=_0x23c2c2[_0x2fb6('0x4b')];return _0x50ec20;};exports[_0x2fb6('0x66')]=function(_0x53801c){var _0x5073d8=[];for(var _0x45fa69 in _0x53801c){if(_0x53801c[_0x2fb6('0x2b')](_0x45fa69)){if(!_[_0x2fb6('0x32')](_0x53801c[_0x45fa69])&&_0x53801c[_0x45fa69][_0x2fb6('0x39')]===_0x2fb6('0x67')&&_0x53801c[_0x45fa69]['status']===_0x2fb6('0x68')){_0x5073d8[_0x2fb6('0x69')](_0x53801c[_0x45fa69]['id']);}}}return _0x5073d8;};exports[_0x2fb6('0x6a')]=function(_0x33dcce){var _0xee697d=moment()[_0x2fb6('0x5')](0x0);var _0x383bb1=moment(_0x33dcce)[_0x2fb6('0x5')](0x0);return _0xee697d[_0x2fb6('0x6')](_0x383bb1,_0x2fb6('0x7'));};exports[_0x2fb6('0x6b')]=function(_0x5166c7){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x5166c7[_0x2fb6('0x1b')],'ListId':_0x5166c7[_0x2fb6('0x5b')],'VoiceQueueId':_0x5166c7[_0x2fb6('0x1d')]||undefined,'CampaignId':_0x5166c7[_0x2fb6('0x6c')]||undefined};};exports[_0x2fb6('0x6d')]=function(_0x37bf43){if(_0x37bf43===_0x2fb6('0x4b')||_0x37bf43==='idContact'||_0x37bf43===_0x2fb6('0x63')||_0x37bf43===_0x2fb6('0x6e')||_0x37bf43==='campaigntype'||_0x37bf43===_0x2fb6('0x6f')||_0x37bf43==='membername'||_0x37bf43==='channelAgent'||_0x37bf43===_0x2fb6('0x19')||_0x37bf43===_0x2fb6('0x70')||_0x37bf43===_0x2fb6('0x1a')||_0x37bf43==='scheduledat'||_0x37bf43==='countbusyretry'||_0x37bf43===_0x2fb6('0x50')||_0x37bf43===_0x2fb6('0x51')||_0x37bf43===_0x2fb6('0x71')||_0x37bf43===_0x2fb6('0x72')||_0x37bf43==='callbackuniqueid'||_0x37bf43===_0x2fb6('0x73')||_0x37bf43===_0x2fb6('0x74')||_0x37bf43===_0x2fb6('0x1b')||_0x37bf43===_0x2fb6('0x5b')||_0x37bf43==='UserId'||_0x37bf43===_0x2fb6('0x1d')||_0x37bf43===_0x2fb6('0x75')||_0x37bf43==='xmd-voicequeueid'||_0x37bf43===_0x2fb6('0x76')||_0x37bf43===_0x2fb6('0x77')||_0x37bf43===_0x2fb6('0x78')||_0x37bf43===_0x2fb6('0x79')||_0x37bf43==='xmd-dialtimeout'||_0x37bf43===_0x2fb6('0x7a')||_0x37bf43===_0x2fb6('0x7b')||_0x37bf43==='xmd-dialchannel'||_0x37bf43===_0x2fb6('0x7c')||_0x37bf43===_0x2fb6('0x7d')||_0x37bf43===_0x2fb6('0x7e')||_0x37bf43==='xmd-agiafter'||_0x37bf43===_0x2fb6('0x7f')||_0x37bf43===_0x2fb6('0x80')||_0x37bf43===_0x2fb6('0x81')||_0x37bf43===_0x2fb6('0x82')||_0x37bf43===_0x2fb6('0x83')||_0x37bf43===_0x2fb6('0x84')||_0x37bf43==='rtpaudioqoslossbridged'||_0x37bf43==='rtpaudioqosrtt'||_0x37bf43===_0x2fb6('0x85')||_0x37bf43===_0x2fb6('0x80')||_0x37bf43===_0x2fb6('0x81')||_0x37bf43===_0x2fb6('0x82')||_0x37bf43==='rtpaudioqosjitterbridged'||_0x37bf43===_0x2fb6('0x84')||_0x37bf43===_0x2fb6('0x86')||_0x37bf43===_0x2fb6('0x87')||_0x37bf43==='rtpaudioqosrttbridged'||_0x37bf43==='bridgepeer'||_0x37bf43===_0x2fb6('0x88')||_0x37bf43===_0x2fb6('0x39')||_0x37bf43===_0x2fb6('0x3a')){return![];}return!![];};exports[_0x2fb6('0x89')]=function(_0x372ec2,_0x36e8df){var _0x7fffd5,_0x462fbe,_0x3d0b6c;if(_0x36e8df<=0x0){_0x36e8df=0x1;}_0x7fffd5=new RegExp(_0x2fb6('0x8a')+_0x36e8df+'}$');_0x462fbe=Math[_0x2fb6('0x8b')](0xa,_0x36e8df-0x1);_0x3d0b6c=Math[_0x2fb6('0x8b')](0xa,_0x36e8df)-0x1;return util['format']('%s',_[_0x2fb6('0x8c')](_0x372ec2,_0x7fffd5,_[_0x2fb6('0x8d')](_0x462fbe,_0x3d0b6c)));};exports[_0x2fb6('0x8e')]=function(_0x20c4a2){var _0x4ec86f=_0x20c4a2[_0x2fb6('0x8f')](/"(.*?)"/);return _0x4ec86f?_0x4ec86f[0x1]:_0x20c4a2;};exports[_0x2fb6('0x90')]=function(_0x4b75c5){var _0x3046ed=_0x4b75c5['match'](/<(.*?)>/);return _0x3046ed?_0x3046ed[0x1]:_0x4b75c5;};