c9122190dd80c049237d6b7a3a3ee951d71a87d3
[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 _0xebf9=['xmd-listid','xmd-dialtimeout','xmd-dialoptions','xmd-dialid','xmd-dialchannel','xmd-contactid','xmd-cdrtype','xmd-callerid','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosrttbridged','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','pow','replace','random','extractCalleridName','match','extractCalleridNumber','noanswer','variables','forEach','toLowerCase','buildNoAnswerEventPayload','util','lodash','moment','preview','XCALLY_IP_AGI','127.0.0.1','../../dialer/utils','loggerCatch','error','inspect','info','loggerError','logger2','message','getCallerId','isUndefined','isEmpty','\x22%s\x22\x20<%s>','format','string','\x22\x22\x20<>','isActive','isNil','addVariables','Queue','calleridnum','ContactId','dialer','VoiceQueueId','\x22rtTxX%s%s\x22','dialQueueProject2','U(xcally-mixmonitor-context)','dialPreviewUrl','dialQueueProject','\x22agi://%s/square,%s\x22','NONE','Call-Type:\x20PREVIEW','monitor_format','_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','toLowerVariables','hasOwnProperty','toLower','YYYY-MM-DD\x20HH:mm:ss','state','statedesc','Blacklist','starttime','responsetime','endtime','ringtime','getSeconds','logLookAgent','membername','UserId','logCustomer','talktime','answertime','Failure','variablesAction','RECALL','BOOKED','uniqueid','originate','channelAgent','xcally-motion-preview','timeout','countbusyretry','countnoanswerretry','countagentrejectretry','clone','Global','scheduledAt','active','add','minutes','ListId','decrementTalking','pTalking','[decrementTalking]\x20is\x20null\x20or\x20undefined','IsNotLoggedIn','lastevent','queue','interface','motionChannel','voice','mandatoryDisposition','buildObj','not_inuse','reachable','push','getDiff','milliseconds','filterKey','idContact','type','campaigntype','dialAnswer','calleridname','scheduledat','countcongestionretry','callback','callbackuniqueid','callbackat','recallme','xmd-voicequeueid','xmd-phone'];(function(_0x520837,_0x41b00d){var _0x5f4317=function(_0x26d902){while(--_0x26d902){_0x520837['push'](_0x520837['shift']());}};_0x5f4317(++_0x41b00d);}(_0xebf9,0x1bd));var _0x9ebf=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0xebf9[_0x321bb2];return _0x9c12ed;};'use strict';var util=require(_0x9ebf('0x0'));var _=require(_0x9ebf('0x1'));var moment=require(_0x9ebf('0x2'));var logger=require('../../../../config/logger')(_0x9ebf('0x3'));var ipAgi=process['env'][_0x9ebf('0x4')]||_0x9ebf('0x5');var utils=require(_0x9ebf('0x6'));exports[_0x9ebf('0x7')]=function(_0x535da5){return function(_0x5908bf){logger[_0x9ebf('0x8')](_0x535da5,util[_0x9ebf('0x9')](_0x5908bf,{'showHidden':![],'depth':null}));};};exports['logger']=function(_0x1638a6,_0x3d9b64){logger[_0x9ebf('0xa')](_0x1638a6,util['inspect'](_0x3d9b64,{'showHidden':![],'depth':null}));};exports[_0x9ebf('0xb')]=function(_0x25c742,_0x2f89ff){logger[_0x9ebf('0x8')](_0x25c742,util[_0x9ebf('0x9')](_0x2f89ff,{'showHidden':![],'depth':null}));};exports[_0x9ebf('0xc')]=function(_0x374b52){return function(_0x19bf19){logger[_0x9ebf('0xa')](_0x374b52,util[_0x9ebf('0x9')](_0x19bf19,{'showHidden':![],'depth':null}));};};exports[_0x9ebf('0xd')]=function(_0x1143af,_0x28e613,_0x56e3d9){return{'message':_0x1143af,'unlock':_0x28e613,'active':_0x56e3d9};};exports[_0x9ebf('0xe')]=function(_0xf4623b,_0xd137b1,_0x162b6b){if(!_[_0x9ebf('0xf')](_0x162b6b)&&'string'===typeof _0x162b6b&&!_[_0x9ebf('0x10')](_0x162b6b)){if(!_['isUndefined'](_0xd137b1)&&'string'===typeof _0xd137b1&&!_[_0x9ebf('0x10')](_0xd137b1)){return util['format'](_0x9ebf('0x11'),_0xd137b1,_0x162b6b);}return util[_0x9ebf('0x12')](_0x9ebf('0x11'),_0x162b6b,_0x162b6b);}if(!_[_0x9ebf('0xf')](_0xf4623b)&&_0x9ebf('0x13')===typeof _0xf4623b&&!_['isEmpty'](_0xf4623b)){return _0xf4623b;}return _0x9ebf('0x14');};exports[_0x9ebf('0x15')]=function(_0x3dec09){if(_[_0x9ebf('0x16')](_0x3dec09)){return![];}return _0x3dec09;};exports[_0x9ebf('0x17')]=function(_0xabb307,_0x529dba,_0x318529,_0x31b2f1,_0x1b54ac,_0x365593){var _0x132a2f={'XMD-QUEUE':_0x529dba[_0x9ebf('0x18')]?_0x529dba[_0x9ebf('0x18')]['name']:'','XMD-CALLERID':_0x31b2f1,'XMD-CALLERID-PREVIEW':_0x365593?util[_0x9ebf('0x12')](_0x9ebf('0x11'),_0x365593['calleridname'],_0x365593[_0x9ebf('0x19')]):_0x31b2f1,'XMD-DIALID':_0x1b54ac,'XMD-CONTACTID':_0x529dba[_0x9ebf('0x1a')],'XMD-CDRTYPE':_0x9ebf('0x1b'),'CALLERID(all)':_0x31b2f1,'XMD-VOICEQUEUEID':_0x529dba[_0x9ebf('0x1c')],'XMD-DIALCHANNEL':_0x318529,'XMD-DIALTIMEOUT':_0xabb307['dialOriginateTimeout']||0x1e,'XMD-DIALOPTIONS':util[_0x9ebf('0x12')](_0x9ebf('0x1d'),_0xabb307[_0x9ebf('0x1e')]?'g':'',_['isEmpty'](_0xabb307['monitor_format'])?'':_0x9ebf('0x1f')),'XMD-DIALURL':_0xabb307[_0x9ebf('0x20')]||'','XMD-AGI':_0xabb307[_0x9ebf('0x21')]?util[_0x9ebf('0x12')](_0x9ebf('0x22'),ipAgi,_0xabb307[_0x9ebf('0x21')]):_0x9ebf('0x23'),'XMD-AGIAFTER':_0xabb307['dialQueueProject2']?util[_0x9ebf('0x12')](_0x9ebf('0x22'),ipAgi,_0xabb307[_0x9ebf('0x1e')]):_0x9ebf('0x23'),'XMD-ORIGINATECALLERIDNUM':_0x365593?_0x365593['originatecalleridnum']:'','XMD-ORIGINATECALLERIDNAME':_0x365593?_0x365593['originatecalleridname']:'','XMD-DESTINATION':'xcally-motion-preview','SIPADDHEADER':_0x9ebf('0x24')};if(!_[_0x9ebf('0x10')](_0xabb307[_0x9ebf('0x25')])){_0x132a2f[util[_0x9ebf('0x12')]('%s',_0x9ebf('0x26'))]=_0xabb307[_0x9ebf('0x25')];_0x132a2f[util['format']('%s',_0x9ebf('0x27'))]=_0x1b54ac;}return _0x132a2f;};exports[_0x9ebf('0x28')]=function(_0x1dd378){var _0x22144e={};for(var _0x3e2ace in _0x1dd378){if(_0x1dd378[_0x9ebf('0x29')](_0x3e2ace)){_0x22144e[util[_0x9ebf('0x12')]('%s',_[_0x9ebf('0x2a')](_0x3e2ace))]=_0x1dd378[_0x3e2ace];}}return{'variables':_0x22144e};};exports['logBlacklist']=function(_0x2bca50){var _0x3de663=moment()[_0x9ebf('0x12')](_0x9ebf('0x2b'));_0x2bca50[_0x9ebf('0x2c')]=0xd;_0x2bca50[_0x9ebf('0x2d')]=_0x9ebf('0x2e');_0x2bca50[_0x9ebf('0x2f')]=_0x3de663;_0x2bca50[_0x9ebf('0x30')]=_0x3de663;_0x2bca50[_0x9ebf('0x31')]=_0x3de663;};exports['logAgent']=function(_0x1c1db1,_0x21d841,_0x345854){var _0x17db52=moment()['format'](_0x9ebf('0x2b'));_0x1c1db1[_0x9ebf('0x2c')]=_0x21d841;_0x1c1db1['statedesc']=_0x345854;_0x1c1db1['responsetime']=_0x17db52;_0x1c1db1[_0x9ebf('0x32')]=utils[_0x9ebf('0x33')](_0x1c1db1['responsetime'],_0x1c1db1[_0x9ebf('0x2f')]);};exports[_0x9ebf('0x34')]=function(_0x6738b4,_0x4b4aaf,_0x4c35e5){_0x6738b4[_0x9ebf('0x35')]=_0x4b4aaf;_0x6738b4[_0x9ebf('0x36')]=_0x4c35e5;};exports[_0x9ebf('0x37')]=function(_0x210f0b,_0x5caf0a,_0x412685){var _0x153848=moment()[_0x9ebf('0x12')]('YYYY-MM-DD\x20HH:mm:ss');_0x210f0b[_0x9ebf('0x2c')]=_0x5caf0a;_0x210f0b[_0x9ebf('0x2d')]=_0x412685;_0x210f0b[_0x9ebf('0x30')]=_0x210f0b['responsetime']?_0x210f0b['responsetime']:_0x153848;_0x210f0b[_0x9ebf('0x31')]=_0x210f0b[_0x9ebf('0x31')]?_0x210f0b[_0x9ebf('0x31')]:_0x153848;_0x210f0b[_0x9ebf('0x32')]=utils[_0x9ebf('0x33')](_0x210f0b[_0x9ebf('0x30')]||0x0,_0x210f0b['starttime']||0x0);_0x210f0b[_0x9ebf('0x38')]=_0x210f0b[_0x9ebf('0x39')]?utils['getSeconds'](_0x210f0b[_0x9ebf('0x31')],_0x210f0b[_0x9ebf('0x39')]):0x0;};exports['isFailure']=function(_0x3f4271){return _0x3f4271===_0x9ebf('0x3a');};exports[_0x9ebf('0x3b')]=function(_0x4c89ee,_0x2c7cfa,_0x3efa1e,_0x424d9e,_0x41a9a4){var _0x4a0c3b=_0x424d9e?_0x9ebf('0x3c'):_0x4c89ee['calleridname'];_0x4a0c3b=_0x41a9a4?_0x9ebf('0x3d'):_0x4a0c3b;return{'actionid':_0x4c89ee[_0x9ebf('0x3e')],'action':_0x9ebf('0x3f'),'channel':_0x4c89ee[_0x9ebf('0x40')],'callerid':util[_0x9ebf('0x12')](_0x9ebf('0x11'),_0x4a0c3b,_0x4c89ee[_0x9ebf('0x19')]),'Exten':_0x9ebf('0x41'),'Context':'from-sip','Priority':'1','variable':_0x3efa1e,'timeout':(_0x2c7cfa[_0x9ebf('0x42')]||0x1e)*0x3e8,'async':!![],'channelid':_0x4c89ee[_0x9ebf('0x3e')]};};exports['totalGlobal']=function(_0x1db082){return _0x1db082[_0x9ebf('0x43')]+_0x1db082['countcongestionretry']+_0x1db082[_0x9ebf('0x44')]+_0x1db082[_0x9ebf('0x45')]+_0x1db082['countnosuchnumberretry'];};exports['cloneAction']=function(_0x7c3c60){var _0x545baf=_[_0x9ebf('0x46')](_0x7c3c60);_0x545baf[_0x9ebf('0x2c')]=0xf;_0x545baf[_0x9ebf('0x2d')]=_0x9ebf('0x47');return _0x545baf;};exports[_0x9ebf('0x48')]=function(_0x46415c,_0x5d7fb4,_0x4321ae){var _0x28d670={};_0x28d670[_0x5d7fb4]=_0x46415c[_0x5d7fb4];_0x28d670[_0x9ebf('0x49')]=![];_0x28d670['scheduledat']=moment()[_0x9ebf('0x4a')](_0x4321ae,_0x9ebf('0x4b'))[_0x9ebf('0x12')]('YYYY-MM-DD\x20HH:mm:ss');_0x28d670[_0x9ebf('0x1a')]=_0x46415c[_0x9ebf('0x1a')];_0x28d670[_0x9ebf('0x4c')]=_0x46415c['ListId'];_0x28d670[_0x9ebf('0x1c')]=_0x46415c[_0x9ebf('0x1c')]||undefined;return _0x28d670;};exports[_0x9ebf('0x4d')]=function(_0x2bda24,_0x1d0072){if(!_[_0x9ebf('0x16')](_0x2bda24)){if(_0x2bda24[_0x9ebf('0x4e')]>0x0){_0x2bda24['pTalking']-=0x1;}else{logger[_0x9ebf('0xa')](_0x1d0072,'[decrementTalking]\x20object\x20talking\x20is\x20negative');}}else{logger[_0x9ebf('0x8')](_0x1d0072,_0x9ebf('0x4f'));}};exports[_0x9ebf('0x50')]=function(_0x5707f0){if(_0x5707f0<=0x0){return!![];}return![];};function buildObj(_0x52b5ee,_0x31c428,_0x46e5c3){_0x52b5ee[_0x9ebf('0x51')]=_0x31c428;_0x52b5ee['name']=_0x52b5ee[_0x9ebf('0x52')];_0x52b5ee[_0x9ebf('0x53')]=_0x52b5ee[_0x9ebf('0x40')];_0x52b5ee[_0x9ebf('0x54')]=_0x9ebf('0x55');if(_0x46e5c3){_0x52b5ee['mandatoryDisposition']=_0x46e5c3[_0x9ebf('0x56')];}return _0x52b5ee;}exports[_0x9ebf('0x57')]=buildObj;exports['agentReadyId']=function(_0x50278b){var _0x4667cc=[];for(var _0x2ba6ff in _0x50278b){if(_0x50278b['hasOwnProperty'](_0x2ba6ff)){if(!_['isNil'](_0x50278b[_0x2ba6ff])&&_0x50278b[_0x2ba6ff][_0x9ebf('0x2c')]===_0x9ebf('0x58')&&_0x50278b[_0x2ba6ff]['status']===_0x9ebf('0x59')){_0x4667cc[_0x9ebf('0x5a')](_0x50278b[_0x2ba6ff]['id']);}}}return _0x4667cc;};exports[_0x9ebf('0x5b')]=function(_0x328c63){var _0x4d41f2=moment()['milliseconds'](0x0);var _0x3c9135=moment(_0x328c63)[_0x9ebf('0x5c')](0x0);return _0x4d41f2['diff'](_0x3c9135,'seconds');};exports['createBody']=function(_0x49a2a7){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x49a2a7['ContactId'],'ListId':_0x49a2a7[_0x9ebf('0x4c')],'VoiceQueueId':_0x49a2a7[_0x9ebf('0x1c')]||undefined,'CampaignId':_0x49a2a7['CampaignId']||undefined};};exports[_0x9ebf('0x5d')]=function(_0x5073c7){if(_0x5073c7==='uniqueid'||_0x5073c7===_0x9ebf('0x5e')||_0x5073c7==='queue'||_0x5073c7===_0x9ebf('0x5f')||_0x5073c7===_0x9ebf('0x60')||_0x5073c7===_0x9ebf('0x61')||_0x5073c7===_0x9ebf('0x35')||_0x5073c7===_0x9ebf('0x40')||_0x5073c7===_0x9ebf('0x62')||_0x5073c7==='active'||_0x5073c7===_0x9ebf('0x19')||_0x5073c7===_0x9ebf('0x63')||_0x5073c7===_0x9ebf('0x43')||_0x5073c7===_0x9ebf('0x64')||_0x5073c7==='countnoanswerretry'||_0x5073c7==='countglobal'||_0x5073c7===_0x9ebf('0x65')||_0x5073c7===_0x9ebf('0x66')||_0x5073c7===_0x9ebf('0x67')||_0x5073c7===_0x9ebf('0x68')||_0x5073c7===_0x9ebf('0x1a')||_0x5073c7===_0x9ebf('0x4c')||_0x5073c7===_0x9ebf('0x36')||_0x5073c7==='VoiceQueueId'||_0x5073c7==='sipcallid'||_0x5073c7===_0x9ebf('0x69')||_0x5073c7==='xmd-queue'||_0x5073c7===_0x9ebf('0x6a')||_0x5073c7===_0x9ebf('0x6b')||_0x5073c7==='xmd-dialurl'||_0x5073c7===_0x9ebf('0x6c')||_0x5073c7===_0x9ebf('0x6d')||_0x5073c7===_0x9ebf('0x6e')||_0x5073c7===_0x9ebf('0x6f')||_0x5073c7===_0x9ebf('0x70')||_0x5073c7===_0x9ebf('0x71')||_0x5073c7===_0x9ebf('0x72')||_0x5073c7==='xmd-agiafter'||_0x5073c7===_0x9ebf('0x73')||_0x5073c7===_0x9ebf('0x74')||_0x5073c7===_0x9ebf('0x75')||_0x5073c7==='rtpaudioqosjitter'||_0x5073c7==='rtpaudioqosjitterbridged'||_0x5073c7===_0x9ebf('0x76')||_0x5073c7===_0x9ebf('0x77')||_0x5073c7===_0x9ebf('0x78')||_0x5073c7==='rtpaudioqosrttbridged'||_0x5073c7===_0x9ebf('0x74')||_0x5073c7===_0x9ebf('0x75')||_0x5073c7===_0x9ebf('0x79')||_0x5073c7===_0x9ebf('0x7a')||_0x5073c7==='rtpaudioqosloss'||_0x5073c7==='rtpaudioqoslossbridged'||_0x5073c7===_0x9ebf('0x78')||_0x5073c7===_0x9ebf('0x7b')||_0x5073c7==='bridgepeer'||_0x5073c7===_0x9ebf('0x7c')||_0x5073c7===_0x9ebf('0x2c')||_0x5073c7===_0x9ebf('0x2d')){return![];}return!![];};exports[_0x9ebf('0x7d')]=function(_0x585876,_0x4ad285){var _0x183fcf,_0x102f5b,_0x2bb054;if(_0x4ad285<=0x0){_0x4ad285=0x1;}_0x183fcf=new RegExp(_0x9ebf('0x7e')+_0x4ad285+'}$');_0x102f5b=Math['pow'](0xa,_0x4ad285-0x1);_0x2bb054=Math[_0x9ebf('0x7f')](0xa,_0x4ad285)-0x1;return util['format']('%s',_[_0x9ebf('0x80')](_0x585876,_0x183fcf,_[_0x9ebf('0x81')](_0x102f5b,_0x2bb054)));};exports[_0x9ebf('0x82')]=function(_0x294c28){var _0x5e6328=_0x294c28[_0x9ebf('0x83')](/"(.*?)"/);return _0x5e6328?_0x5e6328[0x1]:_0x294c28;};exports[_0x9ebf('0x84')]=function(_0x1d709e){var _0x692d32=_0x1d709e[_0x9ebf('0x83')](/<(.*?)>/);return _0x692d32?_0x692d32[0x1]:_0x1d709e;};function buildNoAnswerEventPayload(_0x23f7b7,_0x7ea9ad){var _0x527824=buildObj(_0x23f7b7,_0x9ebf('0x85'));if(!_[_0x9ebf('0x10')](_0x7ea9ad[_0x9ebf('0x86')])){Object['keys'](_0x7ea9ad[_0x9ebf('0x86')])[_0x9ebf('0x87')](function(_0x1d4d61){_0x527824[_0x1d4d61[_0x9ebf('0x88')]()]=_0x7ea9ad['variables'][_0x1d4d61];});}return _0x527824;}exports[_0x9ebf('0x89')]=buildNoAnswerEventPayload;