8882247c64b2ca89a3af8fd21f84053a7ac61d05
[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 _0x510c=['logger','info','logger2','message','getCallerId','isUndefined','string','isEmpty','format','\x22%s\x22\x20<%s>','\x22\x22\x20<>','isActive','isNil','addVariables','Queue','name','calleridname','calleridnum','dialer','dialOriginateTimeout','\x22rtTxX%s%s\x22','dialQueueProject2','U(xcally-mixmonitor-context)','dialPreviewUrl','\x22agi://%s/square,%s\x22','NONE','originatecalleridnum','originatecalleridname','Call-Type:\x20PREVIEW','monitor_format','_XCALLY_MIXMONITOR_FORMAT','_XCALLY_MIXMONITOR_UNIQUEID','toLowerVariables','hasOwnProperty','toLower','updateOriginated','originated','error','logBlacklist','YYYY-MM-DD\x20HH:mm:ss','state','Blacklist','starttime','responsetime','endtime','logAgent','getSeconds','logLookAgent','membername','UserId','logCustomer','statedesc','ringtime','talktime','answertime','isFailure','Failure','variablesAction','RECALL','BOOKED','uniqueid','originate','channelAgent','xcally-motion-preview','from-sip','timeout','countbusyretry','countnosuchnumberretry','cloneAction','clone','Global','scheduledAt','scheduledat','add','minutes','ContactId','ListId','VoiceQueueId','decrementTalkink','pTalking','[decrementTalkink]\x20object\x20talking\x20is\x20negative','[decrementTalkink]\x20is\x20null\x20or\x20undefined','motionChannel','voice','mandatoryDisposition','buildObj','agentReadyId','not_inuse','status','reachable','push','getDiff','milliseconds','seconds','createBody','idContact','campaigntype','dialAnswer','active','countcongestionretry','countnoanswerretry','countglobal','callback','callbackuniqueid','callbackat','sipcallid','xmd-voicequeueid','xmd-phone','xmd-listid','xmd-dialurl','xmd-dialoptions','xmd-dialid','xmd-dialchannel','xmd-contactid','xmd-cdrtype','xmd-agiafter','rtpaudioqos','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrttbridged','rtpaudioqosbridged','rtpaudioqosrtt','bridgepeer','bridgepvtcallid','getCallerIdRandom','\x5cw{0,','pow','extractCalleridName','match','noanswer','variables','keys','toLowerCase','buildNoAnswerEventPayload','lodash','moment','env','XCALLY_IP_AGI','127.0.0.1','loggerCatch','inspect'];(function(_0x21435f,_0x2887a2){var _0x22e018=function(_0x109e20){while(--_0x109e20){_0x21435f['push'](_0x21435f['shift']());}};_0x22e018(++_0x2887a2);}(_0x510c,0x88));var _0xc510=function(_0x27d7a0,_0x2c669c){_0x27d7a0=_0x27d7a0-0x0;var _0x5943db=_0x510c[_0x27d7a0];return _0x5943db;};'use strict';var util=require('util');var _=require(_0xc510('0x0'));var moment=require(_0xc510('0x1'));var logger=require('../../../../config/logger')('preview');var ipAgi=process[_0xc510('0x2')][_0xc510('0x3')]||_0xc510('0x4');var utils=require('../../dialer/utils');exports[_0xc510('0x5')]=function(_0x2117f9){return function(_0x586049){logger['error'](_0x2117f9,util[_0xc510('0x6')](_0x586049,{'showHidden':![],'depth':null}));};};exports[_0xc510('0x7')]=function(_0x2c3ce4,_0xdda155){logger[_0xc510('0x8')](_0x2c3ce4,util[_0xc510('0x6')](_0xdda155,{'showHidden':![],'depth':null}));};exports['loggerError']=function(_0x5b4163,_0x3d3fa3){logger['error'](_0x5b4163,util['inspect'](_0x3d3fa3,{'showHidden':![],'depth':null}));};exports[_0xc510('0x9')]=function(_0xcc11b){return function(_0x5d7b84){logger[_0xc510('0x8')](_0xcc11b,util[_0xc510('0x6')](_0x5d7b84,{'showHidden':![],'depth':null}));};};exports[_0xc510('0xa')]=function(_0x2cae28,_0x113771,_0x3b6d4c){return{'message':_0x2cae28,'unlock':_0x113771,'active':_0x3b6d4c};};exports[_0xc510('0xb')]=function(_0x16d9f1,_0x2139a6,_0x252d2e){if(!_[_0xc510('0xc')](_0x252d2e)&&_0xc510('0xd')===typeof _0x252d2e&&!_[_0xc510('0xe')](_0x252d2e)){if(!_['isUndefined'](_0x2139a6)&&_0xc510('0xd')===typeof _0x2139a6&&!_[_0xc510('0xe')](_0x2139a6)){return util[_0xc510('0xf')](_0xc510('0x10'),_0x2139a6,_0x252d2e);}return util['format']('\x22%s\x22\x20<%s>',_0x252d2e,_0x252d2e);}if(!_['isUndefined'](_0x16d9f1)&&'string'===typeof _0x16d9f1&&!_[_0xc510('0xe')](_0x16d9f1)){return _0x16d9f1;}return _0xc510('0x11');};exports[_0xc510('0x12')]=function(_0x2b9259){if(_[_0xc510('0x13')](_0x2b9259)){return![];}return _0x2b9259;};exports[_0xc510('0x14')]=function(_0x28a74e,_0x4723fb,_0x1caec8,_0x53fb11,_0x5d9d54,_0xb8a3bd){var _0x134add={'XMD-QUEUE':_0x4723fb[_0xc510('0x15')]?_0x4723fb[_0xc510('0x15')][_0xc510('0x16')]:'','XMD-CALLERID':_0x53fb11,'XMD-CALLERID-PREVIEW':_0xb8a3bd?util[_0xc510('0xf')](_0xc510('0x10'),_0xb8a3bd[_0xc510('0x17')],_0xb8a3bd[_0xc510('0x18')]):_0x53fb11,'XMD-DIALID':_0x5d9d54,'XMD-CONTACTID':_0x4723fb['ContactId'],'XMD-CDRTYPE':_0xc510('0x19'),'CALLERID(all)':_0x53fb11,'XMD-VOICEQUEUEID':_0x4723fb['VoiceQueueId'],'XMD-DIALCHANNEL':_0x1caec8,'XMD-DIALTIMEOUT':_0x28a74e[_0xc510('0x1a')]||0x1e,'XMD-DIALOPTIONS':util[_0xc510('0xf')](_0xc510('0x1b'),_0x28a74e[_0xc510('0x1c')]?'g':'',_['isEmpty'](_0x28a74e['monitor_format'])?'':_0xc510('0x1d')),'XMD-DIALURL':_0x28a74e[_0xc510('0x1e')]||'','XMD-AGI':_0x28a74e['dialQueueProject']?util[_0xc510('0xf')](_0xc510('0x1f'),ipAgi,_0x28a74e['dialQueueProject']):_0xc510('0x20'),'XMD-AGIAFTER':_0x28a74e[_0xc510('0x1c')]?util[_0xc510('0xf')](_0xc510('0x1f'),ipAgi,_0x28a74e[_0xc510('0x1c')]):_0xc510('0x20'),'XMD-ORIGINATECALLERIDNUM':_0xb8a3bd?_0xb8a3bd[_0xc510('0x21')]:'','XMD-ORIGINATECALLERIDNAME':_0xb8a3bd?_0xb8a3bd[_0xc510('0x22')]:'','XMD-DESTINATION':'xcally-motion-preview','SIPADDHEADER':_0xc510('0x23')};if(!_[_0xc510('0xe')](_0x28a74e[_0xc510('0x24')])){_0x134add[util['format']('%s',_0xc510('0x25'))]=_0x28a74e[_0xc510('0x24')];_0x134add[util[_0xc510('0xf')]('%s',_0xc510('0x26'))]=_0x5d9d54;}return _0x134add;};exports[_0xc510('0x27')]=function(_0x3cf29b){var _0x244619={};for(var _0x1bced9 in _0x3cf29b){if(_0x3cf29b[_0xc510('0x28')](_0x1bced9)){_0x244619[util[_0xc510('0xf')]('%s',_[_0xc510('0x29')](_0x1bced9))]=_0x3cf29b[_0x1bced9];}}return{'variables':_0x244619};};exports[_0xc510('0x2a')]=function(_0x1aa948,_0x3f6ac2){if(!_['isNil'](_0x1aa948)){if(_0x1aa948[_0xc510('0x28')](_0xc510('0x2b'))){if(_0x1aa948[_0xc510('0x2b')]>0x0){_0x1aa948[_0xc510('0x2b')]-=0x1;}else{logger['error']('[updateOriginated]\x20object\x20originated\x20is\x20negative',_0x3f6ac2);}}}else{logger[_0xc510('0x2c')]('[updateOriginated]\x20is\x20null\x20or\x20undefined',_0x3f6ac2);}};exports[_0xc510('0x2d')]=function(_0x315b9d){var _0x5a720b=moment()[_0xc510('0xf')](_0xc510('0x2e'));_0x315b9d[_0xc510('0x2f')]=0xd;_0x315b9d['statedesc']=_0xc510('0x30');_0x315b9d[_0xc510('0x31')]=_0x5a720b;_0x315b9d[_0xc510('0x32')]=_0x5a720b;_0x315b9d[_0xc510('0x33')]=_0x5a720b;};exports[_0xc510('0x34')]=function(_0x3688b7,_0x5addb4,_0x3318df){var _0x163a91=moment()[_0xc510('0xf')](_0xc510('0x2e'));_0x3688b7[_0xc510('0x2f')]=_0x5addb4;_0x3688b7['statedesc']=_0x3318df;_0x3688b7[_0xc510('0x32')]=_0x163a91;_0x3688b7['ringtime']=utils[_0xc510('0x35')](_0x3688b7[_0xc510('0x32')],_0x3688b7[_0xc510('0x31')]);};exports[_0xc510('0x36')]=function(_0x32927f,_0xb17e2,_0x197dd0){_0x32927f[_0xc510('0x37')]=_0xb17e2;_0x32927f[_0xc510('0x38')]=_0x197dd0;};exports[_0xc510('0x39')]=function(_0x2ed328,_0x4adb97,_0x4c11a9){var _0x12f7d3=moment()[_0xc510('0xf')](_0xc510('0x2e'));_0x2ed328[_0xc510('0x2f')]=_0x4adb97;_0x2ed328[_0xc510('0x3a')]=_0x4c11a9;_0x2ed328[_0xc510('0x32')]=_0x2ed328['responsetime']?_0x2ed328[_0xc510('0x32')]:_0x12f7d3;_0x2ed328[_0xc510('0x33')]=_0x2ed328[_0xc510('0x33')]?_0x2ed328[_0xc510('0x33')]:_0x12f7d3;_0x2ed328[_0xc510('0x3b')]=utils['getSeconds'](_0x2ed328[_0xc510('0x32')]||0x0,_0x2ed328['starttime']||0x0);_0x2ed328[_0xc510('0x3c')]=_0x2ed328['answertime']?utils[_0xc510('0x35')](_0x2ed328['endtime'],_0x2ed328[_0xc510('0x3d')]):0x0;};exports[_0xc510('0x3e')]=function(_0x3f7811){return _0x3f7811===_0xc510('0x3f');};exports[_0xc510('0x40')]=function(_0x2eb8dc,_0x35f54e,_0x42d1a2,_0x190868,_0x1d29f3){var _0x4c9665=_0x190868?_0xc510('0x41'):_0x2eb8dc[_0xc510('0x17')];_0x4c9665=_0x1d29f3?_0xc510('0x42'):_0x4c9665;return{'actionid':_0x2eb8dc[_0xc510('0x43')],'action':_0xc510('0x44'),'channel':_0x2eb8dc[_0xc510('0x45')],'callerid':util[_0xc510('0xf')](_0xc510('0x10'),_0x4c9665,_0x2eb8dc[_0xc510('0x18')]),'Exten':_0xc510('0x46'),'Context':_0xc510('0x47'),'Priority':'1','variable':_0x42d1a2,'timeout':(_0x35f54e[_0xc510('0x48')]||0x1e)*0x3e8,'async':!![],'channelid':_0x2eb8dc[_0xc510('0x43')]};};exports['totalGlobal']=function(_0x4c7dab){return _0x4c7dab[_0xc510('0x49')]+_0x4c7dab['countcongestionretry']+_0x4c7dab['countnoanswerretry']+_0x4c7dab['countagentrejectretry']+_0x4c7dab[_0xc510('0x4a')];};exports[_0xc510('0x4b')]=function(_0x3f0667){var _0x1e1f90=_[_0xc510('0x4c')](_0x3f0667);_0x1e1f90[_0xc510('0x2f')]=0xf;_0x1e1f90[_0xc510('0x3a')]=_0xc510('0x4d');return _0x1e1f90;};exports[_0xc510('0x4e')]=function(_0x45d49f,_0xd3f723,_0x3e019e){var _0x284737={};_0x284737[_0xd3f723]=_0x45d49f[_0xd3f723];_0x284737['active']=![];_0x284737[_0xc510('0x4f')]=moment()[_0xc510('0x50')](_0x3e019e,_0xc510('0x51'))[_0xc510('0xf')](_0xc510('0x2e'));_0x284737[_0xc510('0x52')]=_0x45d49f[_0xc510('0x52')];_0x284737[_0xc510('0x53')]=_0x45d49f['ListId'];_0x284737['VoiceQueueId']=_0x45d49f[_0xc510('0x54')]||undefined;return _0x284737;};exports[_0xc510('0x55')]=function(_0xbad9a9,_0x27ca82){if(!_[_0xc510('0x13')](_0xbad9a9)){if(_0xbad9a9[_0xc510('0x56')]>0x0){_0xbad9a9[_0xc510('0x56')]-=0x1;}else{logger[_0xc510('0x2c')](_0x27ca82,_0xc510('0x57'));}}else{logger[_0xc510('0x2c')](_0x27ca82,_0xc510('0x58'));}};exports['IsNotLoggedIn']=function(_0x233071){if(_0x233071<=0x0){return!![];}return![];};function buildObj(_0x5c5431,_0x433664,_0x1ef550){_0x5c5431['lastevent']=_0x433664;_0x5c5431[_0xc510('0x16')]=_0x5c5431['queue'];_0x5c5431['interface']=_0x5c5431[_0xc510('0x45')];_0x5c5431[_0xc510('0x59')]=_0xc510('0x5a');if(_0x1ef550){_0x5c5431[_0xc510('0x5b')]=_0x1ef550[_0xc510('0x5b')];}return _0x5c5431;}exports[_0xc510('0x5c')]=buildObj;exports[_0xc510('0x5d')]=function(_0xe41b48){var _0x3b15f8=[];for(var _0xd21114 in _0xe41b48){if(_0xe41b48['hasOwnProperty'](_0xd21114)){if(!_[_0xc510('0x13')](_0xe41b48[_0xd21114])&&_0xe41b48[_0xd21114]['state']===_0xc510('0x5e')&&_0xe41b48[_0xd21114][_0xc510('0x5f')]===_0xc510('0x60')){_0x3b15f8[_0xc510('0x61')](_0xe41b48[_0xd21114]['id']);}}}return _0x3b15f8;};exports[_0xc510('0x62')]=function(_0x5f2294){var _0x38894b=moment()[_0xc510('0x63')](0x0);var _0x24a232=moment(_0x5f2294)[_0xc510('0x63')](0x0);return _0x38894b['diff'](_0x24a232,_0xc510('0x64'));};exports[_0xc510('0x65')]=function(_0x5adc54){return{'active':![],'recallme':![],'UserId':null,'ContactId':_0x5adc54['ContactId'],'ListId':_0x5adc54['ListId'],'VoiceQueueId':_0x5adc54['VoiceQueueId']||undefined,'CampaignId':_0x5adc54['CampaignId']||undefined};};exports['filterKey']=function(_0x1a73c0){if(_0x1a73c0===_0xc510('0x43')||_0x1a73c0===_0xc510('0x66')||_0x1a73c0==='queue'||_0x1a73c0==='type'||_0x1a73c0===_0xc510('0x67')||_0x1a73c0===_0xc510('0x68')||_0x1a73c0===_0xc510('0x37')||_0x1a73c0===_0xc510('0x45')||_0x1a73c0==='calleridname'||_0x1a73c0===_0xc510('0x69')||_0x1a73c0==='calleridnum'||_0x1a73c0==='scheduledat'||_0x1a73c0==='countbusyretry'||_0x1a73c0===_0xc510('0x6a')||_0x1a73c0===_0xc510('0x6b')||_0x1a73c0===_0xc510('0x6c')||_0x1a73c0===_0xc510('0x6d')||_0x1a73c0===_0xc510('0x6e')||_0x1a73c0===_0xc510('0x6f')||_0x1a73c0==='recallme'||_0x1a73c0===_0xc510('0x52')||_0x1a73c0===_0xc510('0x53')||_0x1a73c0===_0xc510('0x38')||_0x1a73c0===_0xc510('0x54')||_0x1a73c0===_0xc510('0x70')||_0x1a73c0===_0xc510('0x71')||_0x1a73c0==='xmd-queue'||_0x1a73c0===_0xc510('0x72')||_0x1a73c0===_0xc510('0x73')||_0x1a73c0===_0xc510('0x74')||_0x1a73c0==='xmd-dialtimeout'||_0x1a73c0===_0xc510('0x75')||_0x1a73c0===_0xc510('0x76')||_0x1a73c0===_0xc510('0x77')||_0x1a73c0===_0xc510('0x78')||_0x1a73c0===_0xc510('0x79')||_0x1a73c0==='xmd-callerid'||_0x1a73c0===_0xc510('0x7a')||_0x1a73c0==='xmd-agi'||_0x1a73c0===_0xc510('0x7b')||_0x1a73c0==='rtpaudioqosbridged'||_0x1a73c0===_0xc510('0x7c')||_0x1a73c0===_0xc510('0x7d')||_0x1a73c0===_0xc510('0x7e')||_0x1a73c0===_0xc510('0x7f')||_0x1a73c0==='rtpaudioqosrtt'||_0x1a73c0===_0xc510('0x80')||_0x1a73c0===_0xc510('0x7b')||_0x1a73c0===_0xc510('0x81')||_0x1a73c0===_0xc510('0x7c')||_0x1a73c0===_0xc510('0x7d')||_0x1a73c0==='rtpaudioqosloss'||_0x1a73c0===_0xc510('0x7f')||_0x1a73c0===_0xc510('0x82')||_0x1a73c0===_0xc510('0x80')||_0x1a73c0===_0xc510('0x83')||_0x1a73c0===_0xc510('0x84')||_0x1a73c0===_0xc510('0x2f')||_0x1a73c0==='statedesc'){return![];}return!![];};exports[_0xc510('0x85')]=function(_0x443117,_0x2e19d7){var _0x5d6605,_0x4d7b75,_0xb626ec;if(_0x2e19d7<=0x0){_0x2e19d7=0x1;}_0x5d6605=new RegExp(_0xc510('0x86')+_0x2e19d7+'}$');_0x4d7b75=Math[_0xc510('0x87')](0xa,_0x2e19d7-0x1);_0xb626ec=Math[_0xc510('0x87')](0xa,_0x2e19d7)-0x1;return util['format']('%s',_['replace'](_0x443117,_0x5d6605,_['random'](_0x4d7b75,_0xb626ec)));};exports[_0xc510('0x88')]=function(_0xe0f2ae){var _0x230e78=_0xe0f2ae[_0xc510('0x89')](/"(.*?)"/);return _0x230e78?_0x230e78[0x1]:_0xe0f2ae;};exports['extractCalleridNumber']=function(_0x4e84ee){var _0x5472a3=_0x4e84ee[_0xc510('0x89')](/<(.*?)>/);return _0x5472a3?_0x5472a3[0x1]:_0x4e84ee;};function buildNoAnswerEventPayload(_0x4b5f81,_0x1f7279){var _0x6f48d=buildObj(_0x4b5f81,_0xc510('0x8a'));if(!_[_0xc510('0xe')](_0x1f7279[_0xc510('0x8b')])){Object[_0xc510('0x8c')](_0x1f7279['variables'])['forEach'](function(_0x564b91){_0x6f48d[_0x564b91[_0xc510('0x8d')]()]=_0x1f7279[_0xc510('0x8b')][_0x564b91];});}return _0x6f48d;}exports[_0xc510('0x8e')]=buildNoAnswerEventPayload;