Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / realtime / realtime.controller.js
index 2627637..e4459e3 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xcaf1=['predictiveIntervalAvgTalktime','map','get','agents','paused','loggedInDb','waiting','find','pick','queue','length','connectedlinenum','internal','toString','talking','getMembers','UserId','accountcode','voiceStatus','online','busy','User','Pause','findAll','QueueId','getChannels','includes','Invalid\x20channel','toLowerCase','getAgents','query','globalQueueFilter','globalStatusFilter','pauseTypeFilter','pause','*pause','resolve','channel','sort','globalStatus','validateSortParameter','getUpdatedSortOptions','fields','join','order','getAgentIdsByQueues','fieldName','type','key','role','agent','raw','sequelize','literal','forEach','where','user','userProfileId','extraQueryConditions','assign','filterAgentAttributes','merge','Status','sortAgentsByStatus','getQueues','rawAttributes','getOptions','filter','UserProfile','findAndCountAll','rows','getRealtimeAgents','all','lodash','jayson/promise','../../components/realtime/agents','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','offset','limit','undefined','count','status','Content-Range','error','name','send','request','startCase','Queues','then','format','result','catch','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','voice','outbound','push','pTalking','originated','dialActive','Trunk','erlangAbandonmentRate','dialPredictiveInterval','dialPredictiveIntervalMinThreshold','predictiveIntervalTotalCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit'];(function(_0x3846ef,_0x3ff934){var _0x5c0ab0=function(_0x1519f4){while(--_0x1519f4){_0x3846ef['push'](_0x3846ef['shift']());}};_0x5c0ab0(++_0x3ff934);}(_0xcaf1,0x19f));var _0x1caf=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xcaf1[_0x3dd15e];return _0x231fd0;};'use strict';var util=require('util');var _=require(_0x1caf('0x0'));var jayson=require(_0x1caf('0x1'));var rta=require(_0x1caf('0x2'));var qs=require(_0x1caf('0x3'));var utils=require('../../config/utils');var logger=require(_0x1caf('0x4'))(_0x1caf('0x5'));var db=require(_0x1caf('0x6'))['db'];var amiClient=jayson[_0x1caf('0x7')][_0x1caf('0x8')]({'port':0x232a});var routingClient=jayson[_0x1caf('0x7')][_0x1caf('0x8')]({'port':0x232c});function respondWithFilteredResult(_0x24abf2,_0x3e7589){return function(_0x584244){if(_0x584244){var _0x2027d7=typeof _0x3e7589[_0x1caf('0x9')]==='undefined'&&typeof _0x3e7589[_0x1caf('0xa')]===_0x1caf('0xb');var _0x297799=_0x584244[_0x1caf('0xc')];var _0xe6f8d3=_0x2027d7?0x0:_0x3e7589[_0x1caf('0x9')];var _0x1a6721=_0x2027d7?_0x584244[_0x1caf('0xc')]:_0x3e7589[_0x1caf('0x9')]+_0x3e7589[_0x1caf('0xa')];var _0x232ba4;if(_0x1a6721>=_0x297799){_0x1a6721=_0x297799;_0x232ba4=0xc8;}else{_0x232ba4=0xce;}_0x24abf2[_0x1caf('0xd')](_0x232ba4);return _0x24abf2['set'](_0x1caf('0xe'),_0xe6f8d3+'-'+_0x1a6721+'/'+_0x297799)['json'](_0x584244);}return null;};}function handleError(_0x2fae22,_0x17cdcd){_0x17cdcd=_0x17cdcd||0x1f4;return function(_0x25bbdd){logger[_0x1caf('0xf')](_0x25bbdd['stack']);if(_0x25bbdd['name']){delete _0x25bbdd[_0x1caf('0x10')];}_0x2fae22['status'](_0x17cdcd)[_0x1caf('0x11')](_0x25bbdd);};}function getRealtimeQueues(_0x2423e1,_0xfa824f){return new Promise(function(_0x1778b9,_0x2918c4){var _0x2c1492=_0xfa824f==='voice'?amiClient:routingClient;return _0x2c1492[_0x1caf('0x12')](_[_0x1caf('0x13')](_0xfa824f)+_0x1caf('0x14'),_0x2423e1)[_0x1caf('0x15')](function(_0xa3731c){if(_0xa3731c[_0x1caf('0xf')])throw new Error(util[_0x1caf('0x16')]('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0xfa824f));return _0x1778b9(_0xa3731c[_0x1caf('0x17')]);})[_0x1caf('0x18')](function(_0x2020a5){_0x2918c4(_0x2020a5);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x1964e7,_0x2da6df){return amiClient[_0x1caf('0x12')](_0x1caf('0x19'),{})[_0x1caf('0x15')](function(_0x3b5fb0){if(_0x3b5fb0['error'])throw new Error(_0x1caf('0x1a'));return _0x1964e7(_0x3b5fb0[_0x1caf('0x17')]);})[_0x1caf('0x18')](function(_0x3af1ba){_0x2da6df(_0x3af1ba);});});}function initializeQueues(_0x2e74cf,_0x5a81f3,_0x3b5932,_0x4db53a){var _0x43f782=[_0x1caf('0x1b'),'available','waiting','talking','paused'];if(_0x3b5932===_0x1caf('0x1c')&&_0x4db53a===_0x1caf('0x1d')){_0x43f782[_0x1caf('0x1e')](_0x1caf('0x1f'),_0x1caf('0x20'),'message',_0x1caf('0x21'),'dialMethod',_0x1caf('0x22'),'startPredictive','startProgressive','erlangCalls','erlangCallToSecond',_0x1caf('0x23'),'erlangBusyFactor',_0x1caf('0x24'),'dialPredictiveIntervalMaxThreshold',_0x1caf('0x25'),'predictiveIntervalAvailable',_0x1caf('0x26'),'predictiveIntervalAnsweredCalls',_0x1caf('0x27'),_0x1caf('0x28'),'predictiveIntervalAvgHoldtime',_0x1caf('0x29'));}return _0x2e74cf[_0x1caf('0x2a')](function(_0x5f5a95){var _0x515c00=_0x5f5a95[_0x1caf('0x2b')]({'plain':!![]});_0x515c00[_0x1caf('0x2c')]=[];_0x515c00[_0x1caf('0x2d')]=0x0;_0x515c00[_0x1caf('0x2e')]=0x0;_0x515c00[_0x1caf('0x1b')]=0x0;_0x515c00['available']=0x0;_0x515c00[_0x1caf('0x2f')]=0x0;if(_0x3b5932===_0x1caf('0x1c')){_0x515c00['talking']=0x0;_0x515c00['busy']=0x0;if(_0x4db53a===_0x1caf('0x1d')){_0x515c00[_0x1caf('0x1f')]=0x0;_0x515c00['originated']=0x0;}}var _0x3a82da=_[_0x1caf('0x30')](_0x5a81f3,['id',_0x515c00['id']]);if(_0x3a82da)_['merge'](_0x515c00,_[_0x1caf('0x31')](_0x3a82da,_0x43f782));return _0x515c00;});}function updateAgentVoiceStatus(_0x5be624,_0x537a85,_0x14ef74){var _0x1dd5c2=_['filter'](_0x14ef74,[_0x1caf('0x32'),_0x537a85['name']]);if(_0x1dd5c2[_0x1caf('0x33')]===0x0)return _0x5be624['busy']=!![];if(_['some'](_0x1dd5c2,[_0x1caf('0x34'),_0x5be624[_0x1caf('0x35')][_0x1caf('0x36')]()]))return _0x5be624[_0x1caf('0x37')]=!![];if(!_0x5be624[_0x1caf('0x37')])return _0x5be624['busy']=!![];}function getVoiceQueueAgents(_0x458330,_0x56c7b1,_0x159a59,_0x58bf0b){var _0x44bc72=_['find'](_0x56c7b1,['id',_0x458330['id']]);if(!_0x44bc72)return _0x458330;return _0x44bc72[_0x1caf('0x38')]({'raw':!![]})[_0x1caf('0x15')](function(_0xffb099){for(var _0x441779=0x0;_0x441779<_0xffb099[_0x1caf('0x33')];_0x441779++){var _0x1a2d96=_[_0x1caf('0x30')](_0x159a59,['id',_0xffb099[_0x441779][_0x1caf('0x39')]]);if(!_0x1a2d96){_0x1a2d96={'id':_0xffb099[_0x441779][_0x1caf('0x39')],'name':_0xffb099[_0x441779][_0x1caf('0x39')],'accountcode':'','online':![]};}var _0x2e2873={'id':_0x1a2d96['id'],'name':_0x1a2d96[_0x1caf('0x10')],'internal':_0x1a2d96[_0x1caf('0x3a')],'online':Boolean(_0x1a2d96['online']),'paused':Boolean(_0xffb099[_0x441779]['paused'])};if(_0x1a2d96[_0x1caf('0x3b')]===_0x1caf('0x37'))updateAgentVoiceStatus(_0x2e2873,_0x458330,_0x58bf0b);if(_0x2e2873[_0x1caf('0x3c')])_0x458330['loggedInDb']++;if(_0x2e2873[_0x1caf('0x3d')])_0x458330[_0x1caf('0x3d')]++;if(_0x2e2873['paused']&&!_0x2e2873['busy']&&!_0x2e2873[_0x1caf('0x37')])_0x458330[_0x1caf('0x2d')]++;_0x458330[_0x1caf('0x2c')][_0x1caf('0x1e')](_0x2e2873);}return _0x458330;});}function getQueueAgents(_0x54d4ae,_0x2f63b9,_0x157ff8){var _0x5e8c31=_0x1caf('0x3e')+_[_0x1caf('0x13')](_0x157ff8)+'Queue';var _0x1db0e5=_0x157ff8+_0x1caf('0x3f');return db[_0x5e8c31][_0x1caf('0x40')]({'where':{[_[_0x1caf('0x13')](_0x157ff8)+_0x1caf('0x41')]:_0x54d4ae['id']},'raw':!![]})[_0x1caf('0x15')](function(_0xa6c9d4){for(var _0x1f3d3c=0x0;_0x1f3d3c<_0xa6c9d4[_0x1caf('0x33')];_0x1f3d3c++){var _0x599371=_[_0x1caf('0x30')](_0x2f63b9,['id',_0xa6c9d4[_0x1f3d3c][_0x1caf('0x39')]]);if(!_0x599371){_0x599371={'id':_0xa6c9d4[_0x1f3d3c][_0x1caf('0x39')],'name':_0xa6c9d4[_0x1f3d3c][_0x1caf('0x39')],'online':![],['pauseField']:![]};}var _0x4624de={'id':_0x599371['id'],'name':_0x599371[_0x1caf('0x10')],'online':Boolean(_0x599371[_0x1caf('0x3c')]),'paused':Boolean(_0x599371[_0x1db0e5])};if(_0x4624de[_0x1caf('0x3c')])_0x54d4ae[_0x1caf('0x2e')]++;_0x54d4ae[_0x1caf('0x2c')][_0x1caf('0x1e')](_0x4624de);}return _0x54d4ae;});}function validateChannel(_0x378407){var _0x196c16=utils[_0x1caf('0x42')]();if(!_[_0x1caf('0x43')](_0x196c16,_0x378407['toLowerCase']()))throw new Error(_0x1caf('0x44'));return _0x378407[_0x1caf('0x45')]();}exports[_0x1caf('0x46')]=function(_0x1182c1,_0x4d1ba3){var _0x9f2120={'count':0x0,'rows':[]};var _0x3b83ed={};var _0x4222e1;var _0x32ebb7;var _0x23bb1d;var _0x308939;var _0x14f727=utils[_0x1caf('0x42')]();var _0x4564cb=_0x1182c1[_0x1caf('0x47')][_0x1caf('0x48')];var _0x1330fe=_0x1182c1['query'][_0x1caf('0x49')];var _0x2530f1=_0x1182c1[_0x1caf('0x47')][_0x1caf('0x4a')];var _0x4f4d6c=_0x1330fe===_0x1caf('0x4b')||_0x1330fe===_0x1caf('0x4c')?!![]:![];var _0x5823d=[];var _0x2f4fa7;Promise[_0x1caf('0x4d')]()[_0x1caf('0x15')](function(){if(_0x1182c1[_0x1caf('0x47')]['channel']){_0x4222e1=validateChannel(_0x1182c1[_0x1caf('0x47')][_0x1caf('0x4e')]);}if(!_0x1182c1[_0x1caf('0x47')]['sort']||!_0x1182c1[_0x1caf('0x47')][_0x1caf('0x4f')][_0x1caf('0x43')](_0x1caf('0x50'))){_0x1182c1['query'][_0x1caf('0x4f')]=rta[_0x1caf('0x51')](_0x1182c1[_0x1caf('0x47')]['sort']);return;}var _0x3ce663=rta[_0x1caf('0x52')](_0x1182c1[_0x1caf('0x47')][_0x1caf('0x4f')]);_0x1182c1['query'][_0x1caf('0x4f')]=_0x3ce663[_0x1caf('0x53')][_0x1caf('0x54')](',');_0x32ebb7=_0x3ce663[_0x1caf('0x55')];})[_0x1caf('0x15')](function(){if(!_0x4564cb){return[];}return rta[_0x1caf('0x56')](_0x4564cb,_0x4222e1);})[_0x1caf('0x15')](function(_0x9cd8fe){_0x5823d=_0x9cd8fe;return rta['getRealtimeAgents']();})[_0x1caf('0x15')](function(_0x20753c){_0x308939=_0x20753c['rows'];if((!_0x1330fe||_0x4f4d6c)&&!_0x32ebb7){return _0x5823d;}if(_0x32ebb7&&!_0x1330fe){return rta['getSortedAgentsIdsByStatus'](_0x308939,_0x5823d,_0x32ebb7);}else{return rta['getAgentIdsByStatus'](_0x308939,_0x5823d,_0x1330fe);}})[_0x1caf('0x15')](function(_0x5e73b1){_0x5823d=_0x5e73b1;var _0x3e3bda=![];if(_0x5823d['length']===0x0){if(_0x4564cb||_0x1330fe){_0x3e3bda=!![];}if(_0x4f4d6c){_0x3e3bda=![];}}if(_0x3e3bda){return _0x9f2120;}var _0x4cc160=_[_0x1caf('0x2a')](db[_0x1caf('0x3e')]['rawAttributes'],function(_0x2e0a51){return{'name':_0x2e0a51[_0x1caf('0x57')],'type':_0x2e0a51[_0x1caf('0x58')][_0x1caf('0x59')]};});_0x1182c1[_0x1caf('0x47')][_0x1caf('0x5a')]=_0x1caf('0x5b');_0x1182c1['query'][_0x1caf('0x3c')]=!![];_0x3b83ed=qs['getOptions'](_0x4cc160,_0x1182c1);_0x3b83ed[_0x1caf('0x5c')]=!![];var _0x47ed2e=[];if(_0x5823d[_0x1caf('0x33')]>0x0){_0x47ed2e[_0x1caf('0x1e')]({'id':{'$in':_0x5823d}});if(_0x32ebb7&&!_0x1330fe){_0x2f4fa7=[db[_0x1caf('0x5d')][_0x1caf('0x5e')]('FIELD(id,'+_0x5823d+')')];_0x3b83ed['order']=_0x2f4fa7;}}if(_0x4f4d6c){_0x14f727[_0x1caf('0x5f')](function(_0x52a585){var _0x198a75=!![];if(_0x1330fe===_0x1caf('0x4c')&&_0x4222e1!==_0x52a585){_0x198a75=![];}_0x47ed2e['push']({[_0x52a585+_0x1caf('0x3f')]:_0x198a75});});if(_0x2530f1){_0x47ed2e[_0x1caf('0x1e')]({'pauseType':_0x2530f1});}}else if(_0x1330fe){_0x14f727[_0x1caf('0x5f')](function(_0x1fc8cc){_0x47ed2e[_0x1caf('0x1e')]({[_0x1fc8cc+_0x1caf('0x3f')]:![]});});}_0x3b83ed[_0x1caf('0x60')]=_['merge'](_0x3b83ed[_0x1caf('0x60')],{'$and':_0x47ed2e});if(_0x1182c1['user']['role']===_0x1caf('0x61')){var _0x57327c={'params':{'id':_0x1182c1['user'][_0x1caf('0x62')]},'query':{'section':'Agents','role':_0x1caf('0x5b'),'online':!![],'raw':!![],'ids':_0x5823d,'customSorting':_0x2f4fa7}};if(_0x4f4d6c){_0x57327c[_0x1caf('0x47')][_0x1caf('0x63')]=_0x47ed2e;}_0x57327c[_0x1caf('0x47')]=Object[_0x1caf('0x64')](_0x57327c[_0x1caf('0x47')],_0x1182c1['query']);delete _0x57327c[_0x1caf('0x47')]['id'];return db['UserProfile']['getResources'](_0x57327c);}return db[_0x1caf('0x3e')]['findAndCountAll'](_0x3b83ed);})[_0x1caf('0x15')](function(_0x47e4b0){_0x9f2120['count']=_0x47e4b0[_0x1caf('0xc')];_0x23bb1d=_0x47e4b0['rows'];return _0x23bb1d[_0x1caf('0x2a')](function(_0x5e037b){var _0x33e2d3=_['find'](_0x308939,['id',_0x5e037b['id']]);if(_0x33e2d3){var _0x2d7ccd=rta[_0x1caf('0x65')](_0x33e2d3);_[_0x1caf('0x66')](_0x5e037b,_0x2d7ccd);}_0x5e037b[_0x1caf('0x50')]=rta['getAgentStatus'](_0x5e037b);if(_0x5e037b[_0x1caf('0x50')][_0x1caf('0x43')](_0x1caf('0x4b'))){_0x14f727[_0x1caf('0x5f')](function(_0x3a2aa5){if(_0x5e037b[_0x3a2aa5+_0x1caf('0x3f')]){_0x5e037b[_0x3a2aa5+_0x1caf('0x67')]=_0x1caf('0x4b');}});}return _0x5e037b;});})[_0x1caf('0x15')](function(_0x1d4f11){if(!_0x32ebb7||_0x2f4fa7){return _0x1d4f11;}return rta[_0x1caf('0x68')](_0x1d4f11,_0x32ebb7);})['then'](function(_0xc16165){_0x9f2120['rows']=_0xc16165;return _0x9f2120;})[_0x1caf('0x15')](respondWithFilteredResult(_0x4d1ba3,_0x3b83ed))[_0x1caf('0x18')](handleError(_0x4d1ba3,null));};exports[_0x1caf('0x69')]=function(_0x40c73f,_0x216dbc){var _0x334cd0={'count':0x0,'rows':[]},_0x36d1ed={},_0xd655ac,_0x31bf61,_0x17825a,_0x58da3c,_0x3e9400;Promise[_0x1caf('0x4d')]()[_0x1caf('0x15')](function(){if(_0x40c73f['query']['channel'])_0xd655ac=validateChannel(_0x40c73f[_0x1caf('0x47')][_0x1caf('0x4e')]);var _0x5da945=_[_0x1caf('0x13')](_0xd655ac)+'Queue';var _0xb29d7b=_[_0x1caf('0x2a')](db[_0x5da945][_0x1caf('0x6a')],function(_0x4be959){return{'name':_0x4be959[_0x1caf('0x57')],'type':_0x4be959[_0x1caf('0x58')]['key']};});_0x36d1ed=qs[_0x1caf('0x6b')](_0xb29d7b,_0x40c73f);if(_0x40c73f[_0x1caf('0x61')][_0x1caf('0x5a')]===_0x1caf('0x61')){var _0x10355c={'params':{'id':_0x40c73f[_0x1caf('0x61')][_0x1caf('0x62')]},'query':{'section':_0xd655ac==='voice'&&_0x40c73f[_0x1caf('0x47')][_0x1caf('0x58')]===_0x1caf('0x1d')?'QueueCampaigns':_[_0x1caf('0x13')](_0xd655ac)+_0x1caf('0x14'),'type':_0x40c73f[_0x1caf('0x47')]['type'],'nolimit':!![],'sort':_0x1caf('0x10'),'filter':_0x40c73f[_0x1caf('0x47')][_0x1caf('0x6c')]}};return db[_0x1caf('0x6d')]['getResources'](_0x10355c);}return db[_0x5da945][_0x1caf('0x6e')](_0x36d1ed);})[_0x1caf('0x15')](function(_0x508e1e){_0x334cd0[_0x1caf('0xc')]=_0x508e1e[_0x1caf('0xc')];_0x31bf61=_0x508e1e[_0x1caf('0x6f')];return getRealtimeQueues(_0x40c73f,_0xd655ac);})[_0x1caf('0x15')](function(_0x501aa4){_0x58da3c=_0x501aa4['rows'];return rta[_0x1caf('0x70')]();})['then'](function(_0x53fa83){_0x17825a=_0x53fa83[_0x1caf('0x6f')];if(_0xd655ac!=_0x1caf('0x1c'))return;return getRealtimeVoiceQueueChannels();})[_0x1caf('0x15')](function(_0x1fe1e5){_0x3e9400=_0x1fe1e5?_0x1fe1e5[_0x1caf('0x6f')]:[];return initializeQueues(_0x31bf61,_0x58da3c,_0xd655ac,_0x40c73f['query']['type']);})['then'](function(_0x10bbe5){var _0x527d61=_0x10bbe5[_0x1caf('0x2a')](function(_0x2e7c10){if(_0xd655ac===_0x1caf('0x1c'))return getVoiceQueueAgents(_0x2e7c10,_0x31bf61,_0x17825a,_0x3e9400);else return getQueueAgents(_0x2e7c10,_0x17825a,_0xd655ac);});return Promise[_0x1caf('0x71')](_0x527d61);})['then'](function(_0x5713e6){_0x334cd0[_0x1caf('0x6f')]=_0x5713e6;return _0x334cd0;})[_0x1caf('0x15')](respondWithFilteredResult(_0x216dbc,_0x36d1ed))['catch'](handleError(_0x216dbc,null));};
\ No newline at end of file
+var _0xd0e7=['accountcode','online','voiceStatus','User','Queue','Pause','getChannels','includes','Invalid\x20channel','toLowerCase','getAgents','globalQueueFilter','query','globalStatusFilter','pauseTypeFilter','*pause','resolve','channel','sort','validateSortParameter','fields','join','order','getAgentIdsByQueues','rows','getSortedAgentsIdsByStatus','getAgentIdsByStatus','rawAttributes','fieldName','type','role','agent','getOptions','literal','FIELD(id,','forEach','where','user','Agents','extraQueryConditions','assign','UserProfile','getResources','findAndCountAll','map','filterAgentAttributes','globalStatus','getAgentStatus','pause','getQueues','key','userProfileId','QueueCampaigns','getRealtimeAgents','all','jayson/promise','../../mysqldb','http','client','offset','undefined','limit','count','status','set','json','error','stack','name','send','voice','startCase','Queues','then','format','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','result','catch','request','loggedIn','waiting','paused','outbound','push','originated','message','dialActive','dialMethod','startPredictive','startProgressive','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgTalktime','agents','loggedInDb','available','talking','busy','merge','filter','some','connectedlinenum','internal','toString','getMembers','length','find','UserId'];(function(_0x264c84,_0x598700){var _0x1fd84c=function(_0x271c3d){while(--_0x271c3d){_0x264c84['push'](_0x264c84['shift']());}};_0x1fd84c(++_0x598700);}(_0xd0e7,0x121));var _0x7d0e=function(_0x3c22e0,_0x1dc6ea){_0x3c22e0=_0x3c22e0-0x0;var _0x215811=_0xd0e7[_0x3c22e0];return _0x215811;};'use strict';var util=require('util');var _=require('lodash');var jayson=require(_0x7d0e('0x0'));var rta=require('../../components/realtime/agents');var qs=require('../../components/parsers/qs');var utils=require('../../config/utils');var logger=require('../../config/logger')('api');var db=require(_0x7d0e('0x1'))['db'];var amiClient=jayson['client'][_0x7d0e('0x2')]({'port':0x232a});var routingClient=jayson[_0x7d0e('0x3')][_0x7d0e('0x2')]({'port':0x232c});function respondWithFilteredResult(_0x513da9,_0x49f42c){return function(_0x1988f1){if(_0x1988f1){var _0x3669dc=typeof _0x49f42c[_0x7d0e('0x4')]===_0x7d0e('0x5')&&typeof _0x49f42c[_0x7d0e('0x6')]===_0x7d0e('0x5');var _0x404c6b=_0x1988f1['count'];var _0x5d5771=_0x3669dc?0x0:_0x49f42c['offset'];var _0x33a632=_0x3669dc?_0x1988f1[_0x7d0e('0x7')]:_0x49f42c[_0x7d0e('0x4')]+_0x49f42c[_0x7d0e('0x6')];var _0x2fb0d7;if(_0x33a632>=_0x404c6b){_0x33a632=_0x404c6b;_0x2fb0d7=0xc8;}else{_0x2fb0d7=0xce;}_0x513da9[_0x7d0e('0x8')](_0x2fb0d7);return _0x513da9[_0x7d0e('0x9')]('Content-Range',_0x5d5771+'-'+_0x33a632+'/'+_0x404c6b)[_0x7d0e('0xa')](_0x1988f1);}return null;};}function handleError(_0x5a7d2e,_0x330fcb){_0x330fcb=_0x330fcb||0x1f4;return function(_0x313e8f){logger[_0x7d0e('0xb')](_0x313e8f[_0x7d0e('0xc')]);if(_0x313e8f[_0x7d0e('0xd')]){delete _0x313e8f['name'];}_0x5a7d2e[_0x7d0e('0x8')](_0x330fcb)[_0x7d0e('0xe')](_0x313e8f);};}function getRealtimeQueues(_0x17648f,_0x4a3129){return new Promise(function(_0x140c32,_0x31ccd8){var _0x356cdd=_0x4a3129===_0x7d0e('0xf')?amiClient:routingClient;return _0x356cdd['request'](_[_0x7d0e('0x10')](_0x4a3129)+_0x7d0e('0x11'),_0x17648f)[_0x7d0e('0x12')](function(_0x5d31b0){if(_0x5d31b0[_0x7d0e('0xb')])throw new Error(util[_0x7d0e('0x13')](_0x7d0e('0x14'),_0x4a3129));return _0x140c32(_0x5d31b0[_0x7d0e('0x15')]);})[_0x7d0e('0x16')](function(_0x58bd58){_0x31ccd8(_0x58bd58);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0xb8cc89,_0x5c29f8){return amiClient[_0x7d0e('0x17')]('VoiceQueuesChannels',{})[_0x7d0e('0x12')](function(_0x1b0ab1){if(_0x1b0ab1['error'])throw new Error('Unable\x20to\x20retrieve\x20voice\x20queues\x20channels');return _0xb8cc89(_0x1b0ab1[_0x7d0e('0x15')]);})[_0x7d0e('0x16')](function(_0x4b9cfc){_0x5c29f8(_0x4b9cfc);});});}function initializeQueues(_0x14bb45,_0x191f32,_0x235f9d,_0xad0fca){var _0x5a6896=[_0x7d0e('0x18'),'available',_0x7d0e('0x19'),'talking',_0x7d0e('0x1a')];if(_0x235f9d===_0x7d0e('0xf')&&_0xad0fca===_0x7d0e('0x1b')){_0x5a6896[_0x7d0e('0x1c')]('pTalking',_0x7d0e('0x1d'),_0x7d0e('0x1e'),_0x7d0e('0x1f'),_0x7d0e('0x20'),'Trunk',_0x7d0e('0x21'),_0x7d0e('0x22'),'erlangCalls',_0x7d0e('0x23'),_0x7d0e('0x24'),_0x7d0e('0x25'),_0x7d0e('0x26'),_0x7d0e('0x27'),_0x7d0e('0x28'),_0x7d0e('0x29'),_0x7d0e('0x2a'),_0x7d0e('0x2b'),_0x7d0e('0x2c'),_0x7d0e('0x2d'),'predictiveIntervalAvgHoldtime',_0x7d0e('0x2e'));}return _0x14bb45['map'](function(_0x3a7f93){var _0x3d35dc=_0x3a7f93['get']({'plain':!![]});_0x3d35dc[_0x7d0e('0x2f')]=[];_0x3d35dc[_0x7d0e('0x1a')]=0x0;_0x3d35dc[_0x7d0e('0x30')]=0x0;_0x3d35dc['loggedIn']=0x0;_0x3d35dc[_0x7d0e('0x31')]=0x0;_0x3d35dc['waiting']=0x0;if(_0x235f9d===_0x7d0e('0xf')){_0x3d35dc[_0x7d0e('0x32')]=0x0;_0x3d35dc[_0x7d0e('0x33')]=0x0;if(_0xad0fca===_0x7d0e('0x1b')){_0x3d35dc['pTalking']=0x0;_0x3d35dc['originated']=0x0;}}var _0x1c8cf7=_['find'](_0x191f32,['id',_0x3d35dc['id']]);if(_0x1c8cf7)_[_0x7d0e('0x34')](_0x3d35dc,_['pick'](_0x1c8cf7,_0x5a6896));return _0x3d35dc;});}function updateAgentVoiceStatus(_0x5310bd,_0x518449,_0x115a67){var _0x1ccbbc=_[_0x7d0e('0x35')](_0x115a67,['queue',_0x518449['name']]);if(_0x1ccbbc['length']===0x0)return _0x5310bd[_0x7d0e('0x33')]=!![];if(_[_0x7d0e('0x36')](_0x1ccbbc,[_0x7d0e('0x37'),_0x5310bd[_0x7d0e('0x38')][_0x7d0e('0x39')]()]))return _0x5310bd[_0x7d0e('0x32')]=!![];if(!_0x5310bd['talking'])return _0x5310bd[_0x7d0e('0x33')]=!![];}function getVoiceQueueAgents(_0x1314ff,_0x32f48f,_0x149e31,_0x43dd69){var _0x509afd=_['find'](_0x32f48f,['id',_0x1314ff['id']]);if(!_0x509afd)return _0x1314ff;return _0x509afd[_0x7d0e('0x3a')]({'raw':!![]})[_0x7d0e('0x12')](function(_0x21fc35){for(var _0x184246=0x0;_0x184246<_0x21fc35[_0x7d0e('0x3b')];_0x184246++){var _0x417d6d=_[_0x7d0e('0x3c')](_0x149e31,['id',_0x21fc35[_0x184246][_0x7d0e('0x3d')]]);if(!_0x417d6d){_0x417d6d={'id':_0x21fc35[_0x184246][_0x7d0e('0x3d')],'name':_0x21fc35[_0x184246][_0x7d0e('0x3d')],'accountcode':'','online':![]};}var _0x3d6762={'id':_0x417d6d['id'],'name':_0x417d6d['name'],'internal':_0x417d6d[_0x7d0e('0x3e')],'online':Boolean(_0x417d6d[_0x7d0e('0x3f')]),'paused':Boolean(_0x21fc35[_0x184246][_0x7d0e('0x1a')])};if(_0x417d6d[_0x7d0e('0x40')]===_0x7d0e('0x32'))updateAgentVoiceStatus(_0x3d6762,_0x1314ff,_0x43dd69);if(_0x3d6762['online'])_0x1314ff[_0x7d0e('0x30')]++;if(_0x3d6762[_0x7d0e('0x33')])_0x1314ff[_0x7d0e('0x33')]++;if(_0x3d6762['paused']&&!_0x3d6762[_0x7d0e('0x33')]&&!_0x3d6762[_0x7d0e('0x32')])_0x1314ff['paused']++;_0x1314ff[_0x7d0e('0x2f')]['push'](_0x3d6762);}return _0x1314ff;});}function getQueueAgents(_0x165c4c,_0x4cdfbe,_0x57aed4){var _0x2b2a4c=_0x7d0e('0x41')+_['startCase'](_0x57aed4)+_0x7d0e('0x42');var _0x5ea9f6=_0x57aed4+_0x7d0e('0x43');return db[_0x2b2a4c]['findAll']({'where':{[_[_0x7d0e('0x10')](_0x57aed4)+'QueueId']:_0x165c4c['id']},'raw':!![]})[_0x7d0e('0x12')](function(_0x3a4220){for(var _0x32a79d=0x0;_0x32a79d<_0x3a4220[_0x7d0e('0x3b')];_0x32a79d++){var _0x2303fd=_['find'](_0x4cdfbe,['id',_0x3a4220[_0x32a79d][_0x7d0e('0x3d')]]);if(!_0x2303fd){_0x2303fd={'id':_0x3a4220[_0x32a79d][_0x7d0e('0x3d')],'name':_0x3a4220[_0x32a79d]['UserId'],'online':![],['pauseField']:![]};}var _0x10d365={'id':_0x2303fd['id'],'name':_0x2303fd[_0x7d0e('0xd')],'online':Boolean(_0x2303fd[_0x7d0e('0x3f')]),'paused':Boolean(_0x2303fd[_0x5ea9f6])};if(_0x10d365[_0x7d0e('0x3f')])_0x165c4c['loggedInDb']++;_0x165c4c['agents']['push'](_0x10d365);}return _0x165c4c;});}function validateChannel(_0x1e3222){var _0x2d13a7=utils[_0x7d0e('0x44')]();if(!_[_0x7d0e('0x45')](_0x2d13a7,_0x1e3222['toLowerCase']()))throw new Error(_0x7d0e('0x46'));return _0x1e3222[_0x7d0e('0x47')]();}exports[_0x7d0e('0x48')]=function(_0x22ecca,_0x1d7eea){var _0x508150={'count':0x0,'rows':[]};var _0x121b3c={};var _0x336aac;var _0x53cfdb;var _0x2af987;var _0x2b5369;var _0x11a498=utils[_0x7d0e('0x44')]();var _0xdaa818=_0x22ecca['query'][_0x7d0e('0x49')];var _0x4c02ab=_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x4b')];var _0x364711=_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x4c')];var _0x20585=_0x4c02ab==='pause'||_0x4c02ab===_0x7d0e('0x4d')?!![]:![];var _0x204487=[];var _0x5519a6;Promise[_0x7d0e('0x4e')]()[_0x7d0e('0x12')](function(){if(_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x4f')]){_0x336aac=validateChannel(_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x4f')]);}if(!_0x22ecca['query'][_0x7d0e('0x50')]||!_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x50')]['includes']('globalStatus')){_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x50')]=rta[_0x7d0e('0x51')](_0x22ecca['query'][_0x7d0e('0x50')]);return;}var _0x56eaa7=rta['getUpdatedSortOptions'](_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x50')]);_0x22ecca['query'][_0x7d0e('0x50')]=_0x56eaa7[_0x7d0e('0x52')][_0x7d0e('0x53')](',');_0x53cfdb=_0x56eaa7[_0x7d0e('0x54')];})[_0x7d0e('0x12')](function(){if(!_0xdaa818){return[];}return rta[_0x7d0e('0x55')](_0xdaa818,_0x336aac);})[_0x7d0e('0x12')](function(_0x362c6d){_0x204487=_0x362c6d;return rta['getRealtimeAgents']();})[_0x7d0e('0x12')](function(_0x98109b){_0x2b5369=_0x98109b[_0x7d0e('0x56')];if((!_0x4c02ab||_0x20585)&&!_0x53cfdb){return _0x204487;}if(_0x53cfdb&&!_0x4c02ab){return rta[_0x7d0e('0x57')](_0x2b5369,_0x204487,_0x53cfdb);}else{return rta[_0x7d0e('0x58')](_0x2b5369,_0x204487,_0x4c02ab);}})[_0x7d0e('0x12')](function(_0x3d1c61){_0x204487=_0x3d1c61;var _0x250022=![];if(_0x204487['length']===0x0){if(_0xdaa818||_0x4c02ab){_0x250022=!![];}if(_0x20585){_0x250022=![];}}if(_0x250022){return _0x508150;}var _0x54c2a8=_['map'](db[_0x7d0e('0x41')][_0x7d0e('0x59')],function(_0x124d29){return{'name':_0x124d29[_0x7d0e('0x5a')],'type':_0x124d29[_0x7d0e('0x5b')]['key']};});_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x5c')]=_0x7d0e('0x5d');_0x22ecca[_0x7d0e('0x4a')][_0x7d0e('0x3f')]=!![];_0x121b3c=qs[_0x7d0e('0x5e')](_0x54c2a8,_0x22ecca);_0x121b3c['raw']=!![];var _0x37c4f6=[];if(_0x204487[_0x7d0e('0x3b')]>0x0){_0x37c4f6[_0x7d0e('0x1c')]({'id':{'$in':_0x204487}});if(_0x53cfdb&&!_0x4c02ab){_0x5519a6=[db['sequelize'][_0x7d0e('0x5f')](_0x7d0e('0x60')+_0x204487+')')];_0x121b3c['order']=_0x5519a6;}}if(_0x20585){_0x11a498[_0x7d0e('0x61')](function(_0x54cd0f){var _0x288f68=!![];if(_0x4c02ab===_0x7d0e('0x4d')&&_0x336aac!==_0x54cd0f){_0x288f68=![];}_0x37c4f6[_0x7d0e('0x1c')]({[_0x54cd0f+'Pause']:_0x288f68});});if(_0x364711){_0x37c4f6['push']({'pauseType':_0x364711});}}else if(_0x4c02ab){_0x11a498[_0x7d0e('0x61')](function(_0x599ccf){_0x37c4f6['push']({[_0x599ccf+_0x7d0e('0x43')]:![]});});}_0x121b3c[_0x7d0e('0x62')]=_[_0x7d0e('0x34')](_0x121b3c['where'],{'$and':_0x37c4f6});if(_0x22ecca[_0x7d0e('0x63')][_0x7d0e('0x5c')]===_0x7d0e('0x63')){var _0x3a042c={'params':{'id':_0x22ecca[_0x7d0e('0x63')]['userProfileId']},'query':{'section':_0x7d0e('0x64'),'role':_0x7d0e('0x5d'),'online':!![],'raw':!![],'ids':_0x204487,'customSorting':_0x5519a6}};if(_0x20585){_0x3a042c[_0x7d0e('0x4a')][_0x7d0e('0x65')]=_0x37c4f6;}_0x3a042c[_0x7d0e('0x4a')]=Object[_0x7d0e('0x66')](_0x3a042c[_0x7d0e('0x4a')],_0x22ecca[_0x7d0e('0x4a')]);delete _0x3a042c[_0x7d0e('0x4a')]['id'];return db[_0x7d0e('0x67')][_0x7d0e('0x68')](_0x3a042c);}return db[_0x7d0e('0x41')][_0x7d0e('0x69')](_0x121b3c);})[_0x7d0e('0x12')](function(_0x12ac1a){_0x508150[_0x7d0e('0x7')]=_0x12ac1a['count'];_0x2af987=_0x12ac1a['rows'];return _0x2af987[_0x7d0e('0x6a')](function(_0x583fbb){var _0x59d181=_['find'](_0x2b5369,['id',_0x583fbb['id']]);if(_0x59d181){var _0x2b1b35=rta[_0x7d0e('0x6b')](_0x59d181);_[_0x7d0e('0x34')](_0x583fbb,_0x2b1b35);}_0x583fbb[_0x7d0e('0x6c')]=rta[_0x7d0e('0x6d')](_0x583fbb);if(_0x583fbb[_0x7d0e('0x6c')][_0x7d0e('0x45')](_0x7d0e('0x6e'))){_0x11a498[_0x7d0e('0x61')](function(_0x4119e7){if(_0x583fbb[_0x4119e7+_0x7d0e('0x43')]){_0x583fbb[_0x4119e7+'Status']=_0x7d0e('0x6e');}});}return _0x583fbb;});})[_0x7d0e('0x12')](function(_0x30f9eb){if(!_0x53cfdb||_0x5519a6){return _0x30f9eb;}return rta['sortAgentsByStatus'](_0x30f9eb,_0x53cfdb);})[_0x7d0e('0x12')](function(_0x2f1e5f){_0x508150['rows']=_0x2f1e5f;return _0x508150;})[_0x7d0e('0x12')](respondWithFilteredResult(_0x1d7eea,_0x121b3c))[_0x7d0e('0x16')](handleError(_0x1d7eea,null));};exports[_0x7d0e('0x6f')]=function(_0x487ba5,_0x491231){var _0x5a252e={'count':0x0,'rows':[]},_0x6e0d4={},_0x437e9d,_0x270614,_0x314add,_0x3fcd3a,_0x57b022;Promise[_0x7d0e('0x4e')]()[_0x7d0e('0x12')](function(){if(_0x487ba5[_0x7d0e('0x4a')][_0x7d0e('0x4f')])_0x437e9d=validateChannel(_0x487ba5['query'][_0x7d0e('0x4f')]);var _0x3a38e1=_[_0x7d0e('0x10')](_0x437e9d)+'Queue';var _0x33aac4=_[_0x7d0e('0x6a')](db[_0x3a38e1][_0x7d0e('0x59')],function(_0x23522c){return{'name':_0x23522c[_0x7d0e('0x5a')],'type':_0x23522c['type'][_0x7d0e('0x70')]};});_0x6e0d4=qs['getOptions'](_0x33aac4,_0x487ba5);if(_0x487ba5[_0x7d0e('0x63')][_0x7d0e('0x5c')]===_0x7d0e('0x63')){var _0x15177d={'params':{'id':_0x487ba5['user'][_0x7d0e('0x71')]},'query':{'section':_0x437e9d===_0x7d0e('0xf')&&_0x487ba5['query']['type']===_0x7d0e('0x1b')?_0x7d0e('0x72'):_[_0x7d0e('0x10')](_0x437e9d)+_0x7d0e('0x11'),'type':_0x487ba5[_0x7d0e('0x4a')]['type'],'nolimit':!![],'sort':_0x7d0e('0xd'),'filter':_0x487ba5[_0x7d0e('0x4a')][_0x7d0e('0x35')]}};return db['UserProfile']['getResources'](_0x15177d);}return db[_0x3a38e1]['findAndCountAll'](_0x6e0d4);})['then'](function(_0x16c35c){_0x5a252e[_0x7d0e('0x7')]=_0x16c35c[_0x7d0e('0x7')];_0x270614=_0x16c35c['rows'];return getRealtimeQueues(_0x487ba5,_0x437e9d);})[_0x7d0e('0x12')](function(_0x5f6b57){_0x3fcd3a=_0x5f6b57['rows'];return rta[_0x7d0e('0x73')]();})[_0x7d0e('0x12')](function(_0x7eb7c9){_0x314add=_0x7eb7c9['rows'];if(_0x437e9d!=_0x7d0e('0xf'))return;return getRealtimeVoiceQueueChannels();})[_0x7d0e('0x12')](function(_0x33adbd){_0x57b022=_0x33adbd?_0x33adbd[_0x7d0e('0x56')]:[];return initializeQueues(_0x270614,_0x3fcd3a,_0x437e9d,_0x487ba5['query'][_0x7d0e('0x5b')]);})[_0x7d0e('0x12')](function(_0x1990ae){var _0x54a4be=_0x1990ae['map'](function(_0x13db28){if(_0x437e9d===_0x7d0e('0xf'))return getVoiceQueueAgents(_0x13db28,_0x270614,_0x314add,_0x57b022);else return getQueueAgents(_0x13db28,_0x314add,_0x437e9d);});return Promise[_0x7d0e('0x74')](_0x54a4be);})['then'](function(_0x5e7f51){_0x5a252e['rows']=_0x5e7f51;return _0x5a252e;})['then'](respondWithFilteredResult(_0x491231,_0x6e0d4))['catch'](handleError(_0x491231,null));};
\ No newline at end of file