Built motion from commit e0fa946e.|2.6.5
[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 _0x02f4=['catch','loggedIn','waiting','talking','paused','push','pTalking','originated','message','dialActive','Trunk','startPredictive','startProgressive','erlangCalls','erlangAbandonmentRate','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','map','get','agents','loggedInDb','available','busy','find','pick','filter','queue','length','connectedlinenum','internal','toString','getMembers','UserId','online','voiceStatus','startCase','findAll','QueueId','unknown','unavailable','ringing','chatPause','mailPause','openchannelPause','smsPause','voicePause','whatsappPause','every','idle','pause','chatStatus','openchannelStatus','smsStatus','*pause','mail','sms','openchannel','fax','whatsapp','includes','Invalid\x20channel','toLowerCase','findOne','getAgents','uniq','value','split','fields','startsWith','DESC','ASC','sort','globalStatus','pauseType','userpic','lastLoginAt','lastPauseAt','faxPause','openchannelCapacity','smsCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','mailStatus','whatsappStatus','faxStatus','openchannelStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','routealias','resolve','query','channel','join','order','globalQueueFilter','Queue','User','fieldName','type','role','agent','raw','isEmpty','where','user','userProfileId','nolimit','UserProfile','getResources','findAndCountAll','rows','omit','globalStatusFilter','pauseTypeFilter','getQueues','key','getOptions','QueueCampaigns','all','util','lodash','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','undefined','limit','count','offset','status','set','Content-Range','stack','name','send','Agents','then','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','request','merge','voice','Queues','format','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels'];(function(_0x4cc242,_0x3cc198){var _0x19b778=function(_0x2a2698){while(--_0x2a2698){_0x4cc242['push'](_0x4cc242['shift']());}};_0x19b778(++_0x3cc198);}(_0x02f4,0x1ca));var _0x402f=function(_0x19950b,_0x53d0d7){_0x19950b=_0x19950b-0x0;var _0x3c6b41=_0x02f4[_0x19950b];return _0x3c6b41;};'use strict';var util=require(_0x402f('0x0'));var _=require(_0x402f('0x1'));var jayson=require(_0x402f('0x2'));var qs=require(_0x402f('0x3'));var logger=require(_0x402f('0x4'))(_0x402f('0x5'));var db=require(_0x402f('0x6'))['db'];var amiClient=jayson[_0x402f('0x7')][_0x402f('0x8')]({'port':0x232a});var routingClient=jayson[_0x402f('0x7')][_0x402f('0x8')]({'port':0x232c});function respondWithFilteredResult(_0x26163b,_0x3bb076){return function(_0x32ef06){if(_0x32ef06){var _0x3a57d2=typeof _0x3bb076['offset']===_0x402f('0x9')&&typeof _0x3bb076[_0x402f('0xa')]===_0x402f('0x9');var _0x4fdf54=_0x32ef06[_0x402f('0xb')];var _0x14d149=_0x3a57d2?0x0:_0x3bb076[_0x402f('0xc')];var _0x5838a1=_0x3a57d2?_0x32ef06[_0x402f('0xb')]:_0x3bb076['offset']+_0x3bb076['limit'];var _0x47f3f5;if(_0x5838a1>=_0x4fdf54){_0x5838a1=_0x4fdf54;_0x47f3f5=0xc8;}else{_0x47f3f5=0xce;}_0x26163b[_0x402f('0xd')](_0x47f3f5);return _0x26163b[_0x402f('0xe')](_0x402f('0xf'),_0x14d149+'-'+_0x5838a1+'/'+_0x4fdf54)['json'](_0x32ef06);}return null;};}function handleError(_0x3d0b0a,_0x19e430){_0x19e430=_0x19e430||0x1f4;return function(_0x13ea2b){logger['error'](_0x13ea2b[_0x402f('0x10')]);if(_0x13ea2b[_0x402f('0x11')]){delete _0x13ea2b[_0x402f('0x11')];}_0x3d0b0a[_0x402f('0xd')](_0x19e430)[_0x402f('0x12')](_0x13ea2b);};}function getRealtimeAgents(){return new Promise(function(_0x6c35e0,_0x4bab32){return amiClient['request'](_0x402f('0x13'),{})[_0x402f('0x14')](function(_0x48e11a){if(_0x48e11a[_0x402f('0x15')])throw new Error(_0x402f('0x16'));var _0x57f749=_0x48e11a[_0x402f('0x17')];return routingClient[_0x402f('0x18')](_0x402f('0x13'),{})[_0x402f('0x14')](function(_0x397724){if(_0x397724['error'])throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)');var _0x123825=_0x397724[_0x402f('0x17')];return _0x6c35e0(_[_0x402f('0x19')]({},_0x57f749,_0x123825));});})['catch'](function(_0x242267){_0x4bab32(_0x242267);});});}function getRealtimeQueues(_0x55dc66,_0x6d02f4){return new Promise(function(_0x427a70,_0x599bce){var _0x1c8875=_0x6d02f4===_0x402f('0x1a')?amiClient:routingClient;return _0x1c8875[_0x402f('0x18')](_['startCase'](_0x6d02f4)+_0x402f('0x1b'),_0x55dc66)['then'](function(_0xb9bd72){if(_0xb9bd72['error'])throw new Error(util[_0x402f('0x1c')](_0x402f('0x1d'),_0x6d02f4));return _0x427a70(_0xb9bd72[_0x402f('0x17')]);})['catch'](function(_0x275650){_0x599bce(_0x275650);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x12af02,_0x4e81f2){return amiClient[_0x402f('0x18')]('VoiceQueuesChannels',{})[_0x402f('0x14')](function(_0x11809f){if(_0x11809f['error'])throw new Error(_0x402f('0x1e'));return _0x12af02(_0x11809f[_0x402f('0x17')]);})[_0x402f('0x1f')](function(_0x196be8){_0x4e81f2(_0x196be8);});});}function initializeQueues(_0x547fec,_0x88e766,_0x41a4e0,_0x56bde3){var _0x623528=[_0x402f('0x20'),'available',_0x402f('0x21'),_0x402f('0x22'),_0x402f('0x23')];if(_0x41a4e0==='voice'&&_0x56bde3==='outbound'){_0x623528[_0x402f('0x24')](_0x402f('0x25'),_0x402f('0x26'),_0x402f('0x27'),_0x402f('0x28'),'dialMethod',_0x402f('0x29'),_0x402f('0x2a'),_0x402f('0x2b'),_0x402f('0x2c'),'erlangCallToSecond',_0x402f('0x2d'),'erlangBusyFactor',_0x402f('0x2e'),_0x402f('0x2f'),_0x402f('0x30'),_0x402f('0x31'),'predictiveIntervalTotalCalls',_0x402f('0x32'),_0x402f('0x33'),_0x402f('0x34'),_0x402f('0x35'),_0x402f('0x36'));}return _0x547fec[_0x402f('0x37')](function(_0x10d8b5){var _0x290bb1=_0x10d8b5[_0x402f('0x38')]({'plain':!![]});_0x290bb1[_0x402f('0x39')]=[];_0x290bb1['paused']=0x0;_0x290bb1[_0x402f('0x3a')]=0x0;_0x290bb1['loggedIn']=0x0;_0x290bb1[_0x402f('0x3b')]=0x0;_0x290bb1[_0x402f('0x21')]=0x0;if(_0x41a4e0===_0x402f('0x1a')){_0x290bb1['talking']=0x0;_0x290bb1[_0x402f('0x3c')]=0x0;if(_0x56bde3==='outbound'){_0x290bb1['pTalking']=0x0;_0x290bb1[_0x402f('0x26')]=0x0;}}var _0x153c0f=_[_0x402f('0x3d')](_0x88e766,['id',_0x290bb1['id']]);if(_0x153c0f)_[_0x402f('0x19')](_0x290bb1,_[_0x402f('0x3e')](_0x153c0f,_0x623528));return _0x290bb1;});}function updateAgentVoiceStatus(_0x43382c,_0x2ff2ef,_0x1a5ca7){var _0x540819=_[_0x402f('0x3f')](_0x1a5ca7,[_0x402f('0x40'),_0x2ff2ef[_0x402f('0x11')]]);if(_0x540819[_0x402f('0x41')]===0x0)return _0x43382c[_0x402f('0x3c')]=!![];if(_['some'](_0x540819,[_0x402f('0x42'),_0x43382c[_0x402f('0x43')][_0x402f('0x44')]()]))return _0x43382c[_0x402f('0x22')]=!![];if(!_0x43382c[_0x402f('0x22')])return _0x43382c['busy']=!![];}function getVoiceQueueAgents(_0x58ee7a,_0xba1b90,_0x4d8b3f,_0x1ad471){var _0x239d41=_[_0x402f('0x3d')](_0xba1b90,['id',_0x58ee7a['id']]);if(!_0x239d41)return _0x58ee7a;return _0x239d41[_0x402f('0x45')]({'raw':!![]})['then'](function(_0x4e7552){for(var _0x11d001=0x0;_0x11d001<_0x4e7552[_0x402f('0x41')];_0x11d001++){var _0x226953=_['find'](_0x4d8b3f,['id',_0x4e7552[_0x11d001][_0x402f('0x46')]]);if(!_0x226953){_0x226953={'id':_0x4e7552[_0x11d001]['UserId'],'name':_0x4e7552[_0x11d001][_0x402f('0x46')],'accountcode':'','online':![]};}var _0x17976b={'id':_0x226953['id'],'name':_0x226953[_0x402f('0x11')],'internal':_0x226953['accountcode'],'online':Boolean(_0x226953[_0x402f('0x47')]),'paused':Boolean(_0x4e7552[_0x11d001]['paused'])};if(_0x226953[_0x402f('0x48')]===_0x402f('0x22'))updateAgentVoiceStatus(_0x17976b,_0x58ee7a,_0x1ad471);if(_0x17976b['online'])_0x58ee7a['loggedInDb']++;if(_0x17976b['busy'])_0x58ee7a['busy']++;if(_0x17976b[_0x402f('0x23')]&&!_0x17976b[_0x402f('0x3c')]&&!_0x17976b[_0x402f('0x22')])_0x58ee7a[_0x402f('0x23')]++;_0x58ee7a[_0x402f('0x39')]['push'](_0x17976b);}return _0x58ee7a;});}function getQueueAgents(_0x4dd2d2,_0x545251,_0x45e2d5){var _0xeede2='User'+_[_0x402f('0x49')](_0x45e2d5)+'Queue';var _0x46ffac=_0x45e2d5+'Pause';return db[_0xeede2][_0x402f('0x4a')]({'where':{[_[_0x402f('0x49')](_0x45e2d5)+_0x402f('0x4b')]:_0x4dd2d2['id']},'raw':!![]})[_0x402f('0x14')](function(_0x20024e){for(var _0x25509e=0x0;_0x25509e<_0x20024e[_0x402f('0x41')];_0x25509e++){var _0x3da75b=_[_0x402f('0x3d')](_0x545251,['id',_0x20024e[_0x25509e][_0x402f('0x46')]]);if(!_0x3da75b){_0x3da75b={'id':_0x20024e[_0x25509e][_0x402f('0x46')],'name':_0x20024e[_0x25509e][_0x402f('0x46')],'online':![],['pauseField']:![]};}var _0x42078f={'id':_0x3da75b['id'],'name':_0x3da75b[_0x402f('0x11')],'online':Boolean(_0x3da75b[_0x402f('0x47')]),'paused':Boolean(_0x3da75b[_0x46ffac])};if(_0x42078f[_0x402f('0x47')])_0x4dd2d2[_0x402f('0x3a')]++;_0x4dd2d2[_0x402f('0x39')][_0x402f('0x24')](_0x42078f);}return _0x4dd2d2;});}function isIdle(_0x1283a2){return _0x1283a2==='idle'||_0x1283a2===_0x402f('0x4c')||_0x1283a2===_0x402f('0x4d')||_0x1283a2===_0x402f('0x4e')||_['isNil'](_0x1283a2);}function isAgentPaused(_0x16ef52,_0x45e0a2){var _0x4ceb14=[_0x16ef52[_0x402f('0x4f')],_0x16ef52['faxPause'],_0x16ef52[_0x402f('0x50')],_0x16ef52[_0x402f('0x51')],_0x16ef52[_0x402f('0x52')],_0x16ef52[_0x402f('0x53')],_0x16ef52[_0x402f('0x54')]];if(!_0x45e0a2)return _[_0x402f('0x55')](_0x4ceb14);var _0x21b8c9=_[_0x402f('0x3f')](_0x4ceb14);return _0x21b8c9[_0x402f('0x41')]>0x0&&_0x21b8c9['length']<_0x4ceb14[_0x402f('0x41')]?!![]:![];}function isAgentIdle(_0x3fefdb){if(_0x3fefdb[_0x402f('0x48')]!==_0x402f('0x56')&&_0x3fefdb['voicePause']){_0x3fefdb[_0x402f('0x48')]=_0x402f('0x57');return![];}return _['every']([_0x3fefdb[_0x402f('0x58')],_0x3fefdb['faxStatus'],_0x3fefdb['mailStatus'],_0x3fefdb[_0x402f('0x59')],_0x3fefdb[_0x402f('0x5a')],_0x3fefdb[_0x402f('0x48')],_0x3fefdb['whatsappStatus']],isIdle);}function getAgentStatus(_0x414c87){var _0x3340ee=_0x402f('0x4c');if(isAgentPaused(_0x414c87))_0x3340ee=_0x402f('0x57');else if(isAgentPaused(_0x414c87,!![]))_0x3340ee=_0x402f('0x5b');else if(isAgentIdle(_0x414c87))_0x3340ee=_0x402f('0x56');else _0x3340ee=_0x402f('0x3c');return _0x3340ee;}function validateChannel(_0x1df989){var _0x5a70fc=[_0x402f('0x5c'),'chat',_0x402f('0x5d'),_0x402f('0x5e'),_0x402f('0x5f'),_0x402f('0x60'),'voice'];if(!_[_0x402f('0x61')](_0x5a70fc,_0x1df989['toLowerCase']()))throw new Error(_0x402f('0x62'));return _0x1df989[_0x402f('0x63')]();}function getFilteredAgentIds(_0x5bafae,_0x3e4191){var _0x41572c=_['isArray'](_0x5bafae)?_0x5bafae:[_0x5bafae];var _0x3705b2=_['map'](_0x41572c,function(_0x50d456){return db[_0x3e4191][_0x402f('0x64')]({'where':{'name':_0x50d456}})['then'](function(_0x32014f){if(!_0x32014f)return[];return _0x32014f[_0x402f('0x65')]({'attributes':['id'],'raw':!![]});});});return Promise['all'](_0x3705b2)[_0x402f('0x14')](function(_0x37f1aa){var _0x30ec81=_(_0x37f1aa)['flatten']()['map']('id')[_0x402f('0x66')]()[_0x402f('0x67')]();return _0x30ec81;});}function getUpdatedSortOptions(_0x4bf89f){var _0x1db964={'fields':[],'order':null};var _0x11a2a3=_0x4bf89f[_0x402f('0x68')](',');_0x1db964[_0x402f('0x69')]=_[_0x402f('0x3f')](_0x11a2a3,function(_0x562bc8){if(!_0x562bc8[_0x402f('0x61')]('globalStatus'))return!![];_0x1db964['order']=_[_0x402f('0x6a')](_0x562bc8,'-')?_0x402f('0x6b'):_0x402f('0x6c');return![];});return _0x1db964;}function orderAgentsByStatus(_0x4d3104,_0x5712e3){return _0x4d3104[_0x402f('0x6d')](function(_0x116b58,_0x107344){if(_0x116b58[_0x402f('0x6e')]===_0x107344[_0x402f('0x6e')]&&_0x116b58[_0x402f('0x6e')]===_0x402f('0x57')){if(_0x5712e3===_0x402f('0x6b'))return(_0x116b58[_0x402f('0x6f')]||'')<(_0x107344[_0x402f('0x6f')]||'')?0x1:-0x1;return _0x116b58[_0x402f('0x6f')]<_0x107344[_0x402f('0x6f')]?-0x1:0x1;}else{if(_0x5712e3===_0x402f('0x6b'))return _0x116b58[_0x402f('0x6e')]<_0x107344[_0x402f('0x6e')]?0x1:-0x1;return _0x116b58[_0x402f('0x6e')]<_0x107344['globalStatus']?-0x1:0x1;}});}exports[_0x402f('0x65')]=function(_0x1edde9,_0x3c087c){var _0x52ece3={'count':0x0,'rows':[]},_0x24343c={},_0x2d9084,_0x2d4ac4,_0x272cda,_0x468449,_0x2f21fd=[_0x402f('0x70'),_0x402f('0x47'),_0x402f('0x71'),_0x402f('0x72'),'pauseType',_0x402f('0x72'),_0x402f('0x43'),'address',_0x402f('0x4f'),'openchannelPause','mailPause','smsPause',_0x402f('0x54'),_0x402f('0x73'),_0x402f('0x53'),'chatCapacity',_0x402f('0x74'),'mailCapacity',_0x402f('0x75'),'whatsappCapacity',_0x402f('0x76'),_0x402f('0x77'),_0x402f('0x78'),'mailCurrentCapacity','smsCurrentCapacity',_0x402f('0x79'),_0x402f('0x7a'),_0x402f('0x58'),_0x402f('0x59'),_0x402f('0x7b'),'smsStatus',_0x402f('0x7c'),_0x402f('0x7d'),'voiceStatus','chatStatusTime',_0x402f('0x7e'),'mailStatusTime','smsStatusTime','whatsappStatusTime',_0x402f('0x7f'),_0x402f('0x80'),_0x402f('0x40'),_0x402f('0x81'),_0x402f('0x82'),_0x402f('0x83'),'phoneBarEnableAutomaticScreenRecording',_0x402f('0x84')],_0x53a6df=[_0x402f('0x4f'),_0x402f('0x51'),_0x402f('0x50'),'smsPause',_0x402f('0x54'),_0x402f('0x73'),_0x402f('0x53'),_0x402f('0x47')];Promise[_0x402f('0x85')]()[_0x402f('0x14')](function(){if(_0x1edde9[_0x402f('0x86')][_0x402f('0x87')])_0x2d9084=validateChannel(_0x1edde9[_0x402f('0x86')][_0x402f('0x87')]);if(!_0x1edde9[_0x402f('0x86')]['sort']||!_0x1edde9[_0x402f('0x86')][_0x402f('0x6d')]['includes'](_0x402f('0x6e')))return;var _0x4ade0b=getUpdatedSortOptions(_0x1edde9['query']['sort']);_0x1edde9[_0x402f('0x86')]['sort']=_0x4ade0b[_0x402f('0x69')][_0x402f('0x88')](',');_0x2d4ac4=_0x4ade0b[_0x402f('0x89')];})[_0x402f('0x14')](function(){if(!_0x1edde9[_0x402f('0x86')][_0x402f('0x8a')])return[];var _0x393a4c=_[_0x402f('0x49')](_0x2d9084)+_0x402f('0x8b');return getFilteredAgentIds(_0x1edde9['query'][_0x402f('0x8a')],_0x393a4c);})[_0x402f('0x14')](function(_0x9c590){var _0x2f2913=_[_0x402f('0x37')](db[_0x402f('0x8c')]['rawAttributes'],function(_0x3e3047){return{'name':_0x3e3047[_0x402f('0x8d')],'type':_0x3e3047[_0x402f('0x8e')]['key']};});_0x1edde9[_0x402f('0x86')][_0x402f('0x8f')]=_0x402f('0x90');_0x1edde9[_0x402f('0x86')][_0x402f('0x47')]=!![];_0x24343c=qs['getOptions'](_0x2f2913,_0x1edde9);_0x24343c[_0x402f('0x91')]=!![];if(!_[_0x402f('0x92')](_0x9c590)){_0x24343c[_0x402f('0x93')]=_['merge'](_0x24343c[_0x402f('0x93')],{'$and':[{'id':{'$in':_0x9c590}}]});}else if(!_['isEmpty'](_0x1edde9[_0x402f('0x86')][_0x402f('0x8a')])){return _0x52ece3;}if(_0x1edde9['user']['role']===_0x402f('0x94')){var _0x586b66={'params':{'id':_0x1edde9['user'][_0x402f('0x95')]},'query':{'section':_0x402f('0x13'),'role':'agent','online':!![],'nolimit':_0x1edde9[_0x402f('0x86')][_0x402f('0x96')],'sort':_0x1edde9[_0x402f('0x86')][_0x402f('0x6d')],'filter':_0x1edde9['query'][_0x402f('0x3f')],'raw':!![],'ids':_0x9c590}};return db[_0x402f('0x97')][_0x402f('0x98')](_0x586b66);}return db[_0x402f('0x8c')][_0x402f('0x99')](_0x24343c);})[_0x402f('0x14')](function(_0xb7e749){_0x52ece3[_0x402f('0xb')]=_0xb7e749[_0x402f('0xb')];_0x272cda=_0xb7e749[_0x402f('0x9a')];return getRealtimeAgents();})['then'](function(_0x32d589){_0x468449=_0x32d589[_0x402f('0x9a')];return _0x272cda[_0x402f('0x37')](function(_0x1f3da1){var _0x4e5262=_[_0x402f('0x3d')](_0x468449,['id',_0x1f3da1['id']]);if(_0x4e5262)_['merge'](_0x1f3da1,_['pick'](_[_0x402f('0x9b')](_0x4e5262,_0x53a6df),_0x2f21fd));_0x1f3da1[_0x402f('0x6e')]=getAgentStatus(_0x1f3da1);return _0x1f3da1;});})[_0x402f('0x14')](function(_0x20ee76){var _0x1f9ea8;if(_0x1edde9[_0x402f('0x86')][_0x402f('0x9c')]){_0x1f9ea8=_[_0x402f('0x3f')](_0x20ee76,[_0x402f('0x6e'),_0x1edde9[_0x402f('0x86')][_0x402f('0x9c')]]);if(_0x1edde9[_0x402f('0x86')]['pauseTypeFilter']){_0x1f9ea8=_['filter'](_0x1f9ea8,[_0x402f('0x6f'),_0x1edde9[_0x402f('0x86')][_0x402f('0x9d')]]);}}if(_0x1f9ea8)_0x20ee76=_0x1f9ea8;if(!_0x2d4ac4)return _0x20ee76;return orderAgentsByStatus(_0x20ee76,_0x2d4ac4);})[_0x402f('0x14')](function(_0x41a929){_0x52ece3[_0x402f('0x9a')]=_0x41a929;return _0x52ece3;})[_0x402f('0x14')](respondWithFilteredResult(_0x3c087c,_0x24343c))[_0x402f('0x1f')](handleError(_0x3c087c,null));};exports[_0x402f('0x9e')]=function(_0x2ca548,_0x44ec58){var _0x503782={'count':0x0,'rows':[]},_0x538910={},_0x20be5d,_0x50ab27,_0x1b4f50,_0x56fcec,_0x4bb80b;Promise[_0x402f('0x85')]()[_0x402f('0x14')](function(){if(_0x2ca548[_0x402f('0x86')][_0x402f('0x87')])_0x20be5d=validateChannel(_0x2ca548[_0x402f('0x86')]['channel']);var _0x29a44d=_[_0x402f('0x49')](_0x20be5d)+_0x402f('0x8b');var _0x48cd0d=_[_0x402f('0x37')](db[_0x29a44d]['rawAttributes'],function(_0x160112){return{'name':_0x160112['fieldName'],'type':_0x160112['type'][_0x402f('0x9f')]};});_0x538910=qs[_0x402f('0xa0')](_0x48cd0d,_0x2ca548);if(_0x2ca548['user'][_0x402f('0x8f')]===_0x402f('0x94')){var _0x254235={'params':{'id':_0x2ca548[_0x402f('0x94')]['userProfileId']},'query':{'section':_0x20be5d===_0x402f('0x1a')&&_0x2ca548['query']['type']==='outbound'?_0x402f('0xa1'):_[_0x402f('0x49')](_0x20be5d)+_0x402f('0x1b'),'type':_0x2ca548[_0x402f('0x86')][_0x402f('0x8e')],'nolimit':!![],'sort':_0x402f('0x11'),'filter':_0x2ca548[_0x402f('0x86')][_0x402f('0x3f')]}};return db[_0x402f('0x97')][_0x402f('0x98')](_0x254235);}return db[_0x29a44d][_0x402f('0x99')](_0x538910);})['then'](function(_0x387380){_0x503782['count']=_0x387380[_0x402f('0xb')];_0x50ab27=_0x387380[_0x402f('0x9a')];return getRealtimeQueues(_0x2ca548,_0x20be5d);})[_0x402f('0x14')](function(_0x51cf13){_0x56fcec=_0x51cf13[_0x402f('0x9a')];return getRealtimeAgents();})[_0x402f('0x14')](function(_0x2bd8f4){_0x1b4f50=_0x2bd8f4[_0x402f('0x9a')];if(_0x20be5d!=_0x402f('0x1a'))return;return getRealtimeVoiceQueueChannels();})['then'](function(_0x388626){_0x4bb80b=_0x388626?_0x388626['rows']:[];return initializeQueues(_0x50ab27,_0x56fcec,_0x20be5d,_0x2ca548['query'][_0x402f('0x8e')]);})[_0x402f('0x14')](function(_0x212f20){var _0x19c602=_0x212f20['map'](function(_0x4fb59a){if(_0x20be5d===_0x402f('0x1a'))return getVoiceQueueAgents(_0x4fb59a,_0x50ab27,_0x1b4f50,_0x4bb80b);else return getQueueAgents(_0x4fb59a,_0x1b4f50,_0x20be5d);});return Promise[_0x402f('0xa2')](_0x19c602);})[_0x402f('0x14')](function(_0x3cc1c3){_0x503782[_0x402f('0x9a')]=_0x3cc1c3;return _0x503782;})[_0x402f('0x14')](respondWithFilteredResult(_0x44ec58,_0x538910))[_0x402f('0x1f')](handleError(_0x44ec58,null));};