Built motion from commit (unavailable).|2.4.17
[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 _0xfc2f=['ContactId','VoiceQueueId','\x22rtTxX%s%s\x22','dialQueueProject2','monitor_format','U(xcally-mixmonitor-context)','dialQueueProject','NONE','\x22agi://%s/square,%s\x22','originatecalleridnum','xcally-motion-preview','_XCALLY_MIXMONITOR_UNIQUEID','Contact','tags','createdAt','XMD-','toUpper','toLowerVariables','hasOwnProperty','toLower','updateOriginated','originated','[updateOriginated]\x20is\x20null\x20or\x20undefined','logBlacklist','YYYY-MM-DD\x20HH:mm:ss','state','statedesc','Blacklist','responsetime','logAgent','ringtime','starttime','membername','UserId','endtime','answertime','isFailure','variablesAction','RECALL','BOOKED','uniqueid','originate','channelAgent','calleridnum','from-sip','timeout','totalGlobal','countbusyretry','countcongestionretry','countnoanswerretry','clone','Global','scheduledAt','active','add','ListId','decrementTalkink','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','IsNotLoggedIn','lastevent','queue','interface','buildAcw','agentReadyId','status','reachable','push','getDiff','CampaignId','filterKey','type','campaigntype','dialAnswer','scheduledat','countglobal','callbackuniqueid','callbackat','recallme','xmd-voicequeueid','xmd-queue','xmd-phone','xmd-listid','xmd-dialurl','xmd-dialchannel','xmd-contactid','xmd-cdrtype','xmd-agi','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosloss','rtpaudioqosrttbridged','bridgepeer','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','match','extractCalleridNumber','lodash','moment','../../../../config/logger','env','milliseconds','seconds','loggerCatch','logger','info','inspect','loggerError','error','logger2','message','getCallerId','isUndefined','string','isEmpty','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isNil','Queue','name','calleridname'];(function(_0x506f64,_0x395f5a){var _0x389fdb=function(_0x3cf504){while(--_0x3cf504){_0x506f64['push'](_0x506f64['shift']());}};_0x389fdb(++_0x395f5a);}(_0xfc2f,0x164));var _0xffc2=function(_0x477c09,_0x385809){_0x477c09=_0x477c09-0x0;var _0x318ed1=_0xfc2f[_0x477c09];return _0x318ed1;};'use strict';var util=require('util');var _=require(_0xffc2('0x0'));var moment=require(_0xffc2('0x1'));var logger=require(_0xffc2('0x2'))('preview');var ipAgi=process[_0xffc2('0x3')]['XCALLY_IP_AGI']||'127.0.0.1';function getSeconds(_0x546318,_0x4d6cfc){var _0x55afe7=moment(_0x546318)[_0xffc2('0x4')](0x0);var _0x302291=moment(_0x4d6cfc)[_0xffc2('0x4')](0x0);return _0x55afe7['diff'](_0x302291,_0xffc2('0x5'));}exports[_0xffc2('0x6')]=function(_0x2acdc3){return function(_0x58b132){logger['error'](_0x2acdc3,util['inspect'](_0x58b132,{'showHidden':![],'depth':null}));};};exports[_0xffc2('0x7')]=function(_0x9fac05,_0x46e6a9){logger[_0xffc2('0x8')](_0x9fac05,util[_0xffc2('0x9')](_0x46e6a9,{'showHidden':![],'depth':null}));};exports[_0xffc2('0xa')]=function(_0x5e0f6a,_0x3ef4b9){logger[_0xffc2('0xb')](_0x5e0f6a,util['inspect'](_0x3ef4b9,{'showHidden':![],'depth':null}));};exports[_0xffc2('0xc')]=function(_0x427a3e){return function(_0xd5f2a0){logger['info'](_0x427a3e,util[_0xffc2('0x9')](_0xd5f2a0,{'showHidden':![],'depth':null}));};};exports[_0xffc2('0xd')]=function(_0x421170,_0x3e35f5,_0x2c0611){return{'message':_0x421170,'unlock':_0x3e35f5,'active':_0x2c0611};};exports[_0xffc2('0xe')]=function(_0xd46315,_0x2f215b,_0x178162){if(!_[_0xffc2('0xf')](_0x178162)&&_0xffc2('0x10')===typeof _0x178162&&!_[_0xffc2('0x11')](_0x178162)){if(!_['isUndefined'](_0x2f215b)&&_0xffc2('0x10')===typeof _0x2f215b&&!_[_0xffc2('0x11')](_0x2f215b)){return util[_0xffc2('0x12')](_0xffc2('0x13'),_0x2f215b,_0x178162);}return util[_0xffc2('0x12')]('\x22%s\x22\x20<%s>',_0x178162,_0x178162);}if(!_[_0xffc2('0xf')](_0xd46315)&&_0xffc2('0x10')===typeof _0xd46315&&!_['isEmpty'](_0xd46315)){return _0xd46315;}return _0xffc2('0x14');};exports['isActive']=function(_0x5b4080){if(_[_0xffc2('0x15')](_0x5b4080)){return![];}return _0x5b4080;};exports['addVariables']=function(_0xb966e8,_0x5988e8,_0x1a85ec,_0x16deec,_0xb97ad5,_0x2a8061){var _0x959b7={'XMD-QUEUE':_0x5988e8[_0xffc2('0x16')]?_0x5988e8[_0xffc2('0x16')][_0xffc2('0x17')]:'','XMD-CALLERID':_0x16deec,'XMD-CALLERID-PREVIEW':_0x2a8061?util[_0xffc2('0x12')](_0xffc2('0x13'),_0x2a8061[_0xffc2('0x18')],_0x2a8061['calleridnum']):_0x16deec,'XMD-DIALID':_0xb97ad5,'XMD-CONTACTID':_0x5988e8[_0xffc2('0x19')],'XMD-CDRTYPE':'dialer','CALLERID(all)':_0x16deec,'XMD-VOICEQUEUEID':_0x5988e8[_0xffc2('0x1a')],'XMD-DIALCHANNEL':_0x1a85ec,'XMD-DIALTIMEOUT':_0xb966e8['dialOriginateTimeout']||0x1e,'XMD-DIALOPTIONS':util[_0xffc2('0x12')](_0xffc2('0x1b'),_0xb966e8[_0xffc2('0x1c')]?'g':'',_[_0xffc2('0x11')](_0xb966e8[_0xffc2('0x1d')])?'':_0xffc2('0x1e')),'XMD-DIALURL':_0xb966e8['dialPreviewUrl']||'','XMD-AGI':_0xb966e8['dialQueueProject']?util[_0xffc2('0x12')]('\x22agi://%s/square,%s\x22',ipAgi,_0xb966e8[_0xffc2('0x1f')]):_0xffc2('0x20'),'XMD-AGIAFTER':_0xb966e8[_0xffc2('0x1c')]?util[_0xffc2('0x12')](_0xffc2('0x21'),ipAgi,_0xb966e8[_0xffc2('0x1c')]):_0xffc2('0x20'),'XMD-ORIGINATECALLERIDNUM':_0x2a8061?_0x2a8061[_0xffc2('0x22')]:'','XMD-ORIGINATECALLERIDNAME':_0x2a8061?_0x2a8061['originatecalleridname']:'','XMD-DESTINATION':_0xffc2('0x23')};if(!_[_0xffc2('0x11')](_0xb966e8[_0xffc2('0x1d')])){_0x959b7[util[_0xffc2('0x12')]('%s','_XCALLY_MIXMONITOR_FORMAT')]=_0xb966e8[_0xffc2('0x1d')];_0x959b7[util[_0xffc2('0x12')]('%s',_0xffc2('0x24'))]=_0xb97ad5;}if(_0x5988e8&&_0x5988e8['Contact']){for(var _0x43ef27 in _0x5988e8['Contact']){if(_0x5988e8[_0xffc2('0x25')]['hasOwnProperty'](_0x43ef27)){if(!_[_0xffc2('0x15')](_0x5988e8['Contact'][_0x43ef27])&&_0x43ef27!=='id'&&_0x43ef27!==_0xffc2('0x26')&&_0x43ef27!==_0xffc2('0x27')&&_0x43ef27!=='updatedAt'){_0x959b7[util['format']('%s%s',_0xffc2('0x28'),_[_0xffc2('0x29')](_0x43ef27))]=_0x5988e8[_0xffc2('0x25')][_0x43ef27];}}}}return _0x959b7;};exports[_0xffc2('0x2a')]=function(_0x18f6fa){var _0x258a4f={};for(var _0x19d9c8 in _0x18f6fa){if(_0x18f6fa[_0xffc2('0x2b')](_0x19d9c8)){_0x258a4f[util[_0xffc2('0x12')]('%s',_[_0xffc2('0x2c')](_0x19d9c8))]=_0x18f6fa[_0x19d9c8];}}return{'variables':_0x258a4f};};exports[_0xffc2('0x2d')]=function(_0x3595dc,_0x377d98){if(!_[_0xffc2('0x15')](_0x3595dc)){if(_0x3595dc[_0xffc2('0x2b')](_0xffc2('0x2e'))){if(_0x3595dc['originated']>0x0){_0x3595dc[_0xffc2('0x2e')]-=0x1;}else{logger[_0xffc2('0xb')]('[updateOriginated]\x20object\x20originated\x20is\x20negative',_0x377d98);}}}else{logger[_0xffc2('0xb')](_0xffc2('0x2f'),_0x377d98);}};exports[_0xffc2('0x30')]=function(_0x11f6db){var _0x51d1dd=moment()[_0xffc2('0x12')](_0xffc2('0x31'));_0x11f6db[_0xffc2('0x32')]=0xd;_0x11f6db[_0xffc2('0x33')]=_0xffc2('0x34');_0x11f6db['starttime']=_0x51d1dd;_0x11f6db[_0xffc2('0x35')]=_0x51d1dd;_0x11f6db['endtime']=_0x51d1dd;};exports[_0xffc2('0x36')]=function(_0x2d4112,_0x649759,_0x4b917f){var _0x2895c0=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x2d4112[_0xffc2('0x32')]=_0x649759;_0x2d4112[_0xffc2('0x33')]=_0x4b917f;_0x2d4112[_0xffc2('0x35')]=_0x2895c0;_0x2d4112[_0xffc2('0x37')]=getSeconds(_0x2d4112[_0xffc2('0x35')],_0x2d4112[_0xffc2('0x38')]);};exports['logLookAgent']=function(_0x442d5f,_0x5a22b0,_0x30cf37){_0x442d5f[_0xffc2('0x39')]=_0x5a22b0;_0x442d5f[_0xffc2('0x3a')]=_0x30cf37;};exports['logCustomer']=function(_0x21e92f,_0x1b7134,_0x23b4d7){var _0x49c3be=moment()[_0xffc2('0x12')]('YYYY-MM-DD\x20HH:mm:ss');_0x21e92f['state']=_0x1b7134;_0x21e92f[_0xffc2('0x33')]=_0x23b4d7;_0x21e92f[_0xffc2('0x35')]=_0x21e92f['responsetime']?_0x21e92f[_0xffc2('0x35')]:_0x49c3be;_0x21e92f[_0xffc2('0x3b')]=_0x21e92f[_0xffc2('0x3b')]?_0x21e92f[_0xffc2('0x3b')]:_0x49c3be;_0x21e92f[_0xffc2('0x37')]=getSeconds(_0x21e92f['responsetime']||0x0,_0x21e92f['starttime']||0x0);_0x21e92f['talktime']=_0x21e92f[_0xffc2('0x3c')]?getSeconds(_0x21e92f[_0xffc2('0x3b')],_0x21e92f['answertime']):0x0;};exports[_0xffc2('0x3d')]=function(_0x467d47){return _0x467d47==='Failure';};exports[_0xffc2('0x3e')]=function(_0x12a842,_0x1ae411,_0x236953,_0x303f7b,_0x3be16d){var _0x3a384e=_0x303f7b?_0xffc2('0x3f'):_0x12a842[_0xffc2('0x18')];_0x3a384e=_0x3be16d?_0xffc2('0x40'):_0x3a384e;return{'actionid':_0x12a842[_0xffc2('0x41')],'action':_0xffc2('0x42'),'channel':_0x12a842[_0xffc2('0x43')],'callerid':util['format'](_0xffc2('0x13'),_0x3a384e,_0x12a842[_0xffc2('0x44')]),'Exten':'xcally-motion-preview','Context':_0xffc2('0x45'),'Priority':'1','variable':_0x236953,'timeout':(_0x1ae411[_0xffc2('0x46')]||0x1e)*0x3e8,'async':!![],'channelid':_0x12a842[_0xffc2('0x41')]};};exports[_0xffc2('0x47')]=function(_0x228c05){return _0x228c05[_0xffc2('0x48')]+_0x228c05[_0xffc2('0x49')]+_0x228c05[_0xffc2('0x4a')];};exports['cloneAction']=function(_0x382019){var _0x26cf39=_[_0xffc2('0x4b')](_0x382019);_0x26cf39[_0xffc2('0x32')]=0xf;_0x26cf39[_0xffc2('0x33')]=_0xffc2('0x4c');return _0x26cf39;};exports[_0xffc2('0x4d')]=function(_0x2132cc,_0x295519,_0x305160){var _0x252436={};_0x252436[_0x295519]=_0x2132cc[_0x295519];_0x252436[_0xffc2('0x4e')]=![];_0x252436['scheduledat']=moment()[_0xffc2('0x4f')](_0x305160,'minutes')[_0xffc2('0x12')](_0xffc2('0x31'));_0x252436[_0xffc2('0x19')]=_0x2132cc[_0xffc2('0x19')];_0x252436[_0xffc2('0x50')]=_0x2132cc[_0xffc2('0x50')];_0x252436[_0xffc2('0x1a')]=_0x2132cc[_0xffc2('0x1a')]||undefined;return _0x252436;};exports[_0xffc2('0x51')]=function(_0x5945dd,_0x43baf1){if(!_['isNil'](_0x5945dd)){if(_0x5945dd[_0xffc2('0x52')]>0x0){_0x5945dd[_0xffc2('0x52')]-=0x1;}else{logger[_0xffc2('0xb')](_0x43baf1,_0xffc2('0x53'));}}else{logger['error'](_0x43baf1,'[decrementTalkink]\x20is\x20null\x20or\x20undefined');}};exports[_0xffc2('0x54')]=function(_0x35cc84){if(_0x35cc84<=0x0){return!![];}return![];};exports['buildObj']=function(_0x10fe7d,_0x2dd859){_0x10fe7d[_0xffc2('0x55')]=_0x2dd859;_0x10fe7d['name']=_0x10fe7d[_0xffc2('0x56')];_0x10fe7d[_0xffc2('0x57')]=_0x10fe7d[_0xffc2('0x43')];return _0x10fe7d;};exports[_0xffc2('0x58')]=function(_0x229dc6){var _0x232e4a={};_0x232e4a['queue']=_0x229dc6[_0xffc2('0x56')];_0x232e4a['interface']=_0x229dc6['channelAgent'];_0x232e4a[_0xffc2('0x41')]=_0x229dc6[_0xffc2('0x41')];return _0x232e4a;};exports[_0xffc2('0x59')]=function(_0x5473a8){var _0x1a5a77=[];for(var _0x16660e in _0x5473a8){if(_0x5473a8[_0xffc2('0x2b')](_0x16660e)){if(!_[_0xffc2('0x15')](_0x5473a8[_0x16660e])&&_0x5473a8[_0x16660e][_0xffc2('0x32')]==='not_inuse'&&_0x5473a8[_0x16660e][_0xffc2('0x5a')]===_0xffc2('0x5b')){_0x1a5a77[_0xffc2('0x5c')](_0x5473a8[_0x16660e]['id']);}}}return _0x1a5a77;};exports[_0xffc2('0x5d')]=function(_0x530a45){var _0x272e31=moment()[_0xffc2('0x4')](0x0);var _0x12a7c3=moment(_0x530a45)[_0xffc2('0x4')](0x0);return _0x272e31['diff'](_0x12a7c3,'seconds');};exports['createBody']=function(_0x1897bc){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x1897bc['ContactId'],'ListId':_0x1897bc[_0xffc2('0x50')],'VoiceQueueId':_0x1897bc['VoiceQueueId']||undefined,'CampaignId':_0x1897bc[_0xffc2('0x5e')]||undefined};};exports[_0xffc2('0x5f')]=function(_0x1ab553){if(_0x1ab553===_0xffc2('0x41')||_0x1ab553==='idContact'||_0x1ab553===_0xffc2('0x56')||_0x1ab553===_0xffc2('0x60')||_0x1ab553===_0xffc2('0x61')||_0x1ab553===_0xffc2('0x62')||_0x1ab553===_0xffc2('0x39')||_0x1ab553===_0xffc2('0x43')||_0x1ab553===_0xffc2('0x18')||_0x1ab553===_0xffc2('0x4e')||_0x1ab553===_0xffc2('0x44')||_0x1ab553===_0xffc2('0x63')||_0x1ab553==='countbusyretry'||_0x1ab553===_0xffc2('0x49')||_0x1ab553===_0xffc2('0x4a')||_0x1ab553===_0xffc2('0x64')||_0x1ab553==='callback'||_0x1ab553===_0xffc2('0x65')||_0x1ab553===_0xffc2('0x66')||_0x1ab553===_0xffc2('0x67')||_0x1ab553===_0xffc2('0x19')||_0x1ab553==='ListId'||_0x1ab553===_0xffc2('0x3a')||_0x1ab553==='VoiceQueueId'||_0x1ab553==='sipcallid'||_0x1ab553===_0xffc2('0x68')||_0x1ab553===_0xffc2('0x69')||_0x1ab553===_0xffc2('0x6a')||_0x1ab553===_0xffc2('0x6b')||_0x1ab553===_0xffc2('0x6c')||_0x1ab553==='xmd-dialtimeout'||_0x1ab553==='xmd-dialoptions'||_0x1ab553==='xmd-dialid'||_0x1ab553===_0xffc2('0x6d')||_0x1ab553===_0xffc2('0x6e')||_0x1ab553===_0xffc2('0x6f')||_0x1ab553==='xmd-callerid'||_0x1ab553==='xmd-agiafter'||_0x1ab553===_0xffc2('0x70')||_0x1ab553===_0xffc2('0x71')||_0x1ab553===_0xffc2('0x72')||_0x1ab553===_0xffc2('0x73')||_0x1ab553===_0xffc2('0x74')||_0x1ab553==='rtpaudioqosloss'||_0x1ab553===_0xffc2('0x75')||_0x1ab553===_0xffc2('0x76')||_0x1ab553==='rtpaudioqosrttbridged'||_0x1ab553==='rtpaudioqos'||_0x1ab553===_0xffc2('0x72')||_0x1ab553===_0xffc2('0x73')||_0x1ab553===_0xffc2('0x74')||_0x1ab553===_0xffc2('0x77')||_0x1ab553===_0xffc2('0x75')||_0x1ab553==='rtpaudioqosrtt'||_0x1ab553===_0xffc2('0x78')||_0x1ab553===_0xffc2('0x79')||_0x1ab553===_0xffc2('0x7a')||_0x1ab553==='state'||_0x1ab553===_0xffc2('0x33')){return![];}return!![];};exports[_0xffc2('0x7b')]=function(_0x2ab60b,_0x2b7191){var _0xb25c0,_0x92be3d,_0x4e3cc6;if(_0x2b7191<=0x0){_0x2b7191=0x1;}_0xb25c0=new RegExp(_0xffc2('0x7c')+_0x2b7191+'}$');_0x92be3d=Math['pow'](0xa,_0x2b7191-0x1);_0x4e3cc6=Math['pow'](0xa,_0x2b7191)-0x1;return util[_0xffc2('0x12')]('%s',_['replace'](_0x2ab60b,_0xb25c0,_['random'](_0x92be3d,_0x4e3cc6)));};exports['extractCalleridName']=function(_0x412d9b){var _0x5641e7=_0x412d9b[_0xffc2('0x7d')](/"(.*?)"/);return _0x5641e7?_0x5641e7[0x1]:_0x412d9b;};exports[_0xffc2('0x7e')]=function(_0x56daca){var _0x5f141f=_0x56daca[_0xffc2('0x7d')](/<(.*?)>/);return _0x5f141f?_0x5f141f[0x1]:_0x56daca;};