Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / realtime / realtime.controller.js
index 18bbafe..a90379f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5fab=['pause','every','faxStatus','mailStatus','whatsappStatus','*pause','getAgents','lastLoginAt','lastPauseAt','pauseType','internal','address','mailPause','faxPause','chatCapacity','mailCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','smsPause','resolve','fieldName','type','role','agent','query','getOptions','raw','user','userProfileId','nolimit','sort','UserProfile','getResources','findAndCountAll','rows','globalStatus','globalStatusFilter','pauseTypeFilter','getQueues','mail','sms','openchannel','fax','channel','includes','toLowerCase','rawAttributes','key','QueueCampaigns','all','util','lodash','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','offset','undefined','limit','count','status','set','Content-Range','json','error','name','send','request','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','result','merge','catch','voice','startCase','Queues','format','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','available','waiting','talking','paused','outbound','push','pTalking','originated','message','dialActive','dialMethod','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalTotalCalls','predictiveIntervalAvgHoldtime','map','get','agents','busy','pick','filter','queue','toString','find','UserId','accountcode','online','voiceStatus','User','Queue','QueueId','length','loggedInDb','idle','unknown','unavailable','ringing','isNil','chatPause','openchannelPause','voicePause','whatsappPause'];(function(_0x6acb69,_0xd36dbf){var _0x29a021=function(_0x374293){while(--_0x374293){_0x6acb69['push'](_0x6acb69['shift']());}};_0x29a021(++_0xd36dbf);}(_0x5fab,0x177));var _0xb5fa=function(_0x4e9df2,_0x36818e){_0x4e9df2=_0x4e9df2-0x0;var _0x9fe790=_0x5fab[_0x4e9df2];return _0x9fe790;};'use strict';var util=require(_0xb5fa('0x0'));var _=require(_0xb5fa('0x1'));var jayson=require('jayson/promise');var qs=require(_0xb5fa('0x2'));var logger=require(_0xb5fa('0x3'))(_0xb5fa('0x4'));var db=require(_0xb5fa('0x5'))['db'];var amiClient=jayson[_0xb5fa('0x6')][_0xb5fa('0x7')]({'port':0x232a});var routingClient=jayson[_0xb5fa('0x6')][_0xb5fa('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x10361d,_0x44df89){return function(_0x4a0249){if(_0x4a0249){var _0x5d70f6=typeof _0x44df89[_0xb5fa('0x8')]===_0xb5fa('0x9')&&typeof _0x44df89[_0xb5fa('0xa')]==='undefined';var _0x410eff=_0x4a0249[_0xb5fa('0xb')];var _0x2cf4a5=_0x5d70f6?0x0:_0x44df89['offset'];var _0x5b5ea8=_0x5d70f6?_0x4a0249[_0xb5fa('0xb')]:_0x44df89[_0xb5fa('0x8')]+_0x44df89[_0xb5fa('0xa')];var _0x44e6c8;if(_0x5b5ea8>=_0x410eff){_0x5b5ea8=_0x410eff;_0x44e6c8=0xc8;}else{_0x44e6c8=0xce;}_0x10361d[_0xb5fa('0xc')](_0x44e6c8);return _0x10361d[_0xb5fa('0xd')](_0xb5fa('0xe'),_0x2cf4a5+'-'+_0x5b5ea8+'/'+_0x410eff)[_0xb5fa('0xf')](_0x4a0249);}return null;};}function handleError(_0x309740,_0x4d3576){_0x4d3576=_0x4d3576||0x1f4;return function(_0x2ad830){logger[_0xb5fa('0x10')](_0x2ad830['stack']);if(_0x2ad830[_0xb5fa('0x11')]){delete _0x2ad830['name'];}_0x309740[_0xb5fa('0xc')](_0x4d3576)[_0xb5fa('0x12')](_0x2ad830);};}function getRealtimeAgents(){return new Promise(function(_0x40c914,_0xca8d82){return amiClient[_0xb5fa('0x13')]('Agents',{})['then'](function(_0x38e964){if(_0x38e964[_0xb5fa('0x10')])throw new Error(_0xb5fa('0x14'));var _0x27c8f7=_0x38e964['result'];return routingClient['request'](_0xb5fa('0x15'),{})[_0xb5fa('0x16')](function(_0x32e9e5){if(_0x32e9e5[_0xb5fa('0x10')])throw new Error(_0xb5fa('0x17'));var _0x13e82b=_0x32e9e5[_0xb5fa('0x18')];return _0x40c914(_[_0xb5fa('0x19')]({},_0x27c8f7,_0x13e82b));});})[_0xb5fa('0x1a')](function(_0x368cb1){_0xca8d82(_0x368cb1);});});}function getRealtimeQueues(_0x3c8d53,_0x1f5064){return new Promise(function(_0x5cd822,_0x432bfa){var _0x519e20=_0x1f5064===_0xb5fa('0x1b')?amiClient:routingClient;return _0x519e20['request'](_[_0xb5fa('0x1c')](_0x1f5064)+_0xb5fa('0x1d'),_0x3c8d53)['then'](function(_0x40dfdf){if(_0x40dfdf[_0xb5fa('0x10')])throw new Error(util[_0xb5fa('0x1e')]('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0x1f5064));return _0x5cd822(_0x40dfdf[_0xb5fa('0x18')]);})[_0xb5fa('0x1a')](function(_0x444237){_0x432bfa(_0x444237);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x542348,_0x224ec8){return amiClient['request'](_0xb5fa('0x1f'),{})[_0xb5fa('0x16')](function(_0x11053a){if(_0x11053a[_0xb5fa('0x10')])throw new Error(_0xb5fa('0x20'));return _0x542348(_0x11053a[_0xb5fa('0x18')]);})[_0xb5fa('0x1a')](function(_0x20d649){_0x224ec8(_0x20d649);});});}function initializeQueues(_0x568870,_0x4ec294,_0x5bdf11,_0x5a1c39){var _0x28a350=[_0xb5fa('0x21'),_0xb5fa('0x22'),_0xb5fa('0x23'),_0xb5fa('0x24'),_0xb5fa('0x25')];if(_0x5bdf11===_0xb5fa('0x1b')&&_0x5a1c39===_0xb5fa('0x26')){_0x28a350[_0xb5fa('0x27')](_0xb5fa('0x28'),_0xb5fa('0x29'),_0xb5fa('0x2a'),_0xb5fa('0x2b'),_0xb5fa('0x2c'),_0xb5fa('0x2d'),_0xb5fa('0x2e'),_0xb5fa('0x2f'),_0xb5fa('0x30'),_0xb5fa('0x31'),_0xb5fa('0x32'),_0xb5fa('0x33'),_0xb5fa('0x34'),_0xb5fa('0x35'),_0xb5fa('0x36'),'predictiveIntervalAvailable',_0xb5fa('0x37'),'predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit',_0xb5fa('0x38'),'predictiveIntervalAvgTalktime');}return _0x568870[_0xb5fa('0x39')](function(_0x5876f1){var _0x5518b1=_0x5876f1[_0xb5fa('0x3a')]({'plain':!![]});_0x5518b1[_0xb5fa('0x3b')]=[];_0x5518b1['paused']=0x0;_0x5518b1['loggedInDb']=0x0;_0x5518b1[_0xb5fa('0x21')]=0x0;_0x5518b1[_0xb5fa('0x22')]=0x0;_0x5518b1[_0xb5fa('0x23')]=0x0;if(_0x5bdf11==='voice'){_0x5518b1[_0xb5fa('0x24')]=0x0;_0x5518b1[_0xb5fa('0x3c')]=0x0;if(_0x5a1c39==='outbound'){_0x5518b1[_0xb5fa('0x28')]=0x0;_0x5518b1[_0xb5fa('0x29')]=0x0;}}var _0x204d6b=_['find'](_0x4ec294,['id',_0x5518b1['id']]);if(_0x204d6b)_[_0xb5fa('0x19')](_0x5518b1,_[_0xb5fa('0x3d')](_0x204d6b,_0x28a350));return _0x5518b1;});}function updateAgentVoiceStatus(_0x24ef11,_0x55bdb7,_0x117694){var _0x1c818f=_[_0xb5fa('0x3e')](_0x117694,[_0xb5fa('0x3f'),_0x55bdb7['name']]);if(_0x1c818f['length']===0x0)return _0x24ef11['busy']=!![];if(_['some'](_0x1c818f,['connectedlinenum',_0x24ef11['internal'][_0xb5fa('0x40')]()]))return _0x24ef11['talking']=!![];if(!_0x24ef11[_0xb5fa('0x24')])return _0x24ef11[_0xb5fa('0x3c')]=!![];}function getVoiceQueueAgents(_0x36db1a,_0x30b288,_0x40c1c0,_0x269d21){var _0x4b4c4c=_['find'](_0x30b288,['id',_0x36db1a['id']]);if(!_0x4b4c4c)return _0x36db1a;return _0x4b4c4c['getMembers']({'raw':!![]})[_0xb5fa('0x16')](function(_0x4d23f1){for(var _0x73d425=0x0;_0x73d425<_0x4d23f1['length'];_0x73d425++){var _0x58aa97=_[_0xb5fa('0x41')](_0x40c1c0,['id',_0x4d23f1[_0x73d425][_0xb5fa('0x42')]]);if(!_0x58aa97){_0x58aa97={'id':_0x4d23f1[_0x73d425][_0xb5fa('0x42')],'name':_0x4d23f1[_0x73d425][_0xb5fa('0x42')],'accountcode':'','online':![]};}var _0x5bc93f={'id':_0x58aa97['id'],'name':_0x58aa97[_0xb5fa('0x11')],'internal':_0x58aa97[_0xb5fa('0x43')],'online':Boolean(_0x58aa97[_0xb5fa('0x44')]),'paused':Boolean(_0x4d23f1[_0x73d425][_0xb5fa('0x25')])};if(_0x58aa97[_0xb5fa('0x45')]==='talking')updateAgentVoiceStatus(_0x5bc93f,_0x36db1a,_0x269d21);if(_0x5bc93f[_0xb5fa('0x44')])_0x36db1a['loggedInDb']++;if(_0x5bc93f[_0xb5fa('0x3c')])_0x36db1a[_0xb5fa('0x3c')]++;if(_0x5bc93f[_0xb5fa('0x25')]&&!_0x5bc93f[_0xb5fa('0x3c')]&&!_0x5bc93f[_0xb5fa('0x24')])_0x36db1a[_0xb5fa('0x25')]++;_0x36db1a[_0xb5fa('0x3b')][_0xb5fa('0x27')](_0x5bc93f);}return _0x36db1a;});}function getQueueAgents(_0x4da448,_0x1c3c2c,_0xc03e44){var _0x59ae64=_0xb5fa('0x46')+_['startCase'](_0xc03e44)+_0xb5fa('0x47');var _0x5ae45a=_0xc03e44+'Pause';return db[_0x59ae64]['findAll']({'where':{[_[_0xb5fa('0x1c')](_0xc03e44)+_0xb5fa('0x48')]:_0x4da448['id']},'raw':!![]})[_0xb5fa('0x16')](function(_0x19e662){for(var _0x430f46=0x0;_0x430f46<_0x19e662[_0xb5fa('0x49')];_0x430f46++){var _0x10f354=_[_0xb5fa('0x41')](_0x1c3c2c,['id',_0x19e662[_0x430f46]['UserId']]);if(!_0x10f354){_0x10f354={'id':_0x19e662[_0x430f46][_0xb5fa('0x42')],'name':_0x19e662[_0x430f46][_0xb5fa('0x42')],'online':![],['pauseField']:![]};}var _0x4e0fe7={'id':_0x10f354['id'],'name':_0x10f354[_0xb5fa('0x11')],'online':Boolean(_0x10f354[_0xb5fa('0x44')]),'paused':Boolean(_0x10f354[_0x5ae45a])};if(_0x4e0fe7[_0xb5fa('0x44')])_0x4da448[_0xb5fa('0x4a')]++;_0x4da448[_0xb5fa('0x3b')][_0xb5fa('0x27')](_0x4e0fe7);}return _0x4da448;});}function isIdle(_0x1e1c2){return _0x1e1c2===_0xb5fa('0x4b')||_0x1e1c2===_0xb5fa('0x4c')||_0x1e1c2===_0xb5fa('0x4d')||_0x1e1c2===_0xb5fa('0x4e')||_[_0xb5fa('0x4f')](_0x1e1c2);}function isAgentPaused(_0x6ae261,_0x23be4c){var _0x42a359=[_0x6ae261[_0xb5fa('0x50')],_0x6ae261['faxPause'],_0x6ae261['mailPause'],_0x6ae261[_0xb5fa('0x51')],_0x6ae261['smsPause'],_0x6ae261[_0xb5fa('0x52')],_0x6ae261[_0xb5fa('0x53')]];if(!_0x23be4c)return _['every'](_0x42a359);var _0x4ef1d0=_[_0xb5fa('0x3e')](_0x42a359);return _0x4ef1d0[_0xb5fa('0x49')]>0x0&&_0x4ef1d0[_0xb5fa('0x49')]<_0x42a359[_0xb5fa('0x49')]?!![]:![];}function isAgentIdle(_0x3ffee0){if(_0x3ffee0['voiceStatus']!==_0xb5fa('0x4b')&&_0x3ffee0['voicePause']){_0x3ffee0[_0xb5fa('0x45')]=_0xb5fa('0x54');return![];}return _[_0xb5fa('0x55')]([_0x3ffee0['chatStatus'],_0x3ffee0[_0xb5fa('0x56')],_0x3ffee0[_0xb5fa('0x57')],_0x3ffee0['openchannelStatus'],_0x3ffee0['smsStatus'],_0x3ffee0[_0xb5fa('0x45')],_0x3ffee0[_0xb5fa('0x58')]],isIdle);}function getAgentStatus(_0x320745){var _0x3ffdb5=_0xb5fa('0x4c');if(isAgentPaused(_0x320745))_0x3ffdb5=_0xb5fa('0x54');else if(isAgentPaused(_0x320745,!![]))_0x3ffdb5=_0xb5fa('0x59');else if(isAgentIdle(_0x320745))_0x3ffdb5=_0xb5fa('0x4b');else _0x3ffdb5=_0xb5fa('0x3c');return _0x3ffdb5;}exports[_0xb5fa('0x5a')]=function(_0x25de19,_0x35cf5a){var _0x3ccfd1={'count':0x0,'rows':[]},_0x2799e7={},_0x23f235,_0x42c34f,_0x10830a=['userpic',_0xb5fa('0x44'),_0xb5fa('0x5b'),_0xb5fa('0x5c'),_0xb5fa('0x5d'),_0xb5fa('0x5c'),_0xb5fa('0x5e'),_0xb5fa('0x5f'),_0xb5fa('0x50'),_0xb5fa('0x51'),_0xb5fa('0x60'),'smsPause','whatsappPause',_0xb5fa('0x61'),_0xb5fa('0x52'),_0xb5fa('0x62'),'openchannelCapacity',_0xb5fa('0x63'),_0xb5fa('0x64'),_0xb5fa('0x65'),_0xb5fa('0x66'),_0xb5fa('0x67'),_0xb5fa('0x68'),_0xb5fa('0x69'),'smsCurrentCapacity',_0xb5fa('0x6a'),_0xb5fa('0x6b'),'chatStatus',_0xb5fa('0x6c'),_0xb5fa('0x57'),'smsStatus',_0xb5fa('0x58'),_0xb5fa('0x56'),_0xb5fa('0x45'),_0xb5fa('0x6d'),_0xb5fa('0x6e'),_0xb5fa('0x6f'),_0xb5fa('0x70'),_0xb5fa('0x71'),_0xb5fa('0x72'),_0xb5fa('0x73'),_0xb5fa('0x3f'),_0xb5fa('0x74'),_0xb5fa('0x75'),_0xb5fa('0x76'),_0xb5fa('0x77'),_0xb5fa('0x78')],_0x24acea=[_0xb5fa('0x50'),_0xb5fa('0x51'),_0xb5fa('0x60'),_0xb5fa('0x79'),_0xb5fa('0x53'),_0xb5fa('0x61'),'voicePause',_0xb5fa('0x44')];Promise[_0xb5fa('0x7a')]()[_0xb5fa('0x16')](function(){var _0x580d1a=_[_0xb5fa('0x39')](db[_0xb5fa('0x46')]['rawAttributes'],function(_0x44fd4a){return{'name':_0x44fd4a[_0xb5fa('0x7b')],'type':_0x44fd4a[_0xb5fa('0x7c')]['key']};});_0x25de19['query'][_0xb5fa('0x7d')]=_0xb5fa('0x7e');_0x25de19[_0xb5fa('0x7f')]['online']=!![];_0x2799e7=qs[_0xb5fa('0x80')](_0x580d1a,_0x25de19);_0x2799e7[_0xb5fa('0x81')]=!![];if(_0x25de19[_0xb5fa('0x82')][_0xb5fa('0x7d')]==='user'){var _0x55000b={'params':{'id':_0x25de19['user'][_0xb5fa('0x83')]},'query':{'section':_0xb5fa('0x15'),'role':_0xb5fa('0x7e'),'online':!![],'nolimit':_0x25de19['query'][_0xb5fa('0x84')],'sort':_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x85')],'filter':_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x3e')],'raw':!![]}};return db[_0xb5fa('0x86')][_0xb5fa('0x87')](_0x55000b);}return db[_0xb5fa('0x46')][_0xb5fa('0x88')](_0x2799e7);})[_0xb5fa('0x16')](function(_0x3a1db9){_0x3ccfd1[_0xb5fa('0xb')]=_0x3a1db9[_0xb5fa('0xb')];_0x23f235=_0x3a1db9[_0xb5fa('0x89')];return getRealtimeAgents();})[_0xb5fa('0x16')](function(_0x5eeaa1){_0x42c34f=_0x5eeaa1[_0xb5fa('0x89')];return _0x23f235['map'](function(_0x47193c){var _0x209213=_[_0xb5fa('0x41')](_0x42c34f,['id',_0x47193c['id']]);if(_0x209213)_[_0xb5fa('0x19')](_0x47193c,_[_0xb5fa('0x3d')](_['omit'](_0x209213,_0x24acea),_0x10830a));_0x47193c[_0xb5fa('0x8a')]=getAgentStatus(_0x47193c);return _0x47193c;});})['then'](function(_0x77a831){if(_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x8b')]){var _0x394386=_['filter'](_0x77a831,['globalStatus',_0x25de19['query'][_0xb5fa('0x8b')]]);if(_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x8c')]){_0x394386=_[_0xb5fa('0x3e')](_0x394386,[_0xb5fa('0x5d'),_0x25de19[_0xb5fa('0x7f')]['pauseTypeFilter']]);}}_0x3ccfd1[_0xb5fa('0x89')]=_0x394386||_0x77a831;return _0x3ccfd1;})['then'](respondWithFilteredResult(_0x35cf5a,_0x2799e7))['catch'](handleError(_0x35cf5a,null));};exports[_0xb5fa('0x8d')]=function(_0x4cba86,_0x5d11bb){var _0x4e2253=[_0xb5fa('0x8e'),'chat',_0xb5fa('0x8f'),_0xb5fa('0x90'),_0xb5fa('0x91'),'whatsapp','voice'];var _0xb1fcac={'count':0x0,'rows':[]},_0x2abe24={},_0x4c70d1,_0x2d0c95,_0x3c7cb4,_0x244892,_0x2aaa2c;Promise['resolve']()[_0xb5fa('0x16')](function(){if(_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x92')]){if(!_[_0xb5fa('0x93')](_0x4e2253,_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x92')][_0xb5fa('0x94')]()))throw new Error('Invalid\x20channel');_0x4c70d1=_0x4cba86[_0xb5fa('0x7f')]['channel'][_0xb5fa('0x94')]();}var _0x45790c=_['startCase'](_0x4c70d1)+_0xb5fa('0x47');var _0x212d4e=_[_0xb5fa('0x39')](db[_0x45790c][_0xb5fa('0x95')],function(_0x3034b0){return{'name':_0x3034b0[_0xb5fa('0x7b')],'type':_0x3034b0[_0xb5fa('0x7c')][_0xb5fa('0x96')]};});_0x2abe24=qs['getOptions'](_0x212d4e,_0x4cba86);if(_0x4cba86[_0xb5fa('0x82')][_0xb5fa('0x7d')]===_0xb5fa('0x82')){var _0x20ffa1={'params':{'id':_0x4cba86['user']['userProfileId']},'query':{'section':_0x4c70d1==='voice'&&_0x4cba86['query'][_0xb5fa('0x7c')]===_0xb5fa('0x26')?_0xb5fa('0x97'):_[_0xb5fa('0x1c')](_0x4c70d1)+'Queues','type':_0x4cba86['query'][_0xb5fa('0x7c')],'nolimit':!![],'sort':'name','filter':_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x3e')]}};return db[_0xb5fa('0x86')][_0xb5fa('0x87')](_0x20ffa1);}return db[_0x45790c]['findAndCountAll'](_0x2abe24);})[_0xb5fa('0x16')](function(_0x5c6b09){_0xb1fcac[_0xb5fa('0xb')]=_0x5c6b09[_0xb5fa('0xb')];_0x2d0c95=_0x5c6b09['rows'];return getRealtimeQueues(_0x4cba86,_0x4c70d1);})['then'](function(_0x391412){_0x244892=_0x391412[_0xb5fa('0x89')];return getRealtimeAgents();})[_0xb5fa('0x16')](function(_0x1bcca7){_0x3c7cb4=_0x1bcca7[_0xb5fa('0x89')];if(_0x4c70d1!=_0xb5fa('0x1b'))return;return getRealtimeVoiceQueueChannels();})[_0xb5fa('0x16')](function(_0x25b278){_0x2aaa2c=_0x25b278?_0x25b278[_0xb5fa('0x89')]:[];return initializeQueues(_0x2d0c95,_0x244892,_0x4c70d1,_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x7c')]);})[_0xb5fa('0x16')](function(_0x86dfe9){var _0x53c7b5=_0x86dfe9['map'](function(_0x3dd9ab){if(_0x4c70d1==='voice')return getVoiceQueueAgents(_0x3dd9ab,_0x2d0c95,_0x3c7cb4,_0x2aaa2c);else return getQueueAgents(_0x3dd9ab,_0x3c7cb4,_0x4c70d1);});return Promise[_0xb5fa('0x98')](_0x53c7b5);})[_0xb5fa('0x16')](function(_0x502946){_0xb1fcac[_0xb5fa('0x89')]=_0x502946;return _0xb1fcac;})[_0xb5fa('0x16')](respondWithFilteredResult(_0x5d11bb,_0x2abe24))['catch'](handleError(_0x5d11bb,null));};
\ No newline at end of file
+var _0xfdbd=['loggedIn','voice','busy','find','pick','filter','queue','length','some','connectedlinenum','internal','toString','getMembers','UserId','accountcode','online','voiceStatus','agents','User','Queue','QueueId','idle','unknown','isNil','chatPause','faxPause','mailPause','openchannelPause','voicePause','whatsappPause','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','whatsappStatus','*pause','getAgents','userpic','lastLoginAt','lastPauseAt','pauseType','address','smsPause','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','fieldName','query','getOptions','raw','user','userProfileId','agent','nolimit','UserProfile','getResources','findAndCountAll','rows','omit','globalStatus','globalStatusFilter','pauseTypeFilter','mail','chat','sms','resolve','channel','includes','Invalid\x20channel','toLowerCase','rawAttributes','type','QueueCampaigns','all','util','lodash','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','limit','undefined','count','offset','status','set','json','error','stack','name','request','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','result','merge','catch','startCase','Queues','format','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','available','waiting','talking','outbound','push','pTalking','originated','message','dialActive','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalDroppedCallsTimeout','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','map','get','paused','loggedInDb'];(function(_0x575730,_0x1862bb){var _0x4c2e0c=function(_0x54625f){while(--_0x54625f){_0x575730['push'](_0x575730['shift']());}};_0x4c2e0c(++_0x1862bb);}(_0xfdbd,0xf0));var _0xdfdb=function(_0x2c3255,_0x4e00ae){_0x2c3255=_0x2c3255-0x0;var _0x282aba=_0xfdbd[_0x2c3255];return _0x282aba;};'use strict';var util=require(_0xdfdb('0x0'));var _=require(_0xdfdb('0x1'));var jayson=require(_0xdfdb('0x2'));var qs=require(_0xdfdb('0x3'));var logger=require(_0xdfdb('0x4'))(_0xdfdb('0x5'));var db=require(_0xdfdb('0x6'))['db'];var amiClient=jayson[_0xdfdb('0x7')][_0xdfdb('0x8')]({'port':0x232a});var routingClient=jayson['client'][_0xdfdb('0x8')]({'port':0x232c});function respondWithFilteredResult(_0x4a4a3f,_0x453ef6){return function(_0x41bd5e){if(_0x41bd5e){var _0x489f19=typeof _0x453ef6['offset']==='undefined'&&typeof _0x453ef6[_0xdfdb('0x9')]===_0xdfdb('0xa');var _0x47c629=_0x41bd5e[_0xdfdb('0xb')];var _0x444c19=_0x489f19?0x0:_0x453ef6[_0xdfdb('0xc')];var _0x27ddcd=_0x489f19?_0x41bd5e[_0xdfdb('0xb')]:_0x453ef6[_0xdfdb('0xc')]+_0x453ef6[_0xdfdb('0x9')];var _0x47dccc;if(_0x27ddcd>=_0x47c629){_0x27ddcd=_0x47c629;_0x47dccc=0xc8;}else{_0x47dccc=0xce;}_0x4a4a3f[_0xdfdb('0xd')](_0x47dccc);return _0x4a4a3f[_0xdfdb('0xe')]('Content-Range',_0x444c19+'-'+_0x27ddcd+'/'+_0x47c629)[_0xdfdb('0xf')](_0x41bd5e);}return null;};}function handleError(_0x33a706,_0x2bee3b){_0x2bee3b=_0x2bee3b||0x1f4;return function(_0x1918c1){logger[_0xdfdb('0x10')](_0x1918c1[_0xdfdb('0x11')]);if(_0x1918c1[_0xdfdb('0x12')]){delete _0x1918c1[_0xdfdb('0x12')];}_0x33a706['status'](_0x2bee3b)['send'](_0x1918c1);};}function getRealtimeAgents(){return new Promise(function(_0x2c44dc,_0x4b1ff7){return amiClient[_0xdfdb('0x13')](_0xdfdb('0x14'),{})[_0xdfdb('0x15')](function(_0x40bc8a){if(_0x40bc8a[_0xdfdb('0x10')])throw new Error(_0xdfdb('0x16'));var _0x54ff23=_0x40bc8a['result'];return routingClient[_0xdfdb('0x13')](_0xdfdb('0x14'),{})[_0xdfdb('0x15')](function(_0x55ab5a){if(_0x55ab5a[_0xdfdb('0x10')])throw new Error(_0xdfdb('0x17'));var _0x467653=_0x55ab5a[_0xdfdb('0x18')];return _0x2c44dc(_[_0xdfdb('0x19')]({},_0x54ff23,_0x467653));});})[_0xdfdb('0x1a')](function(_0x693a2c){_0x4b1ff7(_0x693a2c);});});}function getRealtimeQueues(_0x29a639,_0x5b8cb5){return new Promise(function(_0x14638a,_0xb7417c){var _0x172c63=_0x5b8cb5==='voice'?amiClient:routingClient;return _0x172c63[_0xdfdb('0x13')](_[_0xdfdb('0x1b')](_0x5b8cb5)+_0xdfdb('0x1c'),_0x29a639)['then'](function(_0x280e53){if(_0x280e53[_0xdfdb('0x10')])throw new Error(util[_0xdfdb('0x1d')]('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0x5b8cb5));return _0x14638a(_0x280e53[_0xdfdb('0x18')]);})['catch'](function(_0x2db1c1){_0xb7417c(_0x2db1c1);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x145350,_0x1fa2f3){return amiClient[_0xdfdb('0x13')]('VoiceQueuesChannels',{})[_0xdfdb('0x15')](function(_0x4363d8){if(_0x4363d8[_0xdfdb('0x10')])throw new Error(_0xdfdb('0x1e'));return _0x145350(_0x4363d8[_0xdfdb('0x18')]);})[_0xdfdb('0x1a')](function(_0x57d24f){_0x1fa2f3(_0x57d24f);});});}function initializeQueues(_0xec4d22,_0x2d5fe2,_0xdf3a5c,_0x4f8057){var _0x466932=['loggedIn',_0xdfdb('0x1f'),_0xdfdb('0x20'),_0xdfdb('0x21'),'paused'];if(_0xdf3a5c==='voice'&&_0x4f8057===_0xdfdb('0x22')){_0x466932[_0xdfdb('0x23')](_0xdfdb('0x24'),_0xdfdb('0x25'),_0xdfdb('0x26'),_0xdfdb('0x27'),'dialMethod',_0xdfdb('0x28'),_0xdfdb('0x29'),_0xdfdb('0x2a'),_0xdfdb('0x2b'),_0xdfdb('0x2c'),_0xdfdb('0x2d'),_0xdfdb('0x2e'),_0xdfdb('0x2f'),_0xdfdb('0x30'),_0xdfdb('0x31'),_0xdfdb('0x32'),'predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls',_0xdfdb('0x33'),'predictiveIntervalDroppedCallsCallersExit',_0xdfdb('0x34'),_0xdfdb('0x35'));}return _0xec4d22[_0xdfdb('0x36')](function(_0x36d91f){var _0x514232=_0x36d91f[_0xdfdb('0x37')]({'plain':!![]});_0x514232['agents']=[];_0x514232[_0xdfdb('0x38')]=0x0;_0x514232[_0xdfdb('0x39')]=0x0;_0x514232[_0xdfdb('0x3a')]=0x0;_0x514232[_0xdfdb('0x1f')]=0x0;_0x514232[_0xdfdb('0x20')]=0x0;if(_0xdf3a5c===_0xdfdb('0x3b')){_0x514232['talking']=0x0;_0x514232[_0xdfdb('0x3c')]=0x0;if(_0x4f8057===_0xdfdb('0x22')){_0x514232['pTalking']=0x0;_0x514232[_0xdfdb('0x25')]=0x0;}}var _0x4377d6=_[_0xdfdb('0x3d')](_0x2d5fe2,['id',_0x514232['id']]);if(_0x4377d6)_[_0xdfdb('0x19')](_0x514232,_[_0xdfdb('0x3e')](_0x4377d6,_0x466932));return _0x514232;});}function updateAgentVoiceStatus(_0x286fdb,_0x16d5b8,_0x1d1f4f){var _0x21f4c7=_[_0xdfdb('0x3f')](_0x1d1f4f,[_0xdfdb('0x40'),_0x16d5b8['name']]);if(_0x21f4c7[_0xdfdb('0x41')]===0x0)return _0x286fdb[_0xdfdb('0x3c')]=!![];if(_[_0xdfdb('0x42')](_0x21f4c7,[_0xdfdb('0x43'),_0x286fdb[_0xdfdb('0x44')][_0xdfdb('0x45')]()]))return _0x286fdb[_0xdfdb('0x21')]=!![];if(!_0x286fdb[_0xdfdb('0x21')])return _0x286fdb['busy']=!![];}function getVoiceQueueAgents(_0x55d707,_0x435557,_0x2146b2,_0x16e100){var _0x1e7688=_[_0xdfdb('0x3d')](_0x435557,['id',_0x55d707['id']]);if(!_0x1e7688)return _0x55d707;return _0x1e7688[_0xdfdb('0x46')]({'raw':!![]})[_0xdfdb('0x15')](function(_0x2eb46c){for(var _0xcee274=0x0;_0xcee274<_0x2eb46c['length'];_0xcee274++){var _0x175f57=_[_0xdfdb('0x3d')](_0x2146b2,['id',_0x2eb46c[_0xcee274][_0xdfdb('0x47')]]);if(!_0x175f57){_0x175f57={'id':_0x2eb46c[_0xcee274][_0xdfdb('0x47')],'name':_0x2eb46c[_0xcee274][_0xdfdb('0x47')],'accountcode':'','online':![]};}var _0x5a1bee={'id':_0x175f57['id'],'name':_0x175f57[_0xdfdb('0x12')],'internal':_0x175f57[_0xdfdb('0x48')],'online':Boolean(_0x175f57[_0xdfdb('0x49')]),'paused':Boolean(_0x2eb46c[_0xcee274][_0xdfdb('0x38')])};if(_0x175f57[_0xdfdb('0x4a')]==='talking')updateAgentVoiceStatus(_0x5a1bee,_0x55d707,_0x16e100);if(_0x5a1bee[_0xdfdb('0x49')])_0x55d707[_0xdfdb('0x39')]++;if(_0x5a1bee[_0xdfdb('0x3c')])_0x55d707['busy']++;if(_0x5a1bee[_0xdfdb('0x38')]&&!_0x5a1bee['busy']&&!_0x5a1bee[_0xdfdb('0x21')])_0x55d707['paused']++;_0x55d707[_0xdfdb('0x4b')][_0xdfdb('0x23')](_0x5a1bee);}return _0x55d707;});}function getQueueAgents(_0x5c14a1,_0xc92f82,_0x4e8ead){var _0xfea790=_0xdfdb('0x4c')+_[_0xdfdb('0x1b')](_0x4e8ead)+_0xdfdb('0x4d');var _0x25cc2f=_0x4e8ead+'Pause';return db[_0xfea790]['findAll']({'where':{[_[_0xdfdb('0x1b')](_0x4e8ead)+_0xdfdb('0x4e')]:_0x5c14a1['id']},'raw':!![]})['then'](function(_0x2b0a8b){for(var _0x59d0c3=0x0;_0x59d0c3<_0x2b0a8b[_0xdfdb('0x41')];_0x59d0c3++){var _0x158407=_[_0xdfdb('0x3d')](_0xc92f82,['id',_0x2b0a8b[_0x59d0c3][_0xdfdb('0x47')]]);if(!_0x158407){_0x158407={'id':_0x2b0a8b[_0x59d0c3][_0xdfdb('0x47')],'name':_0x2b0a8b[_0x59d0c3][_0xdfdb('0x47')],'online':![],['pauseField']:![]};}var _0x41701c={'id':_0x158407['id'],'name':_0x158407[_0xdfdb('0x12')],'online':Boolean(_0x158407[_0xdfdb('0x49')]),'paused':Boolean(_0x158407[_0x25cc2f])};if(_0x41701c[_0xdfdb('0x49')])_0x5c14a1[_0xdfdb('0x39')]++;_0x5c14a1[_0xdfdb('0x4b')][_0xdfdb('0x23')](_0x41701c);}return _0x5c14a1;});}function isIdle(_0x202c25){return _0x202c25===_0xdfdb('0x4f')||_0x202c25===_0xdfdb('0x50')||_0x202c25==='unavailable'||_0x202c25==='ringing'||_[_0xdfdb('0x51')](_0x202c25);}function isAgentPaused(_0x1aff71,_0x2f1d06){var _0x4bbb88=[_0x1aff71[_0xdfdb('0x52')],_0x1aff71[_0xdfdb('0x53')],_0x1aff71[_0xdfdb('0x54')],_0x1aff71[_0xdfdb('0x55')],_0x1aff71['smsPause'],_0x1aff71[_0xdfdb('0x56')],_0x1aff71[_0xdfdb('0x57')]];if(!_0x2f1d06)return _['every'](_0x4bbb88);var _0x3a6ce2=_[_0xdfdb('0x3f')](_0x4bbb88);return _0x3a6ce2[_0xdfdb('0x41')]>0x0&&_0x3a6ce2[_0xdfdb('0x41')]<_0x4bbb88[_0xdfdb('0x41')]?!![]:![];}function isAgentIdle(_0x10b490){if(_0x10b490[_0xdfdb('0x4a')]!==_0xdfdb('0x4f')&&_0x10b490[_0xdfdb('0x56')]){_0x10b490['voiceStatus']=_0xdfdb('0x58');return![];}return _['every']([_0x10b490[_0xdfdb('0x59')],_0x10b490[_0xdfdb('0x5a')],_0x10b490[_0xdfdb('0x5b')],_0x10b490[_0xdfdb('0x5c')],_0x10b490[_0xdfdb('0x5d')],_0x10b490[_0xdfdb('0x4a')],_0x10b490[_0xdfdb('0x5e')]],isIdle);}function getAgentStatus(_0x480e98){var _0x2a5803=_0xdfdb('0x50');if(isAgentPaused(_0x480e98))_0x2a5803=_0xdfdb('0x58');else if(isAgentPaused(_0x480e98,!![]))_0x2a5803=_0xdfdb('0x5f');else if(isAgentIdle(_0x480e98))_0x2a5803=_0xdfdb('0x4f');else _0x2a5803='busy';return _0x2a5803;}exports[_0xdfdb('0x60')]=function(_0x4df3b6,_0x9bbf0e){var _0x1331eb={'count':0x0,'rows':[]},_0xdd48cd={},_0x6d7407,_0x3f10fe,_0x5e7388=[_0xdfdb('0x61'),'online',_0xdfdb('0x62'),_0xdfdb('0x63'),_0xdfdb('0x64'),'lastPauseAt',_0xdfdb('0x44'),_0xdfdb('0x65'),_0xdfdb('0x52'),_0xdfdb('0x55'),_0xdfdb('0x54'),_0xdfdb('0x66'),'whatsappPause','faxPause',_0xdfdb('0x56'),'chatCapacity','openchannelCapacity','mailCapacity',_0xdfdb('0x67'),_0xdfdb('0x68'),_0xdfdb('0x69'),_0xdfdb('0x6a'),_0xdfdb('0x6b'),_0xdfdb('0x6c'),_0xdfdb('0x6d'),_0xdfdb('0x6e'),_0xdfdb('0x6f'),'chatStatus','openchannelStatus',_0xdfdb('0x5b'),'smsStatus',_0xdfdb('0x5e'),_0xdfdb('0x5a'),_0xdfdb('0x4a'),'chatStatusTime',_0xdfdb('0x70'),_0xdfdb('0x71'),_0xdfdb('0x72'),_0xdfdb('0x73'),_0xdfdb('0x74'),_0xdfdb('0x75'),_0xdfdb('0x40'),_0xdfdb('0x76'),'screenrecording',_0xdfdb('0x77'),_0xdfdb('0x78'),'routealias'],_0x3fbbb5=[_0xdfdb('0x52'),_0xdfdb('0x55'),_0xdfdb('0x54'),_0xdfdb('0x66'),'whatsappPause','faxPause',_0xdfdb('0x56'),_0xdfdb('0x49')];Promise['resolve']()[_0xdfdb('0x15')](function(){var _0x2b8776=_[_0xdfdb('0x36')](db['User']['rawAttributes'],function(_0x42ad97){return{'name':_0x42ad97[_0xdfdb('0x79')],'type':_0x42ad97['type']['key']};});_0x4df3b6[_0xdfdb('0x7a')]['role']='agent';_0x4df3b6[_0xdfdb('0x7a')]['online']=!![];_0xdd48cd=qs[_0xdfdb('0x7b')](_0x2b8776,_0x4df3b6);_0xdd48cd[_0xdfdb('0x7c')]=!![];if(_0x4df3b6['user']['role']===_0xdfdb('0x7d')){var _0x2a218a={'params':{'id':_0x4df3b6['user'][_0xdfdb('0x7e')]},'query':{'section':_0xdfdb('0x14'),'role':_0xdfdb('0x7f'),'online':!![],'nolimit':_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x80')],'sort':_0x4df3b6['query']['sort'],'filter':_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x3f')],'raw':!![]}};return db[_0xdfdb('0x81')][_0xdfdb('0x82')](_0x2a218a);}return db[_0xdfdb('0x4c')][_0xdfdb('0x83')](_0xdd48cd);})['then'](function(_0xd226af){_0x1331eb[_0xdfdb('0xb')]=_0xd226af[_0xdfdb('0xb')];_0x6d7407=_0xd226af[_0xdfdb('0x84')];return getRealtimeAgents();})[_0xdfdb('0x15')](function(_0x1bcfdd){_0x3f10fe=_0x1bcfdd[_0xdfdb('0x84')];return _0x6d7407[_0xdfdb('0x36')](function(_0x38fa9c){var _0x3eca7f=_['find'](_0x3f10fe,['id',_0x38fa9c['id']]);if(_0x3eca7f)_[_0xdfdb('0x19')](_0x38fa9c,_[_0xdfdb('0x3e')](_[_0xdfdb('0x85')](_0x3eca7f,_0x3fbbb5),_0x5e7388));_0x38fa9c[_0xdfdb('0x86')]=getAgentStatus(_0x38fa9c);return _0x38fa9c;});})[_0xdfdb('0x15')](function(_0x590a16){if(_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x87')]){var _0x234882=_[_0xdfdb('0x3f')](_0x590a16,['globalStatus',_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x87')]]);if(_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x88')]){_0x234882=_[_0xdfdb('0x3f')](_0x234882,[_0xdfdb('0x64'),_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x88')]]);}}_0x1331eb[_0xdfdb('0x84')]=_0x234882||_0x590a16;return _0x1331eb;})[_0xdfdb('0x15')](respondWithFilteredResult(_0x9bbf0e,_0xdd48cd))[_0xdfdb('0x1a')](handleError(_0x9bbf0e,null));};exports['getQueues']=function(_0x1bf0d2,_0x616d29){var _0x5ad38a=[_0xdfdb('0x89'),_0xdfdb('0x8a'),_0xdfdb('0x8b'),'openchannel','fax','whatsapp',_0xdfdb('0x3b')];var _0x465565={'count':0x0,'rows':[]},_0x1c7964={},_0x8e68a8,_0xd4b817,_0x394536,_0xf60176,_0x4b2c31;Promise[_0xdfdb('0x8c')]()[_0xdfdb('0x15')](function(){if(_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x8d')]){if(!_[_0xdfdb('0x8e')](_0x5ad38a,_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x8d')]['toLowerCase']()))throw new Error(_0xdfdb('0x8f'));_0x8e68a8=_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x8d')][_0xdfdb('0x90')]();}var _0x275e5f=_['startCase'](_0x8e68a8)+_0xdfdb('0x4d');var _0x56a633=_[_0xdfdb('0x36')](db[_0x275e5f][_0xdfdb('0x91')],function(_0x18c6d1){return{'name':_0x18c6d1[_0xdfdb('0x79')],'type':_0x18c6d1[_0xdfdb('0x92')]['key']};});_0x1c7964=qs[_0xdfdb('0x7b')](_0x56a633,_0x1bf0d2);if(_0x1bf0d2[_0xdfdb('0x7d')]['role']==='user'){var _0x284439={'params':{'id':_0x1bf0d2['user']['userProfileId']},'query':{'section':_0x8e68a8===_0xdfdb('0x3b')&&_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x92')]===_0xdfdb('0x22')?_0xdfdb('0x93'):_[_0xdfdb('0x1b')](_0x8e68a8)+_0xdfdb('0x1c'),'type':_0x1bf0d2[_0xdfdb('0x7a')]['type'],'nolimit':!![],'sort':_0xdfdb('0x12'),'filter':_0x1bf0d2['query'][_0xdfdb('0x3f')]}};return db[_0xdfdb('0x81')][_0xdfdb('0x82')](_0x284439);}return db[_0x275e5f][_0xdfdb('0x83')](_0x1c7964);})[_0xdfdb('0x15')](function(_0x52a8a5){_0x465565[_0xdfdb('0xb')]=_0x52a8a5[_0xdfdb('0xb')];_0xd4b817=_0x52a8a5[_0xdfdb('0x84')];return getRealtimeQueues(_0x1bf0d2,_0x8e68a8);})[_0xdfdb('0x15')](function(_0x36241c){_0xf60176=_0x36241c['rows'];return getRealtimeAgents();})['then'](function(_0x231f20){_0x394536=_0x231f20[_0xdfdb('0x84')];if(_0x8e68a8!='voice')return;return getRealtimeVoiceQueueChannels();})[_0xdfdb('0x15')](function(_0x50d5d4){_0x4b2c31=_0x50d5d4?_0x50d5d4[_0xdfdb('0x84')]:[];return initializeQueues(_0xd4b817,_0xf60176,_0x8e68a8,_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x92')]);})['then'](function(_0x2828a5){var _0x53ca83=_0x2828a5['map'](function(_0x3eb36e){if(_0x8e68a8==='voice')return getVoiceQueueAgents(_0x3eb36e,_0xd4b817,_0x394536,_0x4b2c31);else return getQueueAgents(_0x3eb36e,_0x394536,_0x8e68a8);});return Promise[_0xdfdb('0x94')](_0x53ca83);})[_0xdfdb('0x15')](function(_0x162eeb){_0x465565[_0xdfdb('0x84')]=_0x162eeb;return _0x465565;})[_0xdfdb('0x15')](respondWithFilteredResult(_0x616d29,_0x1c7964))[_0xdfdb('0x1a')](handleError(_0x616d29,null));};
\ No newline at end of file