Built motion from commit 85328c08.|2.5.50
[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 _0xfaff=['chatCapacity','mailCapacity','faxCapacity','faxCurrentCapacity','smsStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','queue','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','resolve','channel','query','globalQueueFilter','fieldName','type','key','role','agent','isEmpty','where','user','userProfileId','nolimit','UserProfile','findAndCountAll','rows','omit','globalStatusFilter','pauseTypeFilter','rawAttributes','getOptions','QueueCampaigns','util','lodash','jayson/promise','../../config/logger','api','../../mysqldb','client','http','offset','limit','undefined','count','status','Content-Range','json','error','stack','name','send','request','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','Agents','merge','catch','voice','startCase','Queues','format','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','VoiceQueuesChannels','loggedIn','available','paused','push','pTalking','originated','message','dialActive','dialMethod','Trunk','startProgressive','erlangCalls','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','map','get','loggedInDb','waiting','talking','outbound','find','pick','filter','length','busy','some','connectedlinenum','getMembers','UserId','accountcode','online','agents','User','Queue','Pause','findAll','QueueId','unknown','ringing','isNil','chatPause','mailPause','openchannelPause','smsPause','voicePause','every','voiceStatus','idle','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','whatsappStatus','*pause','mail','chat','sms','openchannel','fax','whatsapp','includes','toLowerCase','isArray','findOne','all','flatten','uniq','fields','globalStatus','order','startsWith','DESC','ASC','sort','getAgents','userpic','lastLoginAt','pauseType','lastPauseAt','whatsappPause','faxPause'];(function(_0x394739,_0x19ce1e){var _0x48d11e=function(_0x570c40){while(--_0x570c40){_0x394739['push'](_0x394739['shift']());}};_0x48d11e(++_0x19ce1e);}(_0xfaff,0x173));var _0xffaf=function(_0xd180a1,_0x4f4ca1){_0xd180a1=_0xd180a1-0x0;var _0x349c05=_0xfaff[_0xd180a1];return _0x349c05;};'use strict';var util=require(_0xffaf('0x0'));var _=require(_0xffaf('0x1'));var jayson=require(_0xffaf('0x2'));var qs=require('../../components/parsers/qs');var logger=require(_0xffaf('0x3'))(_0xffaf('0x4'));var db=require(_0xffaf('0x5'))['db'];var amiClient=jayson[_0xffaf('0x6')]['http']({'port':0x232a});var routingClient=jayson[_0xffaf('0x6')][_0xffaf('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x43e774,_0x5662d1){return function(_0x55a923){if(_0x55a923){var _0x2cf7ae=typeof _0x5662d1[_0xffaf('0x8')]==='undefined'&&typeof _0x5662d1[_0xffaf('0x9')]===_0xffaf('0xa');var _0x2657a1=_0x55a923[_0xffaf('0xb')];var _0x36d787=_0x2cf7ae?0x0:_0x5662d1['offset'];var _0x4a9ab3=_0x2cf7ae?_0x55a923[_0xffaf('0xb')]:_0x5662d1[_0xffaf('0x8')]+_0x5662d1['limit'];var _0x361e50;if(_0x4a9ab3>=_0x2657a1){_0x4a9ab3=_0x2657a1;_0x361e50=0xc8;}else{_0x361e50=0xce;}_0x43e774[_0xffaf('0xc')](_0x361e50);return _0x43e774['set'](_0xffaf('0xd'),_0x36d787+'-'+_0x4a9ab3+'/'+_0x2657a1)[_0xffaf('0xe')](_0x55a923);}return null;};}function handleError(_0x13c67c,_0x3b2876){_0x3b2876=_0x3b2876||0x1f4;return function(_0x4ccc80){logger[_0xffaf('0xf')](_0x4ccc80[_0xffaf('0x10')]);if(_0x4ccc80['name']){delete _0x4ccc80[_0xffaf('0x11')];}_0x13c67c[_0xffaf('0xc')](_0x3b2876)[_0xffaf('0x12')](_0x4ccc80);};}function getRealtimeAgents(){return new Promise(function(_0x4cb300,_0x1a149a){return amiClient[_0xffaf('0x13')]('Agents',{})[_0xffaf('0x14')](function(_0x23b8da){if(_0x23b8da[_0xffaf('0xf')])throw new Error(_0xffaf('0x15'));var _0x15ee9e=_0x23b8da[_0xffaf('0x16')];return routingClient['request'](_0xffaf('0x17'),{})[_0xffaf('0x14')](function(_0x569415){if(_0x569415['error'])throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)');var _0x5a46c6=_0x569415[_0xffaf('0x16')];return _0x4cb300(_[_0xffaf('0x18')]({},_0x15ee9e,_0x5a46c6));});})[_0xffaf('0x19')](function(_0x4062f9){_0x1a149a(_0x4062f9);});});}function getRealtimeQueues(_0x1dbefd,_0x218cd8){return new Promise(function(_0xfd4db8,_0x691113){var _0x7416e4=_0x218cd8===_0xffaf('0x1a')?amiClient:routingClient;return _0x7416e4['request'](_[_0xffaf('0x1b')](_0x218cd8)+_0xffaf('0x1c'),_0x1dbefd)[_0xffaf('0x14')](function(_0x4beb53){if(_0x4beb53[_0xffaf('0xf')])throw new Error(util[_0xffaf('0x1d')](_0xffaf('0x1e'),_0x218cd8));return _0xfd4db8(_0x4beb53['result']);})['catch'](function(_0x56c754){_0x691113(_0x56c754);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x3b2ac4,_0x3ee05b){return amiClient[_0xffaf('0x13')](_0xffaf('0x1f'),{})[_0xffaf('0x14')](function(_0x5e940b){if(_0x5e940b[_0xffaf('0xf')])throw new Error('Unable\x20to\x20retrieve\x20voice\x20queues\x20channels');return _0x3b2ac4(_0x5e940b[_0xffaf('0x16')]);})[_0xffaf('0x19')](function(_0x21bd0b){_0x3ee05b(_0x21bd0b);});});}function initializeQueues(_0x4394b7,_0x266c73,_0x32dc1c,_0x1b8cc4){var _0x103fbe=[_0xffaf('0x20'),_0xffaf('0x21'),'waiting','talking',_0xffaf('0x22')];if(_0x32dc1c==='voice'&&_0x1b8cc4==='outbound'){_0x103fbe[_0xffaf('0x23')](_0xffaf('0x24'),_0xffaf('0x25'),_0xffaf('0x26'),_0xffaf('0x27'),_0xffaf('0x28'),_0xffaf('0x29'),'startPredictive',_0xffaf('0x2a'),_0xffaf('0x2b'),_0xffaf('0x2c'),_0xffaf('0x2d'),_0xffaf('0x2e'),_0xffaf('0x2f'),_0xffaf('0x30'),_0xffaf('0x31'),_0xffaf('0x32'),_0xffaf('0x33'),_0xffaf('0x34'),_0xffaf('0x35'),_0xffaf('0x36'),_0xffaf('0x37'),'predictiveIntervalAvgTalktime');}return _0x4394b7[_0xffaf('0x38')](function(_0x53b630){var _0x5551aa=_0x53b630[_0xffaf('0x39')]({'plain':!![]});_0x5551aa['agents']=[];_0x5551aa[_0xffaf('0x22')]=0x0;_0x5551aa[_0xffaf('0x3a')]=0x0;_0x5551aa[_0xffaf('0x20')]=0x0;_0x5551aa['available']=0x0;_0x5551aa[_0xffaf('0x3b')]=0x0;if(_0x32dc1c===_0xffaf('0x1a')){_0x5551aa[_0xffaf('0x3c')]=0x0;_0x5551aa['busy']=0x0;if(_0x1b8cc4===_0xffaf('0x3d')){_0x5551aa[_0xffaf('0x24')]=0x0;_0x5551aa[_0xffaf('0x25')]=0x0;}}var _0x148948=_[_0xffaf('0x3e')](_0x266c73,['id',_0x5551aa['id']]);if(_0x148948)_['merge'](_0x5551aa,_[_0xffaf('0x3f')](_0x148948,_0x103fbe));return _0x5551aa;});}function updateAgentVoiceStatus(_0x541bef,_0xd72e28,_0x2804ce){var _0x23b260=_[_0xffaf('0x40')](_0x2804ce,['queue',_0xd72e28[_0xffaf('0x11')]]);if(_0x23b260[_0xffaf('0x41')]===0x0)return _0x541bef[_0xffaf('0x42')]=!![];if(_[_0xffaf('0x43')](_0x23b260,[_0xffaf('0x44'),_0x541bef['internal']['toString']()]))return _0x541bef[_0xffaf('0x3c')]=!![];if(!_0x541bef['talking'])return _0x541bef['busy']=!![];}function getVoiceQueueAgents(_0x4ca184,_0x4c4d5c,_0x562b60,_0x24026f){var _0x513ab8=_[_0xffaf('0x3e')](_0x4c4d5c,['id',_0x4ca184['id']]);if(!_0x513ab8)return _0x4ca184;return _0x513ab8[_0xffaf('0x45')]({'raw':!![]})[_0xffaf('0x14')](function(_0x2201bb){for(var _0x2f1ce2=0x0;_0x2f1ce2<_0x2201bb['length'];_0x2f1ce2++){var _0x5747f0=_['find'](_0x562b60,['id',_0x2201bb[_0x2f1ce2][_0xffaf('0x46')]]);if(!_0x5747f0){_0x5747f0={'id':_0x2201bb[_0x2f1ce2][_0xffaf('0x46')],'name':_0x2201bb[_0x2f1ce2][_0xffaf('0x46')],'accountcode':'','online':![]};}var _0x4b76bb={'id':_0x5747f0['id'],'name':_0x5747f0[_0xffaf('0x11')],'internal':_0x5747f0[_0xffaf('0x47')],'online':Boolean(_0x5747f0[_0xffaf('0x48')]),'paused':Boolean(_0x2201bb[_0x2f1ce2]['paused'])};if(_0x5747f0['voiceStatus']===_0xffaf('0x3c'))updateAgentVoiceStatus(_0x4b76bb,_0x4ca184,_0x24026f);if(_0x4b76bb[_0xffaf('0x48')])_0x4ca184[_0xffaf('0x3a')]++;if(_0x4b76bb[_0xffaf('0x42')])_0x4ca184[_0xffaf('0x42')]++;if(_0x4b76bb[_0xffaf('0x22')]&&!_0x4b76bb['busy']&&!_0x4b76bb['talking'])_0x4ca184[_0xffaf('0x22')]++;_0x4ca184[_0xffaf('0x49')][_0xffaf('0x23')](_0x4b76bb);}return _0x4ca184;});}function getQueueAgents(_0x58576c,_0xb221b3,_0x5a10bf){var _0x49e644=_0xffaf('0x4a')+_[_0xffaf('0x1b')](_0x5a10bf)+_0xffaf('0x4b');var _0x581516=_0x5a10bf+_0xffaf('0x4c');return db[_0x49e644][_0xffaf('0x4d')]({'where':{[_[_0xffaf('0x1b')](_0x5a10bf)+_0xffaf('0x4e')]:_0x58576c['id']},'raw':!![]})[_0xffaf('0x14')](function(_0x174555){for(var _0x21c8e0=0x0;_0x21c8e0<_0x174555[_0xffaf('0x41')];_0x21c8e0++){var _0xd59bf2=_[_0xffaf('0x3e')](_0xb221b3,['id',_0x174555[_0x21c8e0][_0xffaf('0x46')]]);if(!_0xd59bf2){_0xd59bf2={'id':_0x174555[_0x21c8e0][_0xffaf('0x46')],'name':_0x174555[_0x21c8e0]['UserId'],'online':![],['pauseField']:![]};}var _0x23979f={'id':_0xd59bf2['id'],'name':_0xd59bf2[_0xffaf('0x11')],'online':Boolean(_0xd59bf2[_0xffaf('0x48')]),'paused':Boolean(_0xd59bf2[_0x581516])};if(_0x23979f[_0xffaf('0x48')])_0x58576c['loggedInDb']++;_0x58576c['agents'][_0xffaf('0x23')](_0x23979f);}return _0x58576c;});}function isIdle(_0x122e14){return _0x122e14==='idle'||_0x122e14===_0xffaf('0x4f')||_0x122e14==='unavailable'||_0x122e14===_0xffaf('0x50')||_[_0xffaf('0x51')](_0x122e14);}function isAgentPaused(_0x2c79c4,_0x4f8595){var _0x3443fe=[_0x2c79c4[_0xffaf('0x52')],_0x2c79c4['faxPause'],_0x2c79c4[_0xffaf('0x53')],_0x2c79c4[_0xffaf('0x54')],_0x2c79c4[_0xffaf('0x55')],_0x2c79c4[_0xffaf('0x56')],_0x2c79c4['whatsappPause']];if(!_0x4f8595)return _[_0xffaf('0x57')](_0x3443fe);var _0x15eb8f=_[_0xffaf('0x40')](_0x3443fe);return _0x15eb8f[_0xffaf('0x41')]>0x0&&_0x15eb8f[_0xffaf('0x41')]<_0x3443fe['length']?!![]:![];}function isAgentIdle(_0x39550b){if(_0x39550b[_0xffaf('0x58')]!==_0xffaf('0x59')&&_0x39550b['voicePause']){_0x39550b[_0xffaf('0x58')]=_0xffaf('0x5a');return![];}return _['every']([_0x39550b[_0xffaf('0x5b')],_0x39550b[_0xffaf('0x5c')],_0x39550b[_0xffaf('0x5d')],_0x39550b[_0xffaf('0x5e')],_0x39550b['smsStatus'],_0x39550b[_0xffaf('0x58')],_0x39550b[_0xffaf('0x5f')]],isIdle);}function getAgentStatus(_0x17716c){var _0x2dd47d=_0xffaf('0x4f');if(isAgentPaused(_0x17716c))_0x2dd47d=_0xffaf('0x5a');else if(isAgentPaused(_0x17716c,!![]))_0x2dd47d=_0xffaf('0x60');else if(isAgentIdle(_0x17716c))_0x2dd47d=_0xffaf('0x59');else _0x2dd47d=_0xffaf('0x42');return _0x2dd47d;}function validateChannel(_0x6f73a6){var _0x3b90c5=[_0xffaf('0x61'),_0xffaf('0x62'),_0xffaf('0x63'),_0xffaf('0x64'),_0xffaf('0x65'),_0xffaf('0x66'),_0xffaf('0x1a')];if(!_[_0xffaf('0x67')](_0x3b90c5,_0x6f73a6[_0xffaf('0x68')]()))throw new Error('Invalid\x20channel');return _0x6f73a6[_0xffaf('0x68')]();}function getFilteredAgentIds(_0x6eed2a,_0x4d4af8){var _0x2b5b76=_[_0xffaf('0x69')](_0x6eed2a)?_0x6eed2a:[_0x6eed2a];var _0x129809=_[_0xffaf('0x38')](_0x2b5b76,function(_0x30fad7){return db[_0x4d4af8][_0xffaf('0x6a')]({'where':{'name':_0x30fad7}})[_0xffaf('0x14')](function(_0x1e0900){if(!_0x1e0900)return[];return _0x1e0900['getAgents']({'attributes':['id'],'raw':!![]});});});return Promise[_0xffaf('0x6b')](_0x129809)[_0xffaf('0x14')](function(_0x1c7a60){var _0x2a8a0f=_(_0x1c7a60)[_0xffaf('0x6c')]()[_0xffaf('0x38')]('id')[_0xffaf('0x6d')]()['value']();return _0x2a8a0f;});}function getUpdatedSortOptions(_0x41631b){var _0x37274b={'fields':[],'order':null};var _0x223358=_0x41631b['split'](',');_0x37274b[_0xffaf('0x6e')]=_['filter'](_0x223358,function(_0x2e03cf){if(!_0x2e03cf[_0xffaf('0x67')](_0xffaf('0x6f')))return!![];_0x37274b[_0xffaf('0x70')]=_[_0xffaf('0x71')](_0x2e03cf,'-')?_0xffaf('0x72'):_0xffaf('0x73');return![];});return _0x37274b;}function orderAgentsByStatus(_0x89f3b0,_0x1664eb){return _0x89f3b0[_0xffaf('0x74')](function(_0x5e0965,_0x3ad689){if(_0x5e0965['globalStatus']===_0x3ad689[_0xffaf('0x6f')]&&_0x5e0965[_0xffaf('0x6f')]===_0xffaf('0x5a')){if(_0x1664eb===_0xffaf('0x72'))return(_0x5e0965['pauseType']||'')<(_0x3ad689['pauseType']||'')?0x1:-0x1;return _0x5e0965['pauseType']<_0x3ad689['pauseType']?-0x1:0x1;}else{if(_0x1664eb==='DESC')return _0x5e0965[_0xffaf('0x6f')]<_0x3ad689[_0xffaf('0x6f')]?0x1:-0x1;return _0x5e0965[_0xffaf('0x6f')]<_0x3ad689[_0xffaf('0x6f')]?-0x1:0x1;}});}exports[_0xffaf('0x75')]=function(_0x5dd05e,_0x44c987){var _0x211c53={'count':0x0,'rows':[]},_0x3b3897={},_0x2e6adc,_0x236ac0,_0x58044d,_0x30e7e3,_0x55ec90=[_0xffaf('0x76'),_0xffaf('0x48'),_0xffaf('0x77'),'lastPauseAt',_0xffaf('0x78'),_0xffaf('0x79'),'internal','address',_0xffaf('0x52'),_0xffaf('0x54'),'mailPause',_0xffaf('0x55'),_0xffaf('0x7a'),_0xffaf('0x7b'),_0xffaf('0x56'),_0xffaf('0x7c'),'openchannelCapacity',_0xffaf('0x7d'),'smsCapacity','whatsappCapacity',_0xffaf('0x7e'),'chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity',_0xffaf('0x7f'),_0xffaf('0x5b'),'openchannelStatus',_0xffaf('0x5d'),_0xffaf('0x80'),_0xffaf('0x5f'),'faxStatus',_0xffaf('0x58'),_0xffaf('0x81'),_0xffaf('0x82'),_0xffaf('0x83'),_0xffaf('0x84'),_0xffaf('0x85'),_0xffaf('0x86'),_0xffaf('0x87'),_0xffaf('0x88'),_0xffaf('0x89'),_0xffaf('0x8a'),_0xffaf('0x8b'),_0xffaf('0x8c'),_0xffaf('0x8d')],_0x443250=[_0xffaf('0x52'),'openchannelPause',_0xffaf('0x53'),'smsPause',_0xffaf('0x7a'),_0xffaf('0x7b'),_0xffaf('0x56'),_0xffaf('0x48')];Promise[_0xffaf('0x8e')]()[_0xffaf('0x14')](function(){if(_0x5dd05e['query'][_0xffaf('0x8f')])_0x2e6adc=validateChannel(_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x8f')]);if(!_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x74')]||!_0x5dd05e[_0xffaf('0x90')]['sort']['includes'](_0xffaf('0x6f')))return;var _0x517baf=getUpdatedSortOptions(_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x74')]);_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x74')]=_0x517baf[_0xffaf('0x6e')]['join'](',');_0x236ac0=_0x517baf['order'];})[_0xffaf('0x14')](function(){if(!_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x91')])return[];var _0x1a4f4b=_[_0xffaf('0x1b')](_0x2e6adc)+'Queue';return getFilteredAgentIds(_0x5dd05e[_0xffaf('0x90')]['globalQueueFilter'],_0x1a4f4b);})['then'](function(_0x2d128f){var _0x336e3f=_[_0xffaf('0x38')](db[_0xffaf('0x4a')]['rawAttributes'],function(_0x57c9a9){return{'name':_0x57c9a9[_0xffaf('0x92')],'type':_0x57c9a9[_0xffaf('0x93')][_0xffaf('0x94')]};});_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x95')]=_0xffaf('0x96');_0x5dd05e['query'][_0xffaf('0x48')]=!![];_0x3b3897=qs['getOptions'](_0x336e3f,_0x5dd05e);_0x3b3897['raw']=!![];if(!_[_0xffaf('0x97')](_0x2d128f)){_0x3b3897[_0xffaf('0x98')]=_[_0xffaf('0x18')](_0x3b3897[_0xffaf('0x98')],{'$and':[{'id':{'$in':_0x2d128f}}]});}else if(!_[_0xffaf('0x97')](_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x91')])){return _0x211c53;}if(_0x5dd05e[_0xffaf('0x99')][_0xffaf('0x95')]===_0xffaf('0x99')){var _0x567b59={'params':{'id':_0x5dd05e[_0xffaf('0x99')][_0xffaf('0x9a')]},'query':{'section':_0xffaf('0x17'),'role':_0xffaf('0x96'),'online':!![],'nolimit':_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x9b')],'sort':_0x5dd05e['query'][_0xffaf('0x74')],'filter':_0x5dd05e[_0xffaf('0x90')][_0xffaf('0x40')],'raw':!![],'ids':_0x2d128f}};return db[_0xffaf('0x9c')]['getResources'](_0x567b59);}return db[_0xffaf('0x4a')][_0xffaf('0x9d')](_0x3b3897);})[_0xffaf('0x14')](function(_0x55a4ee){_0x211c53[_0xffaf('0xb')]=_0x55a4ee[_0xffaf('0xb')];_0x58044d=_0x55a4ee[_0xffaf('0x9e')];return getRealtimeAgents();})[_0xffaf('0x14')](function(_0x53b2fe){_0x30e7e3=_0x53b2fe[_0xffaf('0x9e')];return _0x58044d[_0xffaf('0x38')](function(_0x4e487c){var _0x301ad6=_[_0xffaf('0x3e')](_0x30e7e3,['id',_0x4e487c['id']]);if(_0x301ad6)_[_0xffaf('0x18')](_0x4e487c,_[_0xffaf('0x3f')](_[_0xffaf('0x9f')](_0x301ad6,_0x443250),_0x55ec90));_0x4e487c[_0xffaf('0x6f')]=getAgentStatus(_0x4e487c);return _0x4e487c;});})[_0xffaf('0x14')](function(_0x5a9336){var _0x5b4b0d;if(_0x5dd05e[_0xffaf('0x90')][_0xffaf('0xa0')]){_0x5b4b0d=_[_0xffaf('0x40')](_0x5a9336,[_0xffaf('0x6f'),_0x5dd05e['query']['globalStatusFilter']]);if(_0x5dd05e[_0xffaf('0x90')][_0xffaf('0xa1')]){_0x5b4b0d=_[_0xffaf('0x40')](_0x5b4b0d,['pauseType',_0x5dd05e[_0xffaf('0x90')]['pauseTypeFilter']]);}}if(_0x5b4b0d)_0x5a9336=_0x5b4b0d;if(!_0x236ac0)return _0x5a9336;return orderAgentsByStatus(_0x5a9336,_0x236ac0);})[_0xffaf('0x14')](function(_0x307db7){_0x211c53[_0xffaf('0x9e')]=_0x307db7;return _0x211c53;})[_0xffaf('0x14')](respondWithFilteredResult(_0x44c987,_0x3b3897))[_0xffaf('0x19')](handleError(_0x44c987,null));};exports['getQueues']=function(_0x18a658,_0x3bc389){var _0x18b04c={'count':0x0,'rows':[]},_0x24fcd5={},_0x30f16d,_0x393b18,_0x4621d6,_0x327c77,_0x4f74c3;Promise[_0xffaf('0x8e')]()[_0xffaf('0x14')](function(){if(_0x18a658[_0xffaf('0x90')][_0xffaf('0x8f')])_0x30f16d=validateChannel(_0x18a658['query']['channel']);var _0x3bb230=_[_0xffaf('0x1b')](_0x30f16d)+'Queue';var _0xd1c0d0=_['map'](db[_0x3bb230][_0xffaf('0xa2')],function(_0x3a67ba){return{'name':_0x3a67ba['fieldName'],'type':_0x3a67ba[_0xffaf('0x93')][_0xffaf('0x94')]};});_0x24fcd5=qs[_0xffaf('0xa3')](_0xd1c0d0,_0x18a658);if(_0x18a658[_0xffaf('0x99')][_0xffaf('0x95')]==='user'){var _0xef657c={'params':{'id':_0x18a658[_0xffaf('0x99')]['userProfileId']},'query':{'section':_0x30f16d===_0xffaf('0x1a')&&_0x18a658[_0xffaf('0x90')]['type']==='outbound'?_0xffaf('0xa4'):_[_0xffaf('0x1b')](_0x30f16d)+_0xffaf('0x1c'),'type':_0x18a658[_0xffaf('0x90')]['type'],'nolimit':!![],'sort':_0xffaf('0x11'),'filter':_0x18a658['query'][_0xffaf('0x40')]}};return db[_0xffaf('0x9c')]['getResources'](_0xef657c);}return db[_0x3bb230]['findAndCountAll'](_0x24fcd5);})[_0xffaf('0x14')](function(_0x2ee527){_0x18b04c[_0xffaf('0xb')]=_0x2ee527[_0xffaf('0xb')];_0x393b18=_0x2ee527[_0xffaf('0x9e')];return getRealtimeQueues(_0x18a658,_0x30f16d);})[_0xffaf('0x14')](function(_0x404504){_0x327c77=_0x404504[_0xffaf('0x9e')];return getRealtimeAgents();})[_0xffaf('0x14')](function(_0x7c2736){_0x4621d6=_0x7c2736[_0xffaf('0x9e')];if(_0x30f16d!='voice')return;return getRealtimeVoiceQueueChannels();})[_0xffaf('0x14')](function(_0x4b00fa){_0x4f74c3=_0x4b00fa?_0x4b00fa[_0xffaf('0x9e')]:[];return initializeQueues(_0x393b18,_0x327c77,_0x30f16d,_0x18a658['query'][_0xffaf('0x93')]);})['then'](function(_0x271cbc){var _0x1eac74=_0x271cbc[_0xffaf('0x38')](function(_0x3b26be){if(_0x30f16d==='voice')return getVoiceQueueAgents(_0x3b26be,_0x393b18,_0x4621d6,_0x4f74c3);else return getQueueAgents(_0x3b26be,_0x4621d6,_0x30f16d);});return Promise[_0xffaf('0x6b')](_0x1eac74);})['then'](function(_0x25ae70){_0x18b04c[_0xffaf('0x9e')]=_0x25ae70;return _0x18b04c;})[_0xffaf('0x14')](respondWithFilteredResult(_0x3bc389,_0x24fcd5))['catch'](handleError(_0x3bc389,null));};