209ea6c50021df455059e8470e9c3f86cc30a19e
[motion2.git] / server / api / realtime / realtime.controller.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 _0xb7fe=['pTalking','originated','message','dialMethod','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','map','get','agents','busy','outbound','find','filter','length','some','UserId','online','paused','voiceStatus','loggedInDb','User','Queue','Pause','findAll','QueueId','idle','unknown','unavailable','ringing','smsPause','voicePause','whatsappPause','every','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','whatsappStatus','*pause','mail','chat','sms','openchannel','whatsapp','toLowerCase','isArray','findOne','getAgents','uniq','value','fields','includes','globalStatus','order','startsWith','ASC','sort','DESC','pauseType','lastLoginAt','lastPauseAt','internal','address','openchannelPause','mailPause','faxPause','openchannelCapacity','mailCapacity','smsCapacity','faxCapacity','openchannelCurrentCapacity','smsCurrentCapacity','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','queue','destconnectedlinenum','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','chatPause','resolve','channel','query','join','globalQueueFilter','type','key','role','agent','getOptions','raw','isEmpty','where','user','userProfileId','nolimit','getResources','findAndCountAll','rows','omit','globalStatusFilter','pauseTypeFilter','fieldName','UserProfile','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','http','client','offset','limit','count','status','set','Content-Range','name','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','request','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','catch','voice','startCase','Queues','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','available','waiting','talking','push'];(function(_0x258e8e,_0x1a81f4){var _0x427d2b=function(_0x3b6c82){while(--_0x3b6c82){_0x258e8e['push'](_0x258e8e['shift']());}};_0x427d2b(++_0x1a81f4);}(_0xb7fe,0x1b3));var _0xeb7f=function(_0x4195c2,_0x57e3b8){_0x4195c2=_0x4195c2-0x0;var _0x273062=_0xb7fe[_0x4195c2];return _0x273062;};'use strict';var util=require('util');var _=require('lodash');var jayson=require(_0xeb7f('0x0'));var qs=require(_0xeb7f('0x1'));var logger=require(_0xeb7f('0x2'))(_0xeb7f('0x3'));var db=require(_0xeb7f('0x4'))['db'];var amiClient=jayson['client'][_0xeb7f('0x5')]({'port':0x232a});var routingClient=jayson[_0xeb7f('0x6')][_0xeb7f('0x5')]({'port':0x232c});function respondWithFilteredResult(_0x43cc7e,_0x5d1782){return function(_0x1edc5b){if(_0x1edc5b){var _0x292ad3=typeof _0x5d1782[_0xeb7f('0x7')]==='undefined'&&typeof _0x5d1782[_0xeb7f('0x8')]==='undefined';var _0x2ea8b1=_0x1edc5b['count'];var _0x42f014=_0x292ad3?0x0:_0x5d1782[_0xeb7f('0x7')];var _0x48380f=_0x292ad3?_0x1edc5b[_0xeb7f('0x9')]:_0x5d1782['offset']+_0x5d1782[_0xeb7f('0x8')];var _0x567f0c;if(_0x48380f>=_0x2ea8b1){_0x48380f=_0x2ea8b1;_0x567f0c=0xc8;}else{_0x567f0c=0xce;}_0x43cc7e[_0xeb7f('0xa')](_0x567f0c);return _0x43cc7e[_0xeb7f('0xb')](_0xeb7f('0xc'),_0x42f014+'-'+_0x48380f+'/'+_0x2ea8b1)['json'](_0x1edc5b);}return null;};}function handleError(_0x4a6e1c,_0xaa31f8){_0xaa31f8=_0xaa31f8||0x1f4;return function(_0x335240){logger['error'](_0x335240['stack']);if(_0x335240[_0xeb7f('0xd')]){delete _0x335240[_0xeb7f('0xd')];}_0x4a6e1c[_0xeb7f('0xa')](_0xaa31f8)['send'](_0x335240);};}function getRealtimeAgents(){return new Promise(function(_0x130bd8,_0x106dd0){return amiClient['request'](_0xeb7f('0xe'),{})[_0xeb7f('0xf')](function(_0x4b2bb1){if(_0x4b2bb1['error'])throw new Error(_0xeb7f('0x10'));var _0x459c92=_0x4b2bb1[_0xeb7f('0x11')];return routingClient[_0xeb7f('0x12')](_0xeb7f('0xe'),{})[_0xeb7f('0xf')](function(_0x560527){if(_0x560527[_0xeb7f('0x13')])throw new Error(_0xeb7f('0x14'));var _0x1f6615=_0x560527[_0xeb7f('0x11')];return _0x130bd8(_[_0xeb7f('0x15')]({},_0x459c92,_0x1f6615));});})[_0xeb7f('0x16')](function(_0x37ed5d){_0x106dd0(_0x37ed5d);});});}function getRealtimeQueues(_0x3dbde3,_0x387b1a){return new Promise(function(_0x7eff63,_0x2cfe58){var _0x5afee0=_0x387b1a===_0xeb7f('0x17')?amiClient:routingClient;return _0x5afee0['request'](_[_0xeb7f('0x18')](_0x387b1a)+_0xeb7f('0x19'),_0x3dbde3)['then'](function(_0x31888f){if(_0x31888f[_0xeb7f('0x13')])throw new Error(util['format']('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0x387b1a));return _0x7eff63(_0x31888f[_0xeb7f('0x11')]);})[_0xeb7f('0x16')](function(_0x15e2b6){_0x2cfe58(_0x15e2b6);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x17da39,_0x122ede){return amiClient[_0xeb7f('0x12')](_0xeb7f('0x1a'),{})[_0xeb7f('0xf')](function(_0xff4675){if(_0xff4675['error'])throw new Error(_0xeb7f('0x1b'));return _0x17da39(_0xff4675[_0xeb7f('0x11')]);})[_0xeb7f('0x16')](function(_0x10bc08){_0x122ede(_0x10bc08);});});}function initializeQueues(_0x33b773,_0xc972c2,_0x186137,_0x405cc7){var _0x205a9f=[_0xeb7f('0x1c'),_0xeb7f('0x1d'),_0xeb7f('0x1e'),_0xeb7f('0x1f'),'paused'];if(_0x186137===_0xeb7f('0x17')&&_0x405cc7==='outbound'){_0x205a9f[_0xeb7f('0x20')](_0xeb7f('0x21'),_0xeb7f('0x22'),_0xeb7f('0x23'),'dialActive',_0xeb7f('0x24'),_0xeb7f('0x25'),_0xeb7f('0x26'),_0xeb7f('0x27'),_0xeb7f('0x28'),_0xeb7f('0x29'),_0xeb7f('0x2a'),_0xeb7f('0x2b'),_0xeb7f('0x2c'),_0xeb7f('0x2d'),'dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable',_0xeb7f('0x2e'),_0xeb7f('0x2f'),'predictiveIntervalDroppedCallsTimeout',_0xeb7f('0x30'),_0xeb7f('0x31'),_0xeb7f('0x32'));}return _0x33b773[_0xeb7f('0x33')](function(_0x449ef7){var _0x4cc2d=_0x449ef7[_0xeb7f('0x34')]({'plain':!![]});_0x4cc2d[_0xeb7f('0x35')]=[];_0x4cc2d['paused']=0x0;_0x4cc2d['loggedInDb']=0x0;_0x4cc2d[_0xeb7f('0x1c')]=0x0;_0x4cc2d['available']=0x0;_0x4cc2d['waiting']=0x0;if(_0x186137===_0xeb7f('0x17')){_0x4cc2d[_0xeb7f('0x1f')]=0x0;_0x4cc2d[_0xeb7f('0x36')]=0x0;if(_0x405cc7===_0xeb7f('0x37')){_0x4cc2d[_0xeb7f('0x21')]=0x0;_0x4cc2d[_0xeb7f('0x22')]=0x0;}}var _0x229674=_[_0xeb7f('0x38')](_0xc972c2,['id',_0x4cc2d['id']]);if(_0x229674)_[_0xeb7f('0x15')](_0x4cc2d,_['pick'](_0x229674,_0x205a9f));return _0x4cc2d;});}function updateAgentVoiceStatus(_0x19ae1a,_0x12fd62,_0x381a1f){var _0x538892=_[_0xeb7f('0x39')](_0x381a1f,['queue',_0x12fd62[_0xeb7f('0xd')]]);if(_0x538892[_0xeb7f('0x3a')]===0x0)return _0x19ae1a[_0xeb7f('0x36')]=!![];if(_[_0xeb7f('0x3b')](_0x538892,['connectedlinenum',_0x19ae1a['internal']['toString']()]))return _0x19ae1a['talking']=!![];if(!_0x19ae1a[_0xeb7f('0x1f')])return _0x19ae1a[_0xeb7f('0x36')]=!![];}function getVoiceQueueAgents(_0x17cdce,_0x4ae753,_0x3c2032,_0x44e69b){var _0x433cd2=_[_0xeb7f('0x38')](_0x4ae753,['id',_0x17cdce['id']]);if(!_0x433cd2)return _0x17cdce;return _0x433cd2['getMembers']({'raw':!![]})[_0xeb7f('0xf')](function(_0x12dec3){for(var _0x177a93=0x0;_0x177a93<_0x12dec3['length'];_0x177a93++){var _0x3b9bfc=_[_0xeb7f('0x38')](_0x3c2032,['id',_0x12dec3[_0x177a93]['UserId']]);if(!_0x3b9bfc){_0x3b9bfc={'id':_0x12dec3[_0x177a93][_0xeb7f('0x3c')],'name':_0x12dec3[_0x177a93][_0xeb7f('0x3c')],'accountcode':'','online':![]};}var _0x3a8a54={'id':_0x3b9bfc['id'],'name':_0x3b9bfc[_0xeb7f('0xd')],'internal':_0x3b9bfc['accountcode'],'online':Boolean(_0x3b9bfc[_0xeb7f('0x3d')]),'paused':Boolean(_0x12dec3[_0x177a93][_0xeb7f('0x3e')])};if(_0x3b9bfc[_0xeb7f('0x3f')]===_0xeb7f('0x1f'))updateAgentVoiceStatus(_0x3a8a54,_0x17cdce,_0x44e69b);if(_0x3a8a54['online'])_0x17cdce[_0xeb7f('0x40')]++;if(_0x3a8a54[_0xeb7f('0x36')])_0x17cdce[_0xeb7f('0x36')]++;if(_0x3a8a54[_0xeb7f('0x3e')]&&!_0x3a8a54[_0xeb7f('0x36')]&&!_0x3a8a54[_0xeb7f('0x1f')])_0x17cdce[_0xeb7f('0x3e')]++;_0x17cdce['agents'][_0xeb7f('0x20')](_0x3a8a54);}return _0x17cdce;});}function getQueueAgents(_0x22962d,_0x3a7a6f,_0x36fa7f){var _0x1e5106=_0xeb7f('0x41')+_[_0xeb7f('0x18')](_0x36fa7f)+_0xeb7f('0x42');var _0x597a90=_0x36fa7f+_0xeb7f('0x43');return db[_0x1e5106][_0xeb7f('0x44')]({'where':{[_['startCase'](_0x36fa7f)+_0xeb7f('0x45')]:_0x22962d['id']},'raw':!![]})['then'](function(_0x5b7e86){for(var _0x28718b=0x0;_0x28718b<_0x5b7e86[_0xeb7f('0x3a')];_0x28718b++){var _0x4f2d47=_['find'](_0x3a7a6f,['id',_0x5b7e86[_0x28718b][_0xeb7f('0x3c')]]);if(!_0x4f2d47){_0x4f2d47={'id':_0x5b7e86[_0x28718b][_0xeb7f('0x3c')],'name':_0x5b7e86[_0x28718b]['UserId'],'online':![],['pauseField']:![]};}var _0x3de6ba={'id':_0x4f2d47['id'],'name':_0x4f2d47[_0xeb7f('0xd')],'online':Boolean(_0x4f2d47[_0xeb7f('0x3d')]),'paused':Boolean(_0x4f2d47[_0x597a90])};if(_0x3de6ba[_0xeb7f('0x3d')])_0x22962d[_0xeb7f('0x40')]++;_0x22962d[_0xeb7f('0x35')][_0xeb7f('0x20')](_0x3de6ba);}return _0x22962d;});}function isIdle(_0x329cd4){return _0x329cd4===_0xeb7f('0x46')||_0x329cd4===_0xeb7f('0x47')||_0x329cd4===_0xeb7f('0x48')||_0x329cd4===_0xeb7f('0x49')||_['isNil'](_0x329cd4);}function isAgentPaused(_0x2098a2,_0x4b0fdf){var _0x23c27a=[_0x2098a2['chatPause'],_0x2098a2['faxPause'],_0x2098a2['mailPause'],_0x2098a2['openchannelPause'],_0x2098a2[_0xeb7f('0x4a')],_0x2098a2[_0xeb7f('0x4b')],_0x2098a2[_0xeb7f('0x4c')]];if(!_0x4b0fdf)return _[_0xeb7f('0x4d')](_0x23c27a);var _0x285599=_[_0xeb7f('0x39')](_0x23c27a);return _0x285599[_0xeb7f('0x3a')]>0x0&&_0x285599[_0xeb7f('0x3a')]<_0x23c27a[_0xeb7f('0x3a')]?!![]:![];}function isAgentIdle(_0x702515){if(_0x702515[_0xeb7f('0x3f')]!==_0xeb7f('0x46')&&_0x702515[_0xeb7f('0x4b')]){_0x702515[_0xeb7f('0x3f')]=_0xeb7f('0x4e');return![];}return _[_0xeb7f('0x4d')]([_0x702515[_0xeb7f('0x4f')],_0x702515[_0xeb7f('0x50')],_0x702515[_0xeb7f('0x51')],_0x702515[_0xeb7f('0x52')],_0x702515[_0xeb7f('0x53')],_0x702515[_0xeb7f('0x3f')],_0x702515[_0xeb7f('0x54')]],isIdle);}function getAgentStatus(_0x55d260){var _0x2c4188='unknown';if(isAgentPaused(_0x55d260))_0x2c4188='pause';else if(isAgentPaused(_0x55d260,!![]))_0x2c4188=_0xeb7f('0x55');else if(isAgentIdle(_0x55d260))_0x2c4188='idle';else _0x2c4188=_0xeb7f('0x36');return _0x2c4188;}function validateChannel(_0x5bce9d){var _0x163375=[_0xeb7f('0x56'),_0xeb7f('0x57'),_0xeb7f('0x58'),_0xeb7f('0x59'),'fax',_0xeb7f('0x5a'),_0xeb7f('0x17')];if(!_['includes'](_0x163375,_0x5bce9d[_0xeb7f('0x5b')]()))throw new Error('Invalid\x20channel');return _0x5bce9d[_0xeb7f('0x5b')]();}function getFilteredAgentIds(_0x163de3,_0x27945e){var _0x98033d=_[_0xeb7f('0x5c')](_0x163de3)?_0x163de3:[_0x163de3];var _0x1629ce=_[_0xeb7f('0x33')](_0x98033d,function(_0x13f7c3){return db[_0x27945e][_0xeb7f('0x5d')]({'where':{'name':_0x13f7c3}})[_0xeb7f('0xf')](function(_0x1eb5bb){if(!_0x1eb5bb)return[];return _0x1eb5bb[_0xeb7f('0x5e')]({'attributes':['id'],'raw':!![]});});});return Promise['all'](_0x1629ce)[_0xeb7f('0xf')](function(_0xd9cac9){var _0x324270=_(_0xd9cac9)['flatten']()[_0xeb7f('0x33')]('id')[_0xeb7f('0x5f')]()[_0xeb7f('0x60')]();return _0x324270;});}function getUpdatedSortOptions(_0x491540){var _0x44c245={'fields':[],'order':null};var _0x1a1866=_0x491540['split'](',');_0x44c245[_0xeb7f('0x61')]=_[_0xeb7f('0x39')](_0x1a1866,function(_0x3d6a04){if(!_0x3d6a04[_0xeb7f('0x62')](_0xeb7f('0x63')))return!![];_0x44c245[_0xeb7f('0x64')]=_[_0xeb7f('0x65')](_0x3d6a04,'-')?'DESC':_0xeb7f('0x66');return![];});return _0x44c245;}function orderAgentsByStatus(_0x333b75,_0x4e48e9){return _0x333b75[_0xeb7f('0x67')](function(_0x162ba4,_0x22444f){if(_0x162ba4['globalStatus']===_0x22444f[_0xeb7f('0x63')]&&_0x162ba4[_0xeb7f('0x63')]===_0xeb7f('0x4e')){if(_0x4e48e9===_0xeb7f('0x68'))return(_0x162ba4[_0xeb7f('0x69')]||'')<(_0x22444f[_0xeb7f('0x69')]||'')?0x1:-0x1;return _0x162ba4['pauseType']<_0x22444f[_0xeb7f('0x69')]?-0x1:0x1;}else{if(_0x4e48e9===_0xeb7f('0x68'))return _0x162ba4[_0xeb7f('0x63')]<_0x22444f[_0xeb7f('0x63')]?0x1:-0x1;return _0x162ba4[_0xeb7f('0x63')]<_0x22444f['globalStatus']?-0x1:0x1;}});}exports['getAgents']=function(_0x2ec060,_0x36c8d1){var _0x5efe47={'count':0x0,'rows':[]},_0x235433={},_0x32d411,_0x5afe1e,_0x44b4c0,_0x186a8d,_0x1c7af6=['userpic',_0xeb7f('0x3d'),_0xeb7f('0x6a'),_0xeb7f('0x6b'),_0xeb7f('0x69'),_0xeb7f('0x6b'),_0xeb7f('0x6c'),_0xeb7f('0x6d'),'chatPause',_0xeb7f('0x6e'),_0xeb7f('0x6f'),_0xeb7f('0x4a'),_0xeb7f('0x4c'),_0xeb7f('0x70'),_0xeb7f('0x4b'),'chatCapacity',_0xeb7f('0x71'),_0xeb7f('0x72'),_0xeb7f('0x73'),'whatsappCapacity',_0xeb7f('0x74'),'chatCurrentCapacity',_0xeb7f('0x75'),'mailCurrentCapacity',_0xeb7f('0x76'),'whatsappCurrentCapacity','faxCurrentCapacity',_0xeb7f('0x4f'),'openchannelStatus',_0xeb7f('0x51'),'smsStatus',_0xeb7f('0x54'),_0xeb7f('0x50'),_0xeb7f('0x3f'),_0xeb7f('0x77'),_0xeb7f('0x78'),_0xeb7f('0x79'),_0xeb7f('0x7a'),_0xeb7f('0x7b'),_0xeb7f('0x7c'),_0xeb7f('0x7d'),_0xeb7f('0x7e'),_0xeb7f('0x7f'),'screenrecording',_0xeb7f('0x80'),_0xeb7f('0x81'),_0xeb7f('0x82')],_0x38ea2c=[_0xeb7f('0x83'),_0xeb7f('0x6e'),'mailPause',_0xeb7f('0x4a'),'whatsappPause',_0xeb7f('0x70'),'voicePause','online'];Promise[_0xeb7f('0x84')]()[_0xeb7f('0xf')](function(){if(_0x2ec060['query'][_0xeb7f('0x85')])_0x32d411=validateChannel(_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x85')]);if(!_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x67')]||!_0x2ec060[_0xeb7f('0x86')]['sort'][_0xeb7f('0x62')](_0xeb7f('0x63')))return;var _0x2e5356=getUpdatedSortOptions(_0x2ec060['query'][_0xeb7f('0x67')]);_0x2ec060[_0xeb7f('0x86')]['sort']=_0x2e5356['fields'][_0xeb7f('0x87')](',');_0x5afe1e=_0x2e5356[_0xeb7f('0x64')];})[_0xeb7f('0xf')](function(){if(!_0x2ec060['query'][_0xeb7f('0x88')])return[];var _0x4b5868=_['startCase'](_0x32d411)+'Queue';return getFilteredAgentIds(_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x88')],_0x4b5868);})['then'](function(_0x11e7a2){var _0x176ca7=_['map'](db['User']['rawAttributes'],function(_0x312a44){return{'name':_0x312a44['fieldName'],'type':_0x312a44[_0xeb7f('0x89')][_0xeb7f('0x8a')]};});_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x8b')]=_0xeb7f('0x8c');_0x2ec060[_0xeb7f('0x86')]['online']=!![];_0x235433=qs[_0xeb7f('0x8d')](_0x176ca7,_0x2ec060);_0x235433[_0xeb7f('0x8e')]=!![];if(!_[_0xeb7f('0x8f')](_0x11e7a2)){_0x235433[_0xeb7f('0x90')]=_[_0xeb7f('0x15')](_0x235433['where'],{'$and':[{'id':{'$in':_0x11e7a2}}]});}else if(!_[_0xeb7f('0x8f')](_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x88')])){return _0x5efe47;}if(_0x2ec060['user'][_0xeb7f('0x8b')]===_0xeb7f('0x91')){var _0x455feb={'params':{'id':_0x2ec060[_0xeb7f('0x91')][_0xeb7f('0x92')]},'query':{'section':_0xeb7f('0xe'),'role':_0xeb7f('0x8c'),'online':!![],'nolimit':_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x93')],'sort':_0x2ec060[_0xeb7f('0x86')]['sort'],'filter':_0x2ec060[_0xeb7f('0x86')]['filter'],'raw':!![],'ids':_0x11e7a2}};return db['UserProfile'][_0xeb7f('0x94')](_0x455feb);}return db[_0xeb7f('0x41')][_0xeb7f('0x95')](_0x235433);})[_0xeb7f('0xf')](function(_0x175a42){_0x5efe47[_0xeb7f('0x9')]=_0x175a42[_0xeb7f('0x9')];_0x44b4c0=_0x175a42[_0xeb7f('0x96')];return getRealtimeAgents();})[_0xeb7f('0xf')](function(_0x3a6f81){_0x186a8d=_0x3a6f81[_0xeb7f('0x96')];return _0x44b4c0['map'](function(_0x34a400){var _0x304e10=_['find'](_0x186a8d,['id',_0x34a400['id']]);if(_0x304e10)_[_0xeb7f('0x15')](_0x34a400,_['pick'](_[_0xeb7f('0x97')](_0x304e10,_0x38ea2c),_0x1c7af6));_0x34a400[_0xeb7f('0x63')]=getAgentStatus(_0x34a400);return _0x34a400;});})['then'](function(_0x528dec){var _0x4d161d;if(_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x98')]){_0x4d161d=_[_0xeb7f('0x39')](_0x528dec,[_0xeb7f('0x63'),_0x2ec060[_0xeb7f('0x86')]['globalStatusFilter']]);if(_0x2ec060[_0xeb7f('0x86')][_0xeb7f('0x99')]){_0x4d161d=_[_0xeb7f('0x39')](_0x4d161d,[_0xeb7f('0x69'),_0x2ec060['query'][_0xeb7f('0x99')]]);}}if(_0x4d161d)_0x528dec=_0x4d161d;if(!_0x5afe1e)return _0x528dec;return orderAgentsByStatus(_0x528dec,_0x5afe1e);})[_0xeb7f('0xf')](function(_0x269da5){_0x5efe47[_0xeb7f('0x96')]=_0x269da5;return _0x5efe47;})['then'](respondWithFilteredResult(_0x36c8d1,_0x235433))[_0xeb7f('0x16')](handleError(_0x36c8d1,null));};exports['getQueues']=function(_0x53d1df,_0x3527aa){var _0x2d3ff9={'count':0x0,'rows':[]},_0x1abd66={},_0x69809f,_0x548956,_0x42de00,_0x44787c,_0xb2c8aa;Promise['resolve']()[_0xeb7f('0xf')](function(){if(_0x53d1df[_0xeb7f('0x86')][_0xeb7f('0x85')])_0x69809f=validateChannel(_0x53d1df[_0xeb7f('0x86')]['channel']);var _0x248297=_['startCase'](_0x69809f)+_0xeb7f('0x42');var _0xe244c1=_[_0xeb7f('0x33')](db[_0x248297]['rawAttributes'],function(_0x3c924d){return{'name':_0x3c924d[_0xeb7f('0x9a')],'type':_0x3c924d[_0xeb7f('0x89')][_0xeb7f('0x8a')]};});_0x1abd66=qs[_0xeb7f('0x8d')](_0xe244c1,_0x53d1df);if(_0x53d1df[_0xeb7f('0x91')][_0xeb7f('0x8b')]===_0xeb7f('0x91')){var _0x259dd6={'params':{'id':_0x53d1df[_0xeb7f('0x91')][_0xeb7f('0x92')]},'query':{'section':_0x69809f===_0xeb7f('0x17')&&_0x53d1df[_0xeb7f('0x86')]['type']===_0xeb7f('0x37')?'QueueCampaigns':_['startCase'](_0x69809f)+_0xeb7f('0x19'),'type':_0x53d1df[_0xeb7f('0x86')][_0xeb7f('0x89')],'nolimit':!![],'sort':'name','filter':_0x53d1df['query']['filter']}};return db[_0xeb7f('0x9b')][_0xeb7f('0x94')](_0x259dd6);}return db[_0x248297][_0xeb7f('0x95')](_0x1abd66);})[_0xeb7f('0xf')](function(_0x465103){_0x2d3ff9[_0xeb7f('0x9')]=_0x465103['count'];_0x548956=_0x465103[_0xeb7f('0x96')];return getRealtimeQueues(_0x53d1df,_0x69809f);})[_0xeb7f('0xf')](function(_0x80440d){_0x44787c=_0x80440d['rows'];return getRealtimeAgents();})[_0xeb7f('0xf')](function(_0x4ff9f1){_0x42de00=_0x4ff9f1[_0xeb7f('0x96')];if(_0x69809f!=_0xeb7f('0x17'))return;return getRealtimeVoiceQueueChannels();})[_0xeb7f('0xf')](function(_0x34d4b5){_0xb2c8aa=_0x34d4b5?_0x34d4b5[_0xeb7f('0x96')]:[];return initializeQueues(_0x548956,_0x44787c,_0x69809f,_0x53d1df['query']['type']);})[_0xeb7f('0xf')](function(_0x1fcc0d){var _0x381a81=_0x1fcc0d[_0xeb7f('0x33')](function(_0x41e306){if(_0x69809f==='voice')return getVoiceQueueAgents(_0x41e306,_0x548956,_0x42de00,_0xb2c8aa);else return getQueueAgents(_0x41e306,_0x42de00,_0x69809f);});return Promise['all'](_0x381a81);})[_0xeb7f('0xf')](function(_0x1a0d69){_0x2d3ff9[_0xeb7f('0x96')]=_0x1a0d69;return _0x2d3ff9;})[_0xeb7f('0xf')](respondWithFilteredResult(_0x3527aa,_0x1abd66))[_0xeb7f('0x16')](handleError(_0x3527aa,null));};