f2b400272cbd2851073fca22999fa95eeb3868dd
[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 _0x542b=['loggedInDb','find','pick','filter','queue','length','busy','some','toString','UserId','accountcode','User','Queue','Pause','findAll','QueueId','online','idle','unknown','unavailable','ringing','chatPause','mailPause','openchannelPause','voicePause','every','voiceStatus','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','whatsappStatus','*pause','mail','sms','openchannel','whatsapp','includes','Invalid\x20channel','toLowerCase','getAgents','all','flatten','uniq','value','fields','globalStatus','startsWith','DESC','ASC','sort','pauseType','lastLoginAt','lastPauseAt','internal','address','smsPause','whatsappPause','chatCapacity','openchannelCapacity','mailCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','faxPause','resolve','query','channel','join','order','globalQueueFilter','fieldName','type','key','role','agent','raw','where','isEmpty','user','nolimit','UserProfile','getResources','rows','globalStatusFilter','pauseTypeFilter','rawAttributes','getOptions','userProfileId','QueueCampaigns','util','lodash','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','undefined','limit','offset','count','status','Content-Range','json','error','stack','name','send','request','Agents','then','result','merge','voice','startCase','Queues','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','catch','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','available','waiting','talking','paused','outbound','push','pTalking','originated','dialMethod','Trunk','startPredictive','erlangCalls','erlangCallToSecond','erlangBusyFactor','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','map','get','agents'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x542b,0x69));var _0xb542=function(_0x1e6db3,_0x5643ac){_0x1e6db3=_0x1e6db3-0x0;var _0x1de886=_0x542b[_0x1e6db3];return _0x1de886;};'use strict';var util=require(_0xb542('0x0'));var _=require(_0xb542('0x1'));var jayson=require('jayson/promise');var qs=require(_0xb542('0x2'));var logger=require(_0xb542('0x3'))(_0xb542('0x4'));var db=require(_0xb542('0x5'))['db'];var amiClient=jayson[_0xb542('0x6')]['http']({'port':0x232a});var routingClient=jayson[_0xb542('0x6')][_0xb542('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x503d95,_0x345a04){return function(_0x164561){if(_0x164561){var _0x355599=typeof _0x345a04['offset']===_0xb542('0x8')&&typeof _0x345a04[_0xb542('0x9')]===_0xb542('0x8');var _0x1965c9=_0x164561['count'];var _0x2310ee=_0x355599?0x0:_0x345a04[_0xb542('0xa')];var _0x1f909e=_0x355599?_0x164561[_0xb542('0xb')]:_0x345a04['offset']+_0x345a04['limit'];var _0x436813;if(_0x1f909e>=_0x1965c9){_0x1f909e=_0x1965c9;_0x436813=0xc8;}else{_0x436813=0xce;}_0x503d95[_0xb542('0xc')](_0x436813);return _0x503d95['set'](_0xb542('0xd'),_0x2310ee+'-'+_0x1f909e+'/'+_0x1965c9)[_0xb542('0xe')](_0x164561);}return null;};}function handleError(_0x50f66d,_0x385bf5){_0x385bf5=_0x385bf5||0x1f4;return function(_0x4d5aa4){logger[_0xb542('0xf')](_0x4d5aa4[_0xb542('0x10')]);if(_0x4d5aa4[_0xb542('0x11')]){delete _0x4d5aa4[_0xb542('0x11')];}_0x50f66d[_0xb542('0xc')](_0x385bf5)[_0xb542('0x12')](_0x4d5aa4);};}function getRealtimeAgents(){return new Promise(function(_0x4ca1a0,_0x192b0d){return amiClient[_0xb542('0x13')](_0xb542('0x14'),{})[_0xb542('0x15')](function(_0x126a3c){if(_0x126a3c[_0xb542('0xf')])throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)');var _0x283046=_0x126a3c[_0xb542('0x16')];return routingClient[_0xb542('0x13')](_0xb542('0x14'),{})['then'](function(_0x2cd41a){if(_0x2cd41a['error'])throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)');var _0x2d2c41=_0x2cd41a[_0xb542('0x16')];return _0x4ca1a0(_[_0xb542('0x17')]({},_0x283046,_0x2d2c41));});})['catch'](function(_0x82d882){_0x192b0d(_0x82d882);});});}function getRealtimeQueues(_0x14ba24,_0x587bc2){return new Promise(function(_0x44806a,_0x149940){var _0x230861=_0x587bc2===_0xb542('0x18')?amiClient:routingClient;return _0x230861['request'](_[_0xb542('0x19')](_0x587bc2)+_0xb542('0x1a'),_0x14ba24)[_0xb542('0x15')](function(_0x25d504){if(_0x25d504['error'])throw new Error(util['format'](_0xb542('0x1b'),_0x587bc2));return _0x44806a(_0x25d504[_0xb542('0x16')]);})[_0xb542('0x1c')](function(_0x14e0a2){_0x149940(_0x14e0a2);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x20a8d3,_0x15a90f){return amiClient[_0xb542('0x13')](_0xb542('0x1d'),{})[_0xb542('0x15')](function(_0x262d99){if(_0x262d99[_0xb542('0xf')])throw new Error(_0xb542('0x1e'));return _0x20a8d3(_0x262d99['result']);})['catch'](function(_0x2f7b85){_0x15a90f(_0x2f7b85);});});}function initializeQueues(_0x27d863,_0x94c17d,_0x543a06,_0x370be8){var _0x419b7a=[_0xb542('0x1f'),_0xb542('0x20'),_0xb542('0x21'),_0xb542('0x22'),_0xb542('0x23')];if(_0x543a06===_0xb542('0x18')&&_0x370be8===_0xb542('0x24')){_0x419b7a[_0xb542('0x25')](_0xb542('0x26'),_0xb542('0x27'),'message','dialActive',_0xb542('0x28'),_0xb542('0x29'),_0xb542('0x2a'),'startProgressive',_0xb542('0x2b'),_0xb542('0x2c'),'erlangAbandonmentRate',_0xb542('0x2d'),'dialPredictiveInterval',_0xb542('0x2e'),_0xb542('0x2f'),_0xb542('0x30'),_0xb542('0x31'),_0xb542('0x32'),_0xb542('0x33'),_0xb542('0x34'),_0xb542('0x35'),_0xb542('0x36'));}return _0x27d863[_0xb542('0x37')](function(_0x3be666){var _0x4e887e=_0x3be666[_0xb542('0x38')]({'plain':!![]});_0x4e887e[_0xb542('0x39')]=[];_0x4e887e[_0xb542('0x23')]=0x0;_0x4e887e[_0xb542('0x3a')]=0x0;_0x4e887e['loggedIn']=0x0;_0x4e887e['available']=0x0;_0x4e887e['waiting']=0x0;if(_0x543a06===_0xb542('0x18')){_0x4e887e[_0xb542('0x22')]=0x0;_0x4e887e['busy']=0x0;if(_0x370be8===_0xb542('0x24')){_0x4e887e[_0xb542('0x26')]=0x0;_0x4e887e['originated']=0x0;}}var _0x40e938=_[_0xb542('0x3b')](_0x94c17d,['id',_0x4e887e['id']]);if(_0x40e938)_[_0xb542('0x17')](_0x4e887e,_[_0xb542('0x3c')](_0x40e938,_0x419b7a));return _0x4e887e;});}function updateAgentVoiceStatus(_0x817021,_0x37e1a0,_0x1393da){var _0x534b7c=_[_0xb542('0x3d')](_0x1393da,[_0xb542('0x3e'),_0x37e1a0[_0xb542('0x11')]]);if(_0x534b7c[_0xb542('0x3f')]===0x0)return _0x817021[_0xb542('0x40')]=!![];if(_[_0xb542('0x41')](_0x534b7c,['connectedlinenum',_0x817021['internal'][_0xb542('0x42')]()]))return _0x817021[_0xb542('0x22')]=!![];if(!_0x817021[_0xb542('0x22')])return _0x817021['busy']=!![];}function getVoiceQueueAgents(_0x12dce3,_0x4f9fc6,_0x39a6aa,_0x5def1b){var _0x4e7a15=_[_0xb542('0x3b')](_0x4f9fc6,['id',_0x12dce3['id']]);if(!_0x4e7a15)return _0x12dce3;return _0x4e7a15['getMembers']({'raw':!![]})[_0xb542('0x15')](function(_0x52facf){for(var _0x127563=0x0;_0x127563<_0x52facf[_0xb542('0x3f')];_0x127563++){var _0x19043=_['find'](_0x39a6aa,['id',_0x52facf[_0x127563][_0xb542('0x43')]]);if(!_0x19043){_0x19043={'id':_0x52facf[_0x127563][_0xb542('0x43')],'name':_0x52facf[_0x127563]['UserId'],'accountcode':'','online':![]};}var _0x330c4c={'id':_0x19043['id'],'name':_0x19043[_0xb542('0x11')],'internal':_0x19043[_0xb542('0x44')],'online':Boolean(_0x19043['online']),'paused':Boolean(_0x52facf[_0x127563][_0xb542('0x23')])};if(_0x19043['voiceStatus']===_0xb542('0x22'))updateAgentVoiceStatus(_0x330c4c,_0x12dce3,_0x5def1b);if(_0x330c4c['online'])_0x12dce3[_0xb542('0x3a')]++;if(_0x330c4c[_0xb542('0x40')])_0x12dce3[_0xb542('0x40')]++;if(_0x330c4c['paused']&&!_0x330c4c[_0xb542('0x40')]&&!_0x330c4c['talking'])_0x12dce3['paused']++;_0x12dce3['agents'][_0xb542('0x25')](_0x330c4c);}return _0x12dce3;});}function getQueueAgents(_0x2157a2,_0xcfa439,_0x333e78){var _0x4e6cec=_0xb542('0x45')+_[_0xb542('0x19')](_0x333e78)+_0xb542('0x46');var _0x19c146=_0x333e78+_0xb542('0x47');return db[_0x4e6cec][_0xb542('0x48')]({'where':{[_['startCase'](_0x333e78)+_0xb542('0x49')]:_0x2157a2['id']},'raw':!![]})[_0xb542('0x15')](function(_0x520145){for(var _0x461015=0x0;_0x461015<_0x520145[_0xb542('0x3f')];_0x461015++){var _0x27c8e5=_[_0xb542('0x3b')](_0xcfa439,['id',_0x520145[_0x461015][_0xb542('0x43')]]);if(!_0x27c8e5){_0x27c8e5={'id':_0x520145[_0x461015]['UserId'],'name':_0x520145[_0x461015][_0xb542('0x43')],'online':![],['pauseField']:![]};}var _0x2d0c1b={'id':_0x27c8e5['id'],'name':_0x27c8e5[_0xb542('0x11')],'online':Boolean(_0x27c8e5[_0xb542('0x4a')]),'paused':Boolean(_0x27c8e5[_0x19c146])};if(_0x2d0c1b[_0xb542('0x4a')])_0x2157a2[_0xb542('0x3a')]++;_0x2157a2[_0xb542('0x39')][_0xb542('0x25')](_0x2d0c1b);}return _0x2157a2;});}function isIdle(_0x1c20c6){return _0x1c20c6===_0xb542('0x4b')||_0x1c20c6===_0xb542('0x4c')||_0x1c20c6===_0xb542('0x4d')||_0x1c20c6===_0xb542('0x4e')||_['isNil'](_0x1c20c6);}function isAgentPaused(_0x511dbd,_0x492859){var _0x3fc603=[_0x511dbd[_0xb542('0x4f')],_0x511dbd['faxPause'],_0x511dbd[_0xb542('0x50')],_0x511dbd[_0xb542('0x51')],_0x511dbd['smsPause'],_0x511dbd[_0xb542('0x52')],_0x511dbd['whatsappPause']];if(!_0x492859)return _[_0xb542('0x53')](_0x3fc603);var _0x54f6a4=_[_0xb542('0x3d')](_0x3fc603);return _0x54f6a4[_0xb542('0x3f')]>0x0&&_0x54f6a4[_0xb542('0x3f')]<_0x3fc603['length']?!![]:![];}function isAgentIdle(_0x423ebd){if(_0x423ebd[_0xb542('0x54')]!==_0xb542('0x4b')&&_0x423ebd[_0xb542('0x52')]){_0x423ebd[_0xb542('0x54')]=_0xb542('0x55');return![];}return _[_0xb542('0x53')]([_0x423ebd[_0xb542('0x56')],_0x423ebd[_0xb542('0x57')],_0x423ebd[_0xb542('0x58')],_0x423ebd[_0xb542('0x59')],_0x423ebd[_0xb542('0x5a')],_0x423ebd[_0xb542('0x54')],_0x423ebd[_0xb542('0x5b')]],isIdle);}function getAgentStatus(_0x4caffa){var _0x5ad931=_0xb542('0x4c');if(isAgentPaused(_0x4caffa))_0x5ad931=_0xb542('0x55');else if(isAgentPaused(_0x4caffa,!![]))_0x5ad931=_0xb542('0x5c');else if(isAgentIdle(_0x4caffa))_0x5ad931=_0xb542('0x4b');else _0x5ad931=_0xb542('0x40');return _0x5ad931;}function validateChannel(_0x59d560){var _0x2f7746=[_0xb542('0x5d'),'chat',_0xb542('0x5e'),_0xb542('0x5f'),'fax',_0xb542('0x60'),_0xb542('0x18')];if(!_[_0xb542('0x61')](_0x2f7746,_0x59d560['toLowerCase']()))throw new Error(_0xb542('0x62'));return _0x59d560[_0xb542('0x63')]();}function getFilteredAgentIds(_0x281ef5,_0xa4f863){var _0x84087=_['isArray'](_0x281ef5)?_0x281ef5:[_0x281ef5];var _0xd2124b=_['map'](_0x84087,function(_0xd8e833){return db[_0xa4f863]['findOne']({'where':{'name':_0xd8e833}})['then'](function(_0x98eb3c){if(!_0x98eb3c)return[];return _0x98eb3c[_0xb542('0x64')]({'attributes':['id'],'raw':!![]});});});return Promise[_0xb542('0x65')](_0xd2124b)[_0xb542('0x15')](function(_0x2a8ee9){var _0x17379b=_(_0x2a8ee9)[_0xb542('0x66')]()[_0xb542('0x37')]('id')[_0xb542('0x67')]()[_0xb542('0x68')]();return _0x17379b;});}function getUpdatedSortOptions(_0x55a338){var _0x503635={'fields':[],'order':null};var _0x555406=_0x55a338['split'](',');_0x503635[_0xb542('0x69')]=_[_0xb542('0x3d')](_0x555406,function(_0x30ff49){if(!_0x30ff49[_0xb542('0x61')](_0xb542('0x6a')))return!![];_0x503635['order']=_[_0xb542('0x6b')](_0x30ff49,'-')?_0xb542('0x6c'):_0xb542('0x6d');return![];});return _0x503635;}function orderAgentsByStatus(_0x53891d,_0x1341c1){return _0x53891d[_0xb542('0x6e')](function(_0x5d6223,_0x2a5698){if(_0x5d6223['globalStatus']===_0x2a5698[_0xb542('0x6a')]&&_0x5d6223[_0xb542('0x6a')]===_0xb542('0x55')){if(_0x1341c1==='DESC')return(_0x5d6223[_0xb542('0x6f')]||'')<(_0x2a5698[_0xb542('0x6f')]||'')?0x1:-0x1;return _0x5d6223[_0xb542('0x6f')]<_0x2a5698[_0xb542('0x6f')]?-0x1:0x1;}else{if(_0x1341c1===_0xb542('0x6c'))return _0x5d6223[_0xb542('0x6a')]<_0x2a5698['globalStatus']?0x1:-0x1;return _0x5d6223[_0xb542('0x6a')]<_0x2a5698[_0xb542('0x6a')]?-0x1:0x1;}});}exports[_0xb542('0x64')]=function(_0x2311a0,_0xaf7cee){var _0x5c1eeb={'count':0x0,'rows':[]},_0x1ef980={},_0x456f6d,_0x2521da,_0x2852aa,_0x405949,_0x3ed691=['userpic',_0xb542('0x4a'),_0xb542('0x70'),_0xb542('0x71'),_0xb542('0x6f'),_0xb542('0x71'),_0xb542('0x72'),_0xb542('0x73'),'chatPause',_0xb542('0x51'),_0xb542('0x50'),_0xb542('0x74'),_0xb542('0x75'),'faxPause',_0xb542('0x52'),_0xb542('0x76'),_0xb542('0x77'),_0xb542('0x78'),'smsCapacity','whatsappCapacity','faxCapacity',_0xb542('0x79'),_0xb542('0x7a'),_0xb542('0x7b'),_0xb542('0x7c'),_0xb542('0x7d'),_0xb542('0x7e'),_0xb542('0x56'),_0xb542('0x59'),'mailStatus',_0xb542('0x5a'),_0xb542('0x5b'),_0xb542('0x57'),_0xb542('0x54'),'chatStatusTime',_0xb542('0x7f'),'mailStatusTime',_0xb542('0x80'),_0xb542('0x81'),_0xb542('0x82'),_0xb542('0x83'),_0xb542('0x3e'),_0xb542('0x84'),_0xb542('0x85'),_0xb542('0x86'),_0xb542('0x87'),_0xb542('0x88')],_0x445232=['chatPause',_0xb542('0x51'),_0xb542('0x50'),_0xb542('0x74'),_0xb542('0x75'),_0xb542('0x89'),_0xb542('0x52'),_0xb542('0x4a')];Promise[_0xb542('0x8a')]()[_0xb542('0x15')](function(){if(_0x2311a0[_0xb542('0x8b')][_0xb542('0x8c')])_0x456f6d=validateChannel(_0x2311a0[_0xb542('0x8b')][_0xb542('0x8c')]);if(!_0x2311a0[_0xb542('0x8b')][_0xb542('0x6e')]||!_0x2311a0['query']['sort'][_0xb542('0x61')](_0xb542('0x6a')))return;var _0xb41dbc=getUpdatedSortOptions(_0x2311a0[_0xb542('0x8b')]['sort']);_0x2311a0[_0xb542('0x8b')][_0xb542('0x6e')]=_0xb41dbc['fields'][_0xb542('0x8d')](',');_0x2521da=_0xb41dbc[_0xb542('0x8e')];})[_0xb542('0x15')](function(){if(!_0x2311a0[_0xb542('0x8b')][_0xb542('0x8f')])return[];var _0x55fbba=_[_0xb542('0x19')](_0x456f6d)+_0xb542('0x46');return getFilteredAgentIds(_0x2311a0[_0xb542('0x8b')][_0xb542('0x8f')],_0x55fbba);})['then'](function(_0x1cd6f7){var _0xdeb24c=_[_0xb542('0x37')](db[_0xb542('0x45')]['rawAttributes'],function(_0x471642){return{'name':_0x471642[_0xb542('0x90')],'type':_0x471642[_0xb542('0x91')][_0xb542('0x92')]};});_0x2311a0[_0xb542('0x8b')][_0xb542('0x93')]=_0xb542('0x94');_0x2311a0[_0xb542('0x8b')][_0xb542('0x4a')]=!![];_0x1ef980=qs['getOptions'](_0xdeb24c,_0x2311a0);_0x1ef980[_0xb542('0x95')]=!![];if(!_['isEmpty'](_0x1cd6f7)){_0x1ef980[_0xb542('0x96')]=_[_0xb542('0x17')](_0x1ef980['where'],{'$and':[{'id':{'$in':_0x1cd6f7}}]});}else if(!_[_0xb542('0x97')](_0x2311a0['query'][_0xb542('0x8f')])){return _0x5c1eeb;}if(_0x2311a0[_0xb542('0x98')][_0xb542('0x93')]===_0xb542('0x98')){var _0x114580={'params':{'id':_0x2311a0[_0xb542('0x98')]['userProfileId']},'query':{'section':_0xb542('0x14'),'role':_0xb542('0x94'),'online':!![],'nolimit':_0x2311a0[_0xb542('0x8b')][_0xb542('0x99')],'sort':_0x2311a0['query'][_0xb542('0x6e')],'filter':_0x2311a0['query'][_0xb542('0x3d')],'raw':!![],'ids':_0x1cd6f7}};return db[_0xb542('0x9a')][_0xb542('0x9b')](_0x114580);}return db[_0xb542('0x45')]['findAndCountAll'](_0x1ef980);})[_0xb542('0x15')](function(_0x32db79){_0x5c1eeb[_0xb542('0xb')]=_0x32db79['count'];_0x2852aa=_0x32db79[_0xb542('0x9c')];return getRealtimeAgents();})[_0xb542('0x15')](function(_0x1efe5a){_0x405949=_0x1efe5a[_0xb542('0x9c')];return _0x2852aa[_0xb542('0x37')](function(_0x3cd0d9){var _0x342afd=_[_0xb542('0x3b')](_0x405949,['id',_0x3cd0d9['id']]);if(_0x342afd)_['merge'](_0x3cd0d9,_[_0xb542('0x3c')](_['omit'](_0x342afd,_0x445232),_0x3ed691));_0x3cd0d9[_0xb542('0x6a')]=getAgentStatus(_0x3cd0d9);return _0x3cd0d9;});})['then'](function(_0x2fb7d0){var _0x43dcc3;if(_0x2311a0[_0xb542('0x8b')][_0xb542('0x9d')]){_0x43dcc3=_['filter'](_0x2fb7d0,[_0xb542('0x6a'),_0x2311a0[_0xb542('0x8b')]['globalStatusFilter']]);if(_0x2311a0[_0xb542('0x8b')][_0xb542('0x9e')]){_0x43dcc3=_[_0xb542('0x3d')](_0x43dcc3,['pauseType',_0x2311a0[_0xb542('0x8b')][_0xb542('0x9e')]]);}}if(_0x43dcc3)_0x2fb7d0=_0x43dcc3;if(!_0x2521da)return _0x2fb7d0;return orderAgentsByStatus(_0x2fb7d0,_0x2521da);})[_0xb542('0x15')](function(_0x1778dc){_0x5c1eeb[_0xb542('0x9c')]=_0x1778dc;return _0x5c1eeb;})[_0xb542('0x15')](respondWithFilteredResult(_0xaf7cee,_0x1ef980))[_0xb542('0x1c')](handleError(_0xaf7cee,null));};exports['getQueues']=function(_0xbd6b09,_0x4c545f){var _0x1990cd={'count':0x0,'rows':[]},_0x5eb89c={},_0x43d15d,_0x83a954,_0x28cff4,_0x2143ed,_0x1bde99;Promise[_0xb542('0x8a')]()[_0xb542('0x15')](function(){if(_0xbd6b09[_0xb542('0x8b')]['channel'])_0x43d15d=validateChannel(_0xbd6b09[_0xb542('0x8b')]['channel']);var _0x3ebdb3=_[_0xb542('0x19')](_0x43d15d)+'Queue';var _0x45c230=_[_0xb542('0x37')](db[_0x3ebdb3][_0xb542('0x9f')],function(_0x3013fd){return{'name':_0x3013fd['fieldName'],'type':_0x3013fd['type'][_0xb542('0x92')]};});_0x5eb89c=qs[_0xb542('0xa0')](_0x45c230,_0xbd6b09);if(_0xbd6b09[_0xb542('0x98')]['role']===_0xb542('0x98')){var _0x2504f8={'params':{'id':_0xbd6b09[_0xb542('0x98')][_0xb542('0xa1')]},'query':{'section':_0x43d15d==='voice'&&_0xbd6b09[_0xb542('0x8b')][_0xb542('0x91')]===_0xb542('0x24')?_0xb542('0xa2'):_[_0xb542('0x19')](_0x43d15d)+_0xb542('0x1a'),'type':_0xbd6b09['query'][_0xb542('0x91')],'nolimit':!![],'sort':_0xb542('0x11'),'filter':_0xbd6b09[_0xb542('0x8b')][_0xb542('0x3d')]}};return db['UserProfile'][_0xb542('0x9b')](_0x2504f8);}return db[_0x3ebdb3]['findAndCountAll'](_0x5eb89c);})[_0xb542('0x15')](function(_0x1976fc){_0x1990cd[_0xb542('0xb')]=_0x1976fc[_0xb542('0xb')];_0x83a954=_0x1976fc['rows'];return getRealtimeQueues(_0xbd6b09,_0x43d15d);})['then'](function(_0x1da033){_0x2143ed=_0x1da033[_0xb542('0x9c')];return getRealtimeAgents();})[_0xb542('0x15')](function(_0x129b7d){_0x28cff4=_0x129b7d['rows'];if(_0x43d15d!=_0xb542('0x18'))return;return getRealtimeVoiceQueueChannels();})[_0xb542('0x15')](function(_0x446c55){_0x1bde99=_0x446c55?_0x446c55[_0xb542('0x9c')]:[];return initializeQueues(_0x83a954,_0x2143ed,_0x43d15d,_0xbd6b09[_0xb542('0x8b')][_0xb542('0x91')]);})[_0xb542('0x15')](function(_0x373fff){var _0x1ab043=_0x373fff[_0xb542('0x37')](function(_0x3f0208){if(_0x43d15d===_0xb542('0x18'))return getVoiceQueueAgents(_0x3f0208,_0x83a954,_0x28cff4,_0x1bde99);else return getQueueAgents(_0x3f0208,_0x28cff4,_0x43d15d);});return Promise['all'](_0x1ab043);})[_0xb542('0x15')](function(_0x5c844e){_0x1990cd[_0xb542('0x9c')]=_0x5c844e;return _0x1990cd;})[_0xb542('0x15')](respondWithFilteredResult(_0x4c545f,_0x5eb89c))[_0xb542('0x1c')](handleError(_0x4c545f,null));};