Built motion from commit 9e1399f3.|2.5.37
[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 _0xf06a=['clone','scheduledAt','active','scheduledat','add','ListId','decrementTalkink','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','IsNotLoggedIn','lastevent','queue','motionChannel','voice','mandatoryDisposition','buildAcw','interface','agentReadyId','not_inuse','reachable','CampaignId','filterKey','idContact','type','campaigntype','dialAnswer','countglobal','callback','callbackuniqueid','recallme','xmd-voicequeueid','xmd-queue','xmd-phone','xmd-dialurl','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-dialchannel','xmd-contactid','xmd-callerid','xmd-agiafter','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrttbridged','rtpaudioqosrtt','bridgepeer','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','random','extractCalleridName','match','extractCalleridNumber','util','lodash','moment','preview','env','XCALLY_IP_AGI','127.0.0.1','milliseconds','diff','seconds','loggerCatch','error','inspect','logger','info','loggerError','message','getCallerId','isUndefined','string','isEmpty','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isActive','addVariables','Queue','name','calleridname','calleridnum','ContactId','dialer','VoiceQueueId','dialOriginateTimeout','\x22rtTxX%s%s\x22','U(xcally-mixmonitor-context)','dialPreviewUrl','dialQueueProject','\x22agi://%s/square,%s\x22','NONE','dialQueueProject2','originatecalleridnum','originatecalleridname','xcally-motion-preview','Call-Type:\x20PREVIEW','_XCALLY_MIXMONITOR_FORMAT','monitor_format','_XCALLY_MIXMONITOR_UNIQUEID','Contact','hasOwnProperty','isNil','tags','createdAt','updatedAt','XMD-','toUpper','toLowerVariables','toLower','updateOriginated','originated','[updateOriginated]\x20object\x20originated\x20is\x20negative','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','state','statedesc','Blacklist','starttime','responsetime','endtime','YYYY-MM-DD\x20HH:mm:ss','ringtime','membername','UserId','logCustomer','talktime','answertime','isFailure','Failure','variablesAction','RECALL','BOOKED','uniqueid','channelAgent','from-sip','totalGlobal','countbusyretry','countnoanswerretry','countagentrejectretry','countnosuchnumberretry','cloneAction'];(function(_0x10d3c2,_0x1f5142){var _0x4208aa=function(_0x2e1ff9){while(--_0x2e1ff9){_0x10d3c2['push'](_0x10d3c2['shift']());}};_0x4208aa(++_0x1f5142);}(_0xf06a,0x162));var _0xaf06=function(_0x4e1857,_0x2a6ccc){_0x4e1857=_0x4e1857-0x0;var _0x2ddd26=_0xf06a[_0x4e1857];return _0x2ddd26;};'use strict';var util=require(_0xaf06('0x0'));var _=require(_0xaf06('0x1'));var moment=require(_0xaf06('0x2'));var logger=require('../../../../config/logger')(_0xaf06('0x3'));var ipAgi=process[_0xaf06('0x4')][_0xaf06('0x5')]||_0xaf06('0x6');function getSeconds(_0x56ab5f,_0xaff3b3){var _0x231223=moment(_0x56ab5f)[_0xaf06('0x7')](0x0);var _0x47fc9a=moment(_0xaff3b3)[_0xaf06('0x7')](0x0);return _0x231223[_0xaf06('0x8')](_0x47fc9a,_0xaf06('0x9'));}exports[_0xaf06('0xa')]=function(_0x1a362b){return function(_0xc342cf){logger[_0xaf06('0xb')](_0x1a362b,util[_0xaf06('0xc')](_0xc342cf,{'showHidden':![],'depth':null}));};};exports[_0xaf06('0xd')]=function(_0xaa0805,_0x35a81c){logger[_0xaf06('0xe')](_0xaa0805,util['inspect'](_0x35a81c,{'showHidden':![],'depth':null}));};exports[_0xaf06('0xf')]=function(_0xbe75f0,_0x4414d5){logger[_0xaf06('0xb')](_0xbe75f0,util[_0xaf06('0xc')](_0x4414d5,{'showHidden':![],'depth':null}));};exports['logger2']=function(_0xfaa2fb){return function(_0x40be7f){logger[_0xaf06('0xe')](_0xfaa2fb,util['inspect'](_0x40be7f,{'showHidden':![],'depth':null}));};};exports[_0xaf06('0x10')]=function(_0x44b73d,_0x2a18bb,_0x60eb6a){return{'message':_0x44b73d,'unlock':_0x2a18bb,'active':_0x60eb6a};};exports[_0xaf06('0x11')]=function(_0x488938,_0x57e66b,_0x8a349f){if(!_[_0xaf06('0x12')](_0x8a349f)&&_0xaf06('0x13')===typeof _0x8a349f&&!_['isEmpty'](_0x8a349f)){if(!_[_0xaf06('0x12')](_0x57e66b)&&_0xaf06('0x13')===typeof _0x57e66b&&!_[_0xaf06('0x14')](_0x57e66b)){return util[_0xaf06('0x15')](_0xaf06('0x16'),_0x57e66b,_0x8a349f);}return util[_0xaf06('0x15')](_0xaf06('0x16'),_0x8a349f,_0x8a349f);}if(!_['isUndefined'](_0x488938)&&_0xaf06('0x13')===typeof _0x488938&&!_[_0xaf06('0x14')](_0x488938)){return _0x488938;}return _0xaf06('0x17');};exports[_0xaf06('0x18')]=function(_0x2d8dac){if(_['isNil'](_0x2d8dac)){return![];}return _0x2d8dac;};exports[_0xaf06('0x19')]=function(_0x4c17ba,_0x236e07,_0x154062,_0x1b60b0,_0x49cf1,_0x2aa042){var _0x2c4e4a={'XMD-QUEUE':_0x236e07[_0xaf06('0x1a')]?_0x236e07['Queue'][_0xaf06('0x1b')]:'','XMD-CALLERID':_0x1b60b0,'XMD-CALLERID-PREVIEW':_0x2aa042?util[_0xaf06('0x15')](_0xaf06('0x16'),_0x2aa042[_0xaf06('0x1c')],_0x2aa042[_0xaf06('0x1d')]):_0x1b60b0,'XMD-DIALID':_0x49cf1,'XMD-CONTACTID':_0x236e07[_0xaf06('0x1e')],'XMD-CDRTYPE':_0xaf06('0x1f'),'CALLERID(all)':_0x1b60b0,'XMD-VOICEQUEUEID':_0x236e07[_0xaf06('0x20')],'XMD-DIALCHANNEL':_0x154062,'XMD-DIALTIMEOUT':_0x4c17ba[_0xaf06('0x21')]||0x1e,'XMD-DIALOPTIONS':util[_0xaf06('0x15')](_0xaf06('0x22'),_0x4c17ba['dialQueueProject2']?'g':'',_[_0xaf06('0x14')](_0x4c17ba['monitor_format'])?'':_0xaf06('0x23')),'XMD-DIALURL':_0x4c17ba[_0xaf06('0x24')]||'','XMD-AGI':_0x4c17ba[_0xaf06('0x25')]?util[_0xaf06('0x15')](_0xaf06('0x26'),ipAgi,_0x4c17ba[_0xaf06('0x25')]):_0xaf06('0x27'),'XMD-AGIAFTER':_0x4c17ba[_0xaf06('0x28')]?util['format'](_0xaf06('0x26'),ipAgi,_0x4c17ba['dialQueueProject2']):'NONE','XMD-ORIGINATECALLERIDNUM':_0x2aa042?_0x2aa042[_0xaf06('0x29')]:'','XMD-ORIGINATECALLERIDNAME':_0x2aa042?_0x2aa042[_0xaf06('0x2a')]:'','XMD-DESTINATION':_0xaf06('0x2b'),'SIPADDHEADER':_0xaf06('0x2c')};if(!_[_0xaf06('0x14')](_0x4c17ba['monitor_format'])){_0x2c4e4a[util[_0xaf06('0x15')]('%s',_0xaf06('0x2d'))]=_0x4c17ba[_0xaf06('0x2e')];_0x2c4e4a[util['format']('%s',_0xaf06('0x2f'))]=_0x49cf1;}if(_0x236e07&&_0x236e07[_0xaf06('0x30')]){for(var _0x5c95bd in _0x236e07['Contact']){if(_0x236e07[_0xaf06('0x30')][_0xaf06('0x31')](_0x5c95bd)){if(!_[_0xaf06('0x32')](_0x236e07['Contact'][_0x5c95bd])&&_0x5c95bd!=='id'&&_0x5c95bd!==_0xaf06('0x33')&&_0x5c95bd!==_0xaf06('0x34')&&_0x5c95bd!==_0xaf06('0x35')){_0x2c4e4a[util[_0xaf06('0x15')]('%s%s',_0xaf06('0x36'),_[_0xaf06('0x37')](_0x5c95bd))]=_0x236e07['Contact'][_0x5c95bd];}}}}return _0x2c4e4a;};exports[_0xaf06('0x38')]=function(_0xc7b003){var _0x39abde={};for(var _0x53a95e in _0xc7b003){if(_0xc7b003[_0xaf06('0x31')](_0x53a95e)){_0x39abde[util[_0xaf06('0x15')]('%s',_[_0xaf06('0x39')](_0x53a95e))]=_0xc7b003[_0x53a95e];}}return{'variables':_0x39abde};};exports[_0xaf06('0x3a')]=function(_0x321c6d,_0x1ea8c1){if(!_[_0xaf06('0x32')](_0x321c6d)){if(_0x321c6d[_0xaf06('0x31')](_0xaf06('0x3b'))){if(_0x321c6d[_0xaf06('0x3b')]>0x0){_0x321c6d[_0xaf06('0x3b')]-=0x1;}else{logger['error'](_0xaf06('0x3c'),_0x1ea8c1);}}}else{logger[_0xaf06('0xb')](_0xaf06('0x3d'),_0x1ea8c1);}};exports[_0xaf06('0x3e')]=function(_0x3e9366){var _0x12ab28=moment()[_0xaf06('0x15')]('YYYY-MM-DD\x20HH:mm:ss');_0x3e9366[_0xaf06('0x3f')]=0xd;_0x3e9366[_0xaf06('0x40')]=_0xaf06('0x41');_0x3e9366[_0xaf06('0x42')]=_0x12ab28;_0x3e9366[_0xaf06('0x43')]=_0x12ab28;_0x3e9366[_0xaf06('0x44')]=_0x12ab28;};exports['logAgent']=function(_0x469e7c,_0x5c0143,_0x8364e5){var _0x28d430=moment()[_0xaf06('0x15')](_0xaf06('0x45'));_0x469e7c[_0xaf06('0x3f')]=_0x5c0143;_0x469e7c[_0xaf06('0x40')]=_0x8364e5;_0x469e7c[_0xaf06('0x43')]=_0x28d430;_0x469e7c[_0xaf06('0x46')]=getSeconds(_0x469e7c[_0xaf06('0x43')],_0x469e7c['starttime']);};exports['logLookAgent']=function(_0x46b68a,_0x490ae4,_0x3794d1){_0x46b68a[_0xaf06('0x47')]=_0x490ae4;_0x46b68a[_0xaf06('0x48')]=_0x3794d1;};exports[_0xaf06('0x49')]=function(_0x58bc1d,_0x4ebb74,_0x3cfb1f){var _0x3f9730=moment()[_0xaf06('0x15')](_0xaf06('0x45'));_0x58bc1d['state']=_0x4ebb74;_0x58bc1d[_0xaf06('0x40')]=_0x3cfb1f;_0x58bc1d[_0xaf06('0x43')]=_0x58bc1d[_0xaf06('0x43')]?_0x58bc1d[_0xaf06('0x43')]:_0x3f9730;_0x58bc1d[_0xaf06('0x44')]=_0x58bc1d['endtime']?_0x58bc1d[_0xaf06('0x44')]:_0x3f9730;_0x58bc1d[_0xaf06('0x46')]=getSeconds(_0x58bc1d[_0xaf06('0x43')]||0x0,_0x58bc1d[_0xaf06('0x42')]||0x0);_0x58bc1d[_0xaf06('0x4a')]=_0x58bc1d[_0xaf06('0x4b')]?getSeconds(_0x58bc1d[_0xaf06('0x44')],_0x58bc1d[_0xaf06('0x4b')]):0x0;};exports[_0xaf06('0x4c')]=function(_0x5c3886){return _0x5c3886===_0xaf06('0x4d');};exports[_0xaf06('0x4e')]=function(_0xda4fd,_0x173cf7,_0x9cc1cc,_0x55a6d7,_0x3aee97){var _0x3784af=_0x55a6d7?_0xaf06('0x4f'):_0xda4fd[_0xaf06('0x1c')];_0x3784af=_0x3aee97?_0xaf06('0x50'):_0x3784af;return{'actionid':_0xda4fd[_0xaf06('0x51')],'action':'originate','channel':_0xda4fd[_0xaf06('0x52')],'callerid':util['format'](_0xaf06('0x16'),_0x3784af,_0xda4fd['calleridnum']),'Exten':_0xaf06('0x2b'),'Context':_0xaf06('0x53'),'Priority':'1','variable':_0x9cc1cc,'timeout':(_0x173cf7['timeout']||0x1e)*0x3e8,'async':!![],'channelid':_0xda4fd[_0xaf06('0x51')]};};exports[_0xaf06('0x54')]=function(_0x1e00f1){return _0x1e00f1[_0xaf06('0x55')]+_0x1e00f1['countcongestionretry']+_0x1e00f1[_0xaf06('0x56')]+_0x1e00f1[_0xaf06('0x57')]+_0x1e00f1[_0xaf06('0x58')];};exports[_0xaf06('0x59')]=function(_0x565b36){var _0x36b9f9=_[_0xaf06('0x5a')](_0x565b36);_0x36b9f9[_0xaf06('0x3f')]=0xf;_0x36b9f9[_0xaf06('0x40')]='Global';return _0x36b9f9;};exports[_0xaf06('0x5b')]=function(_0x327a9f,_0x292a95,_0x5d8c57){var _0x23975f={};_0x23975f[_0x292a95]=_0x327a9f[_0x292a95];_0x23975f[_0xaf06('0x5c')]=![];_0x23975f[_0xaf06('0x5d')]=moment()[_0xaf06('0x5e')](_0x5d8c57,'minutes')[_0xaf06('0x15')](_0xaf06('0x45'));_0x23975f['ContactId']=_0x327a9f[_0xaf06('0x1e')];_0x23975f[_0xaf06('0x5f')]=_0x327a9f[_0xaf06('0x5f')];_0x23975f['VoiceQueueId']=_0x327a9f[_0xaf06('0x20')]||undefined;return _0x23975f;};exports[_0xaf06('0x60')]=function(_0x5e6f5b,_0x19d832){if(!_[_0xaf06('0x32')](_0x5e6f5b)){if(_0x5e6f5b[_0xaf06('0x61')]>0x0){_0x5e6f5b[_0xaf06('0x61')]-=0x1;}else{logger['error'](_0x19d832,_0xaf06('0x62'));}}else{logger['error'](_0x19d832,'[decrementTalkink]\x20is\x20null\x20or\x20undefined');}};exports[_0xaf06('0x63')]=function(_0x2809b8){if(_0x2809b8<=0x0){return!![];}return![];};exports['buildObj']=function(_0x52ec07,_0x48ef96,_0x2b77f7){_0x52ec07[_0xaf06('0x64')]=_0x48ef96;_0x52ec07[_0xaf06('0x1b')]=_0x52ec07[_0xaf06('0x65')];_0x52ec07['interface']=_0x52ec07[_0xaf06('0x52')];_0x52ec07[_0xaf06('0x66')]=_0xaf06('0x67');if(_0x2b77f7){_0x52ec07[_0xaf06('0x68')]=_0x2b77f7[_0xaf06('0x68')];}return _0x52ec07;};exports[_0xaf06('0x69')]=function(_0x1f0c3f){var _0xdeb4f3={};_0xdeb4f3[_0xaf06('0x65')]=_0x1f0c3f[_0xaf06('0x65')];_0xdeb4f3[_0xaf06('0x6a')]=_0x1f0c3f[_0xaf06('0x52')];_0xdeb4f3['uniqueid']=_0x1f0c3f[_0xaf06('0x51')];return _0xdeb4f3;};exports[_0xaf06('0x6b')]=function(_0x2a0046){var _0x5efc64=[];for(var _0x557e30 in _0x2a0046){if(_0x2a0046['hasOwnProperty'](_0x557e30)){if(!_[_0xaf06('0x32')](_0x2a0046[_0x557e30])&&_0x2a0046[_0x557e30][_0xaf06('0x3f')]===_0xaf06('0x6c')&&_0x2a0046[_0x557e30]['status']===_0xaf06('0x6d')){_0x5efc64['push'](_0x2a0046[_0x557e30]['id']);}}}return _0x5efc64;};exports['getDiff']=function(_0x1e67ab){var _0x10517d=moment()[_0xaf06('0x7')](0x0);var _0x201d46=moment(_0x1e67ab)[_0xaf06('0x7')](0x0);return _0x10517d[_0xaf06('0x8')](_0x201d46,'seconds');};exports['createBody']=function(_0x306b9c){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x306b9c[_0xaf06('0x1e')],'ListId':_0x306b9c[_0xaf06('0x5f')],'VoiceQueueId':_0x306b9c['VoiceQueueId']||undefined,'CampaignId':_0x306b9c[_0xaf06('0x6e')]||undefined};};exports[_0xaf06('0x6f')]=function(_0x2b8e00){if(_0x2b8e00==='uniqueid'||_0x2b8e00===_0xaf06('0x70')||_0x2b8e00==='queue'||_0x2b8e00===_0xaf06('0x71')||_0x2b8e00===_0xaf06('0x72')||_0x2b8e00===_0xaf06('0x73')||_0x2b8e00===_0xaf06('0x47')||_0x2b8e00===_0xaf06('0x52')||_0x2b8e00==='calleridname'||_0x2b8e00==='active'||_0x2b8e00===_0xaf06('0x1d')||_0x2b8e00==='scheduledat'||_0x2b8e00===_0xaf06('0x55')||_0x2b8e00==='countcongestionretry'||_0x2b8e00===_0xaf06('0x56')||_0x2b8e00===_0xaf06('0x74')||_0x2b8e00===_0xaf06('0x75')||_0x2b8e00===_0xaf06('0x76')||_0x2b8e00==='callbackat'||_0x2b8e00===_0xaf06('0x77')||_0x2b8e00===_0xaf06('0x1e')||_0x2b8e00==='ListId'||_0x2b8e00===_0xaf06('0x48')||_0x2b8e00===_0xaf06('0x20')||_0x2b8e00==='sipcallid'||_0x2b8e00===_0xaf06('0x78')||_0x2b8e00===_0xaf06('0x79')||_0x2b8e00===_0xaf06('0x7a')||_0x2b8e00==='xmd-listid'||_0x2b8e00===_0xaf06('0x7b')||_0x2b8e00===_0xaf06('0x7c')||_0x2b8e00===_0xaf06('0x7d')||_0x2b8e00===_0xaf06('0x7e')||_0x2b8e00===_0xaf06('0x7f')||_0x2b8e00===_0xaf06('0x80')||_0x2b8e00==='xmd-cdrtype'||_0x2b8e00===_0xaf06('0x81')||_0x2b8e00===_0xaf06('0x82')||_0x2b8e00===_0xaf06('0x83')||_0x2b8e00===_0xaf06('0x84')||_0x2b8e00===_0xaf06('0x85')||_0x2b8e00===_0xaf06('0x86')||_0x2b8e00===_0xaf06('0x87')||_0x2b8e00===_0xaf06('0x88')||_0x2b8e00===_0xaf06('0x89')||_0x2b8e00==='rtpaudioqosrtt'||_0x2b8e00===_0xaf06('0x8a')||_0x2b8e00==='rtpaudioqos'||_0x2b8e00===_0xaf06('0x85')||_0x2b8e00===_0xaf06('0x86')||_0x2b8e00==='rtpaudioqosjitterbridged'||_0x2b8e00===_0xaf06('0x88')||_0x2b8e00==='rtpaudioqoslossbridged'||_0x2b8e00===_0xaf06('0x8b')||_0x2b8e00===_0xaf06('0x8a')||_0x2b8e00===_0xaf06('0x8c')||_0x2b8e00===_0xaf06('0x8d')||_0x2b8e00===_0xaf06('0x3f')||_0x2b8e00===_0xaf06('0x40')){return![];}return!![];};exports[_0xaf06('0x8e')]=function(_0x316d54,_0xc65ed3){var _0x27e9c2,_0x135089,_0x37bffd;if(_0xc65ed3<=0x0){_0xc65ed3=0x1;}_0x27e9c2=new RegExp(_0xaf06('0x8f')+_0xc65ed3+'}$');_0x135089=Math['pow'](0xa,_0xc65ed3-0x1);_0x37bffd=Math['pow'](0xa,_0xc65ed3)-0x1;return util[_0xaf06('0x15')]('%s',_['replace'](_0x316d54,_0x27e9c2,_[_0xaf06('0x90')](_0x135089,_0x37bffd)));};exports[_0xaf06('0x91')]=function(_0x4b797f){var _0x24aa1a=_0x4b797f[_0xaf06('0x92')](/"(.*?)"/);return _0x24aa1a?_0x24aa1a[0x1]:_0x4b797f;};exports[_0xaf06('0x93')]=function(_0x59b972){var _0x525955=_0x59b972[_0xaf06('0x92')](/<(.*?)>/);return _0x525955?_0x525955[0x1]:_0x59b972;};