Built motion from commit a61a4a20.|2.5.46
[motion2.git] / server / api / realtime / realtime.controller.js
index a90379f..26c4c1b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfdbd=['loggedIn','voice','busy','find','pick','filter','queue','length','some','connectedlinenum','internal','toString','getMembers','UserId','accountcode','online','voiceStatus','agents','User','Queue','QueueId','idle','unknown','isNil','chatPause','faxPause','mailPause','openchannelPause','voicePause','whatsappPause','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','whatsappStatus','*pause','getAgents','userpic','lastLoginAt','lastPauseAt','pauseType','address','smsPause','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','fieldName','query','getOptions','raw','user','userProfileId','agent','nolimit','UserProfile','getResources','findAndCountAll','rows','omit','globalStatus','globalStatusFilter','pauseTypeFilter','mail','chat','sms','resolve','channel','includes','Invalid\x20channel','toLowerCase','rawAttributes','type','QueueCampaigns','all','util','lodash','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','limit','undefined','count','offset','status','set','json','error','stack','name','request','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','result','merge','catch','startCase','Queues','format','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','available','waiting','talking','outbound','push','pTalking','originated','message','dialActive','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalDroppedCallsTimeout','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','map','get','paused','loggedInDb'];(function(_0x575730,_0x1862bb){var _0x4c2e0c=function(_0x54625f){while(--_0x54625f){_0x575730['push'](_0x575730['shift']());}};_0x4c2e0c(++_0x1862bb);}(_0xfdbd,0xf0));var _0xdfdb=function(_0x2c3255,_0x4e00ae){_0x2c3255=_0x2c3255-0x0;var _0x282aba=_0xfdbd[_0x2c3255];return _0x282aba;};'use strict';var util=require(_0xdfdb('0x0'));var _=require(_0xdfdb('0x1'));var jayson=require(_0xdfdb('0x2'));var qs=require(_0xdfdb('0x3'));var logger=require(_0xdfdb('0x4'))(_0xdfdb('0x5'));var db=require(_0xdfdb('0x6'))['db'];var amiClient=jayson[_0xdfdb('0x7')][_0xdfdb('0x8')]({'port':0x232a});var routingClient=jayson['client'][_0xdfdb('0x8')]({'port':0x232c});function respondWithFilteredResult(_0x4a4a3f,_0x453ef6){return function(_0x41bd5e){if(_0x41bd5e){var _0x489f19=typeof _0x453ef6['offset']==='undefined'&&typeof _0x453ef6[_0xdfdb('0x9')]===_0xdfdb('0xa');var _0x47c629=_0x41bd5e[_0xdfdb('0xb')];var _0x444c19=_0x489f19?0x0:_0x453ef6[_0xdfdb('0xc')];var _0x27ddcd=_0x489f19?_0x41bd5e[_0xdfdb('0xb')]:_0x453ef6[_0xdfdb('0xc')]+_0x453ef6[_0xdfdb('0x9')];var _0x47dccc;if(_0x27ddcd>=_0x47c629){_0x27ddcd=_0x47c629;_0x47dccc=0xc8;}else{_0x47dccc=0xce;}_0x4a4a3f[_0xdfdb('0xd')](_0x47dccc);return _0x4a4a3f[_0xdfdb('0xe')]('Content-Range',_0x444c19+'-'+_0x27ddcd+'/'+_0x47c629)[_0xdfdb('0xf')](_0x41bd5e);}return null;};}function handleError(_0x33a706,_0x2bee3b){_0x2bee3b=_0x2bee3b||0x1f4;return function(_0x1918c1){logger[_0xdfdb('0x10')](_0x1918c1[_0xdfdb('0x11')]);if(_0x1918c1[_0xdfdb('0x12')]){delete _0x1918c1[_0xdfdb('0x12')];}_0x33a706['status'](_0x2bee3b)['send'](_0x1918c1);};}function getRealtimeAgents(){return new Promise(function(_0x2c44dc,_0x4b1ff7){return amiClient[_0xdfdb('0x13')](_0xdfdb('0x14'),{})[_0xdfdb('0x15')](function(_0x40bc8a){if(_0x40bc8a[_0xdfdb('0x10')])throw new Error(_0xdfdb('0x16'));var _0x54ff23=_0x40bc8a['result'];return routingClient[_0xdfdb('0x13')](_0xdfdb('0x14'),{})[_0xdfdb('0x15')](function(_0x55ab5a){if(_0x55ab5a[_0xdfdb('0x10')])throw new Error(_0xdfdb('0x17'));var _0x467653=_0x55ab5a[_0xdfdb('0x18')];return _0x2c44dc(_[_0xdfdb('0x19')]({},_0x54ff23,_0x467653));});})[_0xdfdb('0x1a')](function(_0x693a2c){_0x4b1ff7(_0x693a2c);});});}function getRealtimeQueues(_0x29a639,_0x5b8cb5){return new Promise(function(_0x14638a,_0xb7417c){var _0x172c63=_0x5b8cb5==='voice'?amiClient:routingClient;return _0x172c63[_0xdfdb('0x13')](_[_0xdfdb('0x1b')](_0x5b8cb5)+_0xdfdb('0x1c'),_0x29a639)['then'](function(_0x280e53){if(_0x280e53[_0xdfdb('0x10')])throw new Error(util[_0xdfdb('0x1d')]('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0x5b8cb5));return _0x14638a(_0x280e53[_0xdfdb('0x18')]);})['catch'](function(_0x2db1c1){_0xb7417c(_0x2db1c1);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x145350,_0x1fa2f3){return amiClient[_0xdfdb('0x13')]('VoiceQueuesChannels',{})[_0xdfdb('0x15')](function(_0x4363d8){if(_0x4363d8[_0xdfdb('0x10')])throw new Error(_0xdfdb('0x1e'));return _0x145350(_0x4363d8[_0xdfdb('0x18')]);})[_0xdfdb('0x1a')](function(_0x57d24f){_0x1fa2f3(_0x57d24f);});});}function initializeQueues(_0xec4d22,_0x2d5fe2,_0xdf3a5c,_0x4f8057){var _0x466932=['loggedIn',_0xdfdb('0x1f'),_0xdfdb('0x20'),_0xdfdb('0x21'),'paused'];if(_0xdf3a5c==='voice'&&_0x4f8057===_0xdfdb('0x22')){_0x466932[_0xdfdb('0x23')](_0xdfdb('0x24'),_0xdfdb('0x25'),_0xdfdb('0x26'),_0xdfdb('0x27'),'dialMethod',_0xdfdb('0x28'),_0xdfdb('0x29'),_0xdfdb('0x2a'),_0xdfdb('0x2b'),_0xdfdb('0x2c'),_0xdfdb('0x2d'),_0xdfdb('0x2e'),_0xdfdb('0x2f'),_0xdfdb('0x30'),_0xdfdb('0x31'),_0xdfdb('0x32'),'predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls',_0xdfdb('0x33'),'predictiveIntervalDroppedCallsCallersExit',_0xdfdb('0x34'),_0xdfdb('0x35'));}return _0xec4d22[_0xdfdb('0x36')](function(_0x36d91f){var _0x514232=_0x36d91f[_0xdfdb('0x37')]({'plain':!![]});_0x514232['agents']=[];_0x514232[_0xdfdb('0x38')]=0x0;_0x514232[_0xdfdb('0x39')]=0x0;_0x514232[_0xdfdb('0x3a')]=0x0;_0x514232[_0xdfdb('0x1f')]=0x0;_0x514232[_0xdfdb('0x20')]=0x0;if(_0xdf3a5c===_0xdfdb('0x3b')){_0x514232['talking']=0x0;_0x514232[_0xdfdb('0x3c')]=0x0;if(_0x4f8057===_0xdfdb('0x22')){_0x514232['pTalking']=0x0;_0x514232[_0xdfdb('0x25')]=0x0;}}var _0x4377d6=_[_0xdfdb('0x3d')](_0x2d5fe2,['id',_0x514232['id']]);if(_0x4377d6)_[_0xdfdb('0x19')](_0x514232,_[_0xdfdb('0x3e')](_0x4377d6,_0x466932));return _0x514232;});}function updateAgentVoiceStatus(_0x286fdb,_0x16d5b8,_0x1d1f4f){var _0x21f4c7=_[_0xdfdb('0x3f')](_0x1d1f4f,[_0xdfdb('0x40'),_0x16d5b8['name']]);if(_0x21f4c7[_0xdfdb('0x41')]===0x0)return _0x286fdb[_0xdfdb('0x3c')]=!![];if(_[_0xdfdb('0x42')](_0x21f4c7,[_0xdfdb('0x43'),_0x286fdb[_0xdfdb('0x44')][_0xdfdb('0x45')]()]))return _0x286fdb[_0xdfdb('0x21')]=!![];if(!_0x286fdb[_0xdfdb('0x21')])return _0x286fdb['busy']=!![];}function getVoiceQueueAgents(_0x55d707,_0x435557,_0x2146b2,_0x16e100){var _0x1e7688=_[_0xdfdb('0x3d')](_0x435557,['id',_0x55d707['id']]);if(!_0x1e7688)return _0x55d707;return _0x1e7688[_0xdfdb('0x46')]({'raw':!![]})[_0xdfdb('0x15')](function(_0x2eb46c){for(var _0xcee274=0x0;_0xcee274<_0x2eb46c['length'];_0xcee274++){var _0x175f57=_[_0xdfdb('0x3d')](_0x2146b2,['id',_0x2eb46c[_0xcee274][_0xdfdb('0x47')]]);if(!_0x175f57){_0x175f57={'id':_0x2eb46c[_0xcee274][_0xdfdb('0x47')],'name':_0x2eb46c[_0xcee274][_0xdfdb('0x47')],'accountcode':'','online':![]};}var _0x5a1bee={'id':_0x175f57['id'],'name':_0x175f57[_0xdfdb('0x12')],'internal':_0x175f57[_0xdfdb('0x48')],'online':Boolean(_0x175f57[_0xdfdb('0x49')]),'paused':Boolean(_0x2eb46c[_0xcee274][_0xdfdb('0x38')])};if(_0x175f57[_0xdfdb('0x4a')]==='talking')updateAgentVoiceStatus(_0x5a1bee,_0x55d707,_0x16e100);if(_0x5a1bee[_0xdfdb('0x49')])_0x55d707[_0xdfdb('0x39')]++;if(_0x5a1bee[_0xdfdb('0x3c')])_0x55d707['busy']++;if(_0x5a1bee[_0xdfdb('0x38')]&&!_0x5a1bee['busy']&&!_0x5a1bee[_0xdfdb('0x21')])_0x55d707['paused']++;_0x55d707[_0xdfdb('0x4b')][_0xdfdb('0x23')](_0x5a1bee);}return _0x55d707;});}function getQueueAgents(_0x5c14a1,_0xc92f82,_0x4e8ead){var _0xfea790=_0xdfdb('0x4c')+_[_0xdfdb('0x1b')](_0x4e8ead)+_0xdfdb('0x4d');var _0x25cc2f=_0x4e8ead+'Pause';return db[_0xfea790]['findAll']({'where':{[_[_0xdfdb('0x1b')](_0x4e8ead)+_0xdfdb('0x4e')]:_0x5c14a1['id']},'raw':!![]})['then'](function(_0x2b0a8b){for(var _0x59d0c3=0x0;_0x59d0c3<_0x2b0a8b[_0xdfdb('0x41')];_0x59d0c3++){var _0x158407=_[_0xdfdb('0x3d')](_0xc92f82,['id',_0x2b0a8b[_0x59d0c3][_0xdfdb('0x47')]]);if(!_0x158407){_0x158407={'id':_0x2b0a8b[_0x59d0c3][_0xdfdb('0x47')],'name':_0x2b0a8b[_0x59d0c3][_0xdfdb('0x47')],'online':![],['pauseField']:![]};}var _0x41701c={'id':_0x158407['id'],'name':_0x158407[_0xdfdb('0x12')],'online':Boolean(_0x158407[_0xdfdb('0x49')]),'paused':Boolean(_0x158407[_0x25cc2f])};if(_0x41701c[_0xdfdb('0x49')])_0x5c14a1[_0xdfdb('0x39')]++;_0x5c14a1[_0xdfdb('0x4b')][_0xdfdb('0x23')](_0x41701c);}return _0x5c14a1;});}function isIdle(_0x202c25){return _0x202c25===_0xdfdb('0x4f')||_0x202c25===_0xdfdb('0x50')||_0x202c25==='unavailable'||_0x202c25==='ringing'||_[_0xdfdb('0x51')](_0x202c25);}function isAgentPaused(_0x1aff71,_0x2f1d06){var _0x4bbb88=[_0x1aff71[_0xdfdb('0x52')],_0x1aff71[_0xdfdb('0x53')],_0x1aff71[_0xdfdb('0x54')],_0x1aff71[_0xdfdb('0x55')],_0x1aff71['smsPause'],_0x1aff71[_0xdfdb('0x56')],_0x1aff71[_0xdfdb('0x57')]];if(!_0x2f1d06)return _['every'](_0x4bbb88);var _0x3a6ce2=_[_0xdfdb('0x3f')](_0x4bbb88);return _0x3a6ce2[_0xdfdb('0x41')]>0x0&&_0x3a6ce2[_0xdfdb('0x41')]<_0x4bbb88[_0xdfdb('0x41')]?!![]:![];}function isAgentIdle(_0x10b490){if(_0x10b490[_0xdfdb('0x4a')]!==_0xdfdb('0x4f')&&_0x10b490[_0xdfdb('0x56')]){_0x10b490['voiceStatus']=_0xdfdb('0x58');return![];}return _['every']([_0x10b490[_0xdfdb('0x59')],_0x10b490[_0xdfdb('0x5a')],_0x10b490[_0xdfdb('0x5b')],_0x10b490[_0xdfdb('0x5c')],_0x10b490[_0xdfdb('0x5d')],_0x10b490[_0xdfdb('0x4a')],_0x10b490[_0xdfdb('0x5e')]],isIdle);}function getAgentStatus(_0x480e98){var _0x2a5803=_0xdfdb('0x50');if(isAgentPaused(_0x480e98))_0x2a5803=_0xdfdb('0x58');else if(isAgentPaused(_0x480e98,!![]))_0x2a5803=_0xdfdb('0x5f');else if(isAgentIdle(_0x480e98))_0x2a5803=_0xdfdb('0x4f');else _0x2a5803='busy';return _0x2a5803;}exports[_0xdfdb('0x60')]=function(_0x4df3b6,_0x9bbf0e){var _0x1331eb={'count':0x0,'rows':[]},_0xdd48cd={},_0x6d7407,_0x3f10fe,_0x5e7388=[_0xdfdb('0x61'),'online',_0xdfdb('0x62'),_0xdfdb('0x63'),_0xdfdb('0x64'),'lastPauseAt',_0xdfdb('0x44'),_0xdfdb('0x65'),_0xdfdb('0x52'),_0xdfdb('0x55'),_0xdfdb('0x54'),_0xdfdb('0x66'),'whatsappPause','faxPause',_0xdfdb('0x56'),'chatCapacity','openchannelCapacity','mailCapacity',_0xdfdb('0x67'),_0xdfdb('0x68'),_0xdfdb('0x69'),_0xdfdb('0x6a'),_0xdfdb('0x6b'),_0xdfdb('0x6c'),_0xdfdb('0x6d'),_0xdfdb('0x6e'),_0xdfdb('0x6f'),'chatStatus','openchannelStatus',_0xdfdb('0x5b'),'smsStatus',_0xdfdb('0x5e'),_0xdfdb('0x5a'),_0xdfdb('0x4a'),'chatStatusTime',_0xdfdb('0x70'),_0xdfdb('0x71'),_0xdfdb('0x72'),_0xdfdb('0x73'),_0xdfdb('0x74'),_0xdfdb('0x75'),_0xdfdb('0x40'),_0xdfdb('0x76'),'screenrecording',_0xdfdb('0x77'),_0xdfdb('0x78'),'routealias'],_0x3fbbb5=[_0xdfdb('0x52'),_0xdfdb('0x55'),_0xdfdb('0x54'),_0xdfdb('0x66'),'whatsappPause','faxPause',_0xdfdb('0x56'),_0xdfdb('0x49')];Promise['resolve']()[_0xdfdb('0x15')](function(){var _0x2b8776=_[_0xdfdb('0x36')](db['User']['rawAttributes'],function(_0x42ad97){return{'name':_0x42ad97[_0xdfdb('0x79')],'type':_0x42ad97['type']['key']};});_0x4df3b6[_0xdfdb('0x7a')]['role']='agent';_0x4df3b6[_0xdfdb('0x7a')]['online']=!![];_0xdd48cd=qs[_0xdfdb('0x7b')](_0x2b8776,_0x4df3b6);_0xdd48cd[_0xdfdb('0x7c')]=!![];if(_0x4df3b6['user']['role']===_0xdfdb('0x7d')){var _0x2a218a={'params':{'id':_0x4df3b6['user'][_0xdfdb('0x7e')]},'query':{'section':_0xdfdb('0x14'),'role':_0xdfdb('0x7f'),'online':!![],'nolimit':_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x80')],'sort':_0x4df3b6['query']['sort'],'filter':_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x3f')],'raw':!![]}};return db[_0xdfdb('0x81')][_0xdfdb('0x82')](_0x2a218a);}return db[_0xdfdb('0x4c')][_0xdfdb('0x83')](_0xdd48cd);})['then'](function(_0xd226af){_0x1331eb[_0xdfdb('0xb')]=_0xd226af[_0xdfdb('0xb')];_0x6d7407=_0xd226af[_0xdfdb('0x84')];return getRealtimeAgents();})[_0xdfdb('0x15')](function(_0x1bcfdd){_0x3f10fe=_0x1bcfdd[_0xdfdb('0x84')];return _0x6d7407[_0xdfdb('0x36')](function(_0x38fa9c){var _0x3eca7f=_['find'](_0x3f10fe,['id',_0x38fa9c['id']]);if(_0x3eca7f)_[_0xdfdb('0x19')](_0x38fa9c,_[_0xdfdb('0x3e')](_[_0xdfdb('0x85')](_0x3eca7f,_0x3fbbb5),_0x5e7388));_0x38fa9c[_0xdfdb('0x86')]=getAgentStatus(_0x38fa9c);return _0x38fa9c;});})[_0xdfdb('0x15')](function(_0x590a16){if(_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x87')]){var _0x234882=_[_0xdfdb('0x3f')](_0x590a16,['globalStatus',_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x87')]]);if(_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x88')]){_0x234882=_[_0xdfdb('0x3f')](_0x234882,[_0xdfdb('0x64'),_0x4df3b6[_0xdfdb('0x7a')][_0xdfdb('0x88')]]);}}_0x1331eb[_0xdfdb('0x84')]=_0x234882||_0x590a16;return _0x1331eb;})[_0xdfdb('0x15')](respondWithFilteredResult(_0x9bbf0e,_0xdd48cd))[_0xdfdb('0x1a')](handleError(_0x9bbf0e,null));};exports['getQueues']=function(_0x1bf0d2,_0x616d29){var _0x5ad38a=[_0xdfdb('0x89'),_0xdfdb('0x8a'),_0xdfdb('0x8b'),'openchannel','fax','whatsapp',_0xdfdb('0x3b')];var _0x465565={'count':0x0,'rows':[]},_0x1c7964={},_0x8e68a8,_0xd4b817,_0x394536,_0xf60176,_0x4b2c31;Promise[_0xdfdb('0x8c')]()[_0xdfdb('0x15')](function(){if(_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x8d')]){if(!_[_0xdfdb('0x8e')](_0x5ad38a,_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x8d')]['toLowerCase']()))throw new Error(_0xdfdb('0x8f'));_0x8e68a8=_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x8d')][_0xdfdb('0x90')]();}var _0x275e5f=_['startCase'](_0x8e68a8)+_0xdfdb('0x4d');var _0x56a633=_[_0xdfdb('0x36')](db[_0x275e5f][_0xdfdb('0x91')],function(_0x18c6d1){return{'name':_0x18c6d1[_0xdfdb('0x79')],'type':_0x18c6d1[_0xdfdb('0x92')]['key']};});_0x1c7964=qs[_0xdfdb('0x7b')](_0x56a633,_0x1bf0d2);if(_0x1bf0d2[_0xdfdb('0x7d')]['role']==='user'){var _0x284439={'params':{'id':_0x1bf0d2['user']['userProfileId']},'query':{'section':_0x8e68a8===_0xdfdb('0x3b')&&_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x92')]===_0xdfdb('0x22')?_0xdfdb('0x93'):_[_0xdfdb('0x1b')](_0x8e68a8)+_0xdfdb('0x1c'),'type':_0x1bf0d2[_0xdfdb('0x7a')]['type'],'nolimit':!![],'sort':_0xdfdb('0x12'),'filter':_0x1bf0d2['query'][_0xdfdb('0x3f')]}};return db[_0xdfdb('0x81')][_0xdfdb('0x82')](_0x284439);}return db[_0x275e5f][_0xdfdb('0x83')](_0x1c7964);})[_0xdfdb('0x15')](function(_0x52a8a5){_0x465565[_0xdfdb('0xb')]=_0x52a8a5[_0xdfdb('0xb')];_0xd4b817=_0x52a8a5[_0xdfdb('0x84')];return getRealtimeQueues(_0x1bf0d2,_0x8e68a8);})[_0xdfdb('0x15')](function(_0x36241c){_0xf60176=_0x36241c['rows'];return getRealtimeAgents();})['then'](function(_0x231f20){_0x394536=_0x231f20[_0xdfdb('0x84')];if(_0x8e68a8!='voice')return;return getRealtimeVoiceQueueChannels();})[_0xdfdb('0x15')](function(_0x50d5d4){_0x4b2c31=_0x50d5d4?_0x50d5d4[_0xdfdb('0x84')]:[];return initializeQueues(_0xd4b817,_0xf60176,_0x8e68a8,_0x1bf0d2[_0xdfdb('0x7a')][_0xdfdb('0x92')]);})['then'](function(_0x2828a5){var _0x53ca83=_0x2828a5['map'](function(_0x3eb36e){if(_0x8e68a8==='voice')return getVoiceQueueAgents(_0x3eb36e,_0xd4b817,_0x394536,_0x4b2c31);else return getQueueAgents(_0x3eb36e,_0x394536,_0x8e68a8);});return Promise[_0xdfdb('0x94')](_0x53ca83);})[_0xdfdb('0x15')](function(_0x162eeb){_0x465565[_0xdfdb('0x84')]=_0x162eeb;return _0x465565;})[_0xdfdb('0x15')](respondWithFilteredResult(_0x616d29,_0x1c7964))[_0xdfdb('0x1a')](handleError(_0x616d29,null));};
\ No newline at end of file
+var _0x01d9=['erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','map','get','agents','paused','loggedInDb','busy','pick','filter','queue','length','some','connectedlinenum','internal','toString','find','getMembers','UserId','accountcode','online','voiceStatus','User','Queue','Pause','startCase','idle','unknown','unavailable','ringing','isNil','chatPause','openchannelPause','smsPause','voicePause','whatsappPause','every','pause','chatStatus','faxStatus','openchannelStatus','smsStatus','whatsappStatus','*pause','getAgents','userpic','lastLoginAt','lastPauseAt','pauseType','mailPause','faxPause','chatCapacity','openchannelCapacity','mailCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','faxCurrentCapacity','openchannelStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','resolve','type','key','query','role','agent','getOptions','raw','user','userProfileId','nolimit','sort','UserProfile','findAndCountAll','rows','omit','globalStatus','globalStatusFilter','pauseTypeFilter','getQueues','chat','openchannel','whatsapp','toLowerCase','Invalid\x20channel','channel','rawAttributes','outbound','all','util','lodash','jayson/promise','../../components/parsers/qs','api','../../mysqldb','client','http','offset','undefined','limit','count','set','Content-Range','json','error','stack','name','status','send','request','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','voice','Queues','format','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','catch','VoiceQueuesChannels','loggedIn','available','waiting','talking','push','pTalking','originated','message','dialActive','dialMethod','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond'];(function(_0x4eda22,_0x3d2db4){var _0x4a5706=function(_0x4345e3){while(--_0x4345e3){_0x4eda22['push'](_0x4eda22['shift']());}};_0x4a5706(++_0x3d2db4);}(_0x01d9,0x6c));var _0x901d=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x01d9[_0x20a584];return _0x4b41a8;};'use strict';var util=require(_0x901d('0x0'));var _=require(_0x901d('0x1'));var jayson=require(_0x901d('0x2'));var qs=require(_0x901d('0x3'));var logger=require('../../config/logger')(_0x901d('0x4'));var db=require(_0x901d('0x5'))['db'];var amiClient=jayson[_0x901d('0x6')][_0x901d('0x7')]({'port':0x232a});var routingClient=jayson[_0x901d('0x6')][_0x901d('0x7')]({'port':0x232c});function respondWithFilteredResult(_0xb96b86,_0x4e7842){return function(_0x1e5d7d){if(_0x1e5d7d){var _0x6c9ac8=typeof _0x4e7842[_0x901d('0x8')]===_0x901d('0x9')&&typeof _0x4e7842[_0x901d('0xa')]===_0x901d('0x9');var _0x202568=_0x1e5d7d[_0x901d('0xb')];var _0x15076e=_0x6c9ac8?0x0:_0x4e7842[_0x901d('0x8')];var _0x440fb0=_0x6c9ac8?_0x1e5d7d[_0x901d('0xb')]:_0x4e7842[_0x901d('0x8')]+_0x4e7842['limit'];var _0x439f17;if(_0x440fb0>=_0x202568){_0x440fb0=_0x202568;_0x439f17=0xc8;}else{_0x439f17=0xce;}_0xb96b86['status'](_0x439f17);return _0xb96b86[_0x901d('0xc')](_0x901d('0xd'),_0x15076e+'-'+_0x440fb0+'/'+_0x202568)[_0x901d('0xe')](_0x1e5d7d);}return null;};}function handleError(_0x42ce79,_0x15ebaf){_0x15ebaf=_0x15ebaf||0x1f4;return function(_0x5d2345){logger[_0x901d('0xf')](_0x5d2345[_0x901d('0x10')]);if(_0x5d2345[_0x901d('0x11')]){delete _0x5d2345[_0x901d('0x11')];}_0x42ce79[_0x901d('0x12')](_0x15ebaf)[_0x901d('0x13')](_0x5d2345);};}function getRealtimeAgents(){return new Promise(function(_0x530a2b,_0x991ee2){return amiClient[_0x901d('0x14')](_0x901d('0x15'),{})[_0x901d('0x16')](function(_0x1aba97){if(_0x1aba97[_0x901d('0xf')])throw new Error(_0x901d('0x17'));var _0x407215=_0x1aba97[_0x901d('0x18')];return routingClient[_0x901d('0x14')](_0x901d('0x15'),{})[_0x901d('0x16')](function(_0x285353){if(_0x285353[_0x901d('0xf')])throw new Error(_0x901d('0x19'));var _0x414171=_0x285353[_0x901d('0x18')];return _0x530a2b(_[_0x901d('0x1a')]({},_0x407215,_0x414171));});})['catch'](function(_0x430634){_0x991ee2(_0x430634);});});}function getRealtimeQueues(_0x2f32f8,_0x4d27db){return new Promise(function(_0x5bdff4,_0x496a06){var _0x53f8ae=_0x4d27db===_0x901d('0x1b')?amiClient:routingClient;return _0x53f8ae[_0x901d('0x14')](_['startCase'](_0x4d27db)+_0x901d('0x1c'),_0x2f32f8)[_0x901d('0x16')](function(_0x488e24){if(_0x488e24[_0x901d('0xf')])throw new Error(util[_0x901d('0x1d')](_0x901d('0x1e'),_0x4d27db));return _0x5bdff4(_0x488e24[_0x901d('0x18')]);})[_0x901d('0x1f')](function(_0x1818d3){_0x496a06(_0x1818d3);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x46e5c6,_0x45b6a8){return amiClient['request'](_0x901d('0x20'),{})[_0x901d('0x16')](function(_0xbc89a5){if(_0xbc89a5[_0x901d('0xf')])throw new Error('Unable\x20to\x20retrieve\x20voice\x20queues\x20channels');return _0x46e5c6(_0xbc89a5[_0x901d('0x18')]);})[_0x901d('0x1f')](function(_0x27f4ca){_0x45b6a8(_0x27f4ca);});});}function initializeQueues(_0x3cbe43,_0x133bff,_0x56e4ec,_0x21fbb9){var _0xc52d0f=[_0x901d('0x21'),_0x901d('0x22'),_0x901d('0x23'),_0x901d('0x24'),'paused'];if(_0x56e4ec===_0x901d('0x1b')&&_0x21fbb9==='outbound'){_0xc52d0f[_0x901d('0x25')](_0x901d('0x26'),_0x901d('0x27'),_0x901d('0x28'),_0x901d('0x29'),_0x901d('0x2a'),_0x901d('0x2b'),_0x901d('0x2c'),_0x901d('0x2d'),_0x901d('0x2e'),_0x901d('0x2f'),_0x901d('0x30'),_0x901d('0x31'),_0x901d('0x32'),_0x901d('0x33'),'dialPredictiveIntervalMinThreshold',_0x901d('0x34'),_0x901d('0x35'),_0x901d('0x36'),'predictiveIntervalDroppedCallsTimeout',_0x901d('0x37'),_0x901d('0x38'),_0x901d('0x39'));}return _0x3cbe43[_0x901d('0x3a')](function(_0x444bff){var _0x3962c2=_0x444bff[_0x901d('0x3b')]({'plain':!![]});_0x3962c2[_0x901d('0x3c')]=[];_0x3962c2[_0x901d('0x3d')]=0x0;_0x3962c2[_0x901d('0x3e')]=0x0;_0x3962c2['loggedIn']=0x0;_0x3962c2['available']=0x0;_0x3962c2[_0x901d('0x23')]=0x0;if(_0x56e4ec==='voice'){_0x3962c2[_0x901d('0x24')]=0x0;_0x3962c2[_0x901d('0x3f')]=0x0;if(_0x21fbb9==='outbound'){_0x3962c2[_0x901d('0x26')]=0x0;_0x3962c2[_0x901d('0x27')]=0x0;}}var _0x2f5e22=_['find'](_0x133bff,['id',_0x3962c2['id']]);if(_0x2f5e22)_[_0x901d('0x1a')](_0x3962c2,_[_0x901d('0x40')](_0x2f5e22,_0xc52d0f));return _0x3962c2;});}function updateAgentVoiceStatus(_0x1a1f9c,_0x13f5d1,_0x37bd5b){var _0x32aa29=_[_0x901d('0x41')](_0x37bd5b,[_0x901d('0x42'),_0x13f5d1[_0x901d('0x11')]]);if(_0x32aa29[_0x901d('0x43')]===0x0)return _0x1a1f9c[_0x901d('0x3f')]=!![];if(_[_0x901d('0x44')](_0x32aa29,[_0x901d('0x45'),_0x1a1f9c[_0x901d('0x46')][_0x901d('0x47')]()]))return _0x1a1f9c[_0x901d('0x24')]=!![];if(!_0x1a1f9c['talking'])return _0x1a1f9c[_0x901d('0x3f')]=!![];}function getVoiceQueueAgents(_0x423cab,_0x5abca2,_0x47fcb5,_0x28725d){var _0x5adf16=_[_0x901d('0x48')](_0x5abca2,['id',_0x423cab['id']]);if(!_0x5adf16)return _0x423cab;return _0x5adf16[_0x901d('0x49')]({'raw':!![]})[_0x901d('0x16')](function(_0x2c6cd9){for(var _0x4ec53f=0x0;_0x4ec53f<_0x2c6cd9[_0x901d('0x43')];_0x4ec53f++){var _0x5df4cb=_['find'](_0x47fcb5,['id',_0x2c6cd9[_0x4ec53f]['UserId']]);if(!_0x5df4cb){_0x5df4cb={'id':_0x2c6cd9[_0x4ec53f]['UserId'],'name':_0x2c6cd9[_0x4ec53f][_0x901d('0x4a')],'accountcode':'','online':![]};}var _0x26f2fe={'id':_0x5df4cb['id'],'name':_0x5df4cb['name'],'internal':_0x5df4cb[_0x901d('0x4b')],'online':Boolean(_0x5df4cb[_0x901d('0x4c')]),'paused':Boolean(_0x2c6cd9[_0x4ec53f]['paused'])};if(_0x5df4cb[_0x901d('0x4d')]===_0x901d('0x24'))updateAgentVoiceStatus(_0x26f2fe,_0x423cab,_0x28725d);if(_0x26f2fe[_0x901d('0x4c')])_0x423cab[_0x901d('0x3e')]++;if(_0x26f2fe['busy'])_0x423cab['busy']++;if(_0x26f2fe[_0x901d('0x3d')]&&!_0x26f2fe[_0x901d('0x3f')]&&!_0x26f2fe[_0x901d('0x24')])_0x423cab[_0x901d('0x3d')]++;_0x423cab[_0x901d('0x3c')][_0x901d('0x25')](_0x26f2fe);}return _0x423cab;});}function getQueueAgents(_0x88bb50,_0x904a94,_0x431204){var _0x2b23bc=_0x901d('0x4e')+_['startCase'](_0x431204)+_0x901d('0x4f');var _0x4d2b1c=_0x431204+_0x901d('0x50');return db[_0x2b23bc]['findAll']({'where':{[_[_0x901d('0x51')](_0x431204)+'QueueId']:_0x88bb50['id']},'raw':!![]})[_0x901d('0x16')](function(_0x12ac04){for(var _0x2f63e8=0x0;_0x2f63e8<_0x12ac04[_0x901d('0x43')];_0x2f63e8++){var _0x2fc1d2=_[_0x901d('0x48')](_0x904a94,['id',_0x12ac04[_0x2f63e8][_0x901d('0x4a')]]);if(!_0x2fc1d2){_0x2fc1d2={'id':_0x12ac04[_0x2f63e8][_0x901d('0x4a')],'name':_0x12ac04[_0x2f63e8][_0x901d('0x4a')],'online':![],['pauseField']:![]};}var _0x430beb={'id':_0x2fc1d2['id'],'name':_0x2fc1d2[_0x901d('0x11')],'online':Boolean(_0x2fc1d2['online']),'paused':Boolean(_0x2fc1d2[_0x4d2b1c])};if(_0x430beb[_0x901d('0x4c')])_0x88bb50[_0x901d('0x3e')]++;_0x88bb50[_0x901d('0x3c')][_0x901d('0x25')](_0x430beb);}return _0x88bb50;});}function isIdle(_0x3b75a3){return _0x3b75a3===_0x901d('0x52')||_0x3b75a3===_0x901d('0x53')||_0x3b75a3===_0x901d('0x54')||_0x3b75a3===_0x901d('0x55')||_[_0x901d('0x56')](_0x3b75a3);}function isAgentPaused(_0x3e01fd,_0x107017){var _0x2cd965=[_0x3e01fd[_0x901d('0x57')],_0x3e01fd['faxPause'],_0x3e01fd['mailPause'],_0x3e01fd[_0x901d('0x58')],_0x3e01fd[_0x901d('0x59')],_0x3e01fd[_0x901d('0x5a')],_0x3e01fd[_0x901d('0x5b')]];if(!_0x107017)return _[_0x901d('0x5c')](_0x2cd965);var _0x5cbc90=_['filter'](_0x2cd965);return _0x5cbc90[_0x901d('0x43')]>0x0&&_0x5cbc90[_0x901d('0x43')]<_0x2cd965['length']?!![]:![];}function isAgentIdle(_0x23673d){if(_0x23673d[_0x901d('0x4d')]!=='idle'&&_0x23673d[_0x901d('0x5a')]){_0x23673d['voiceStatus']=_0x901d('0x5d');return![];}return _[_0x901d('0x5c')]([_0x23673d[_0x901d('0x5e')],_0x23673d[_0x901d('0x5f')],_0x23673d['mailStatus'],_0x23673d[_0x901d('0x60')],_0x23673d[_0x901d('0x61')],_0x23673d[_0x901d('0x4d')],_0x23673d[_0x901d('0x62')]],isIdle);}function getAgentStatus(_0x10c51c){var _0x11953e=_0x901d('0x53');if(isAgentPaused(_0x10c51c))_0x11953e=_0x901d('0x5d');else if(isAgentPaused(_0x10c51c,!![]))_0x11953e=_0x901d('0x63');else if(isAgentIdle(_0x10c51c))_0x11953e=_0x901d('0x52');else _0x11953e='busy';return _0x11953e;}exports[_0x901d('0x64')]=function(_0x4afe28,_0xd7fbb3){var _0x26e6a2={'count':0x0,'rows':[]},_0xaa7394={},_0x2aa9b4,_0x3e3487,_0x21f3bd=[_0x901d('0x65'),'online',_0x901d('0x66'),_0x901d('0x67'),_0x901d('0x68'),'lastPauseAt',_0x901d('0x46'),'address',_0x901d('0x57'),_0x901d('0x58'),_0x901d('0x69'),'smsPause',_0x901d('0x5b'),_0x901d('0x6a'),_0x901d('0x5a'),_0x901d('0x6b'),_0x901d('0x6c'),_0x901d('0x6d'),'smsCapacity',_0x901d('0x6e'),_0x901d('0x6f'),_0x901d('0x70'),_0x901d('0x71'),_0x901d('0x72'),_0x901d('0x73'),'whatsappCurrentCapacity',_0x901d('0x74'),'chatStatus','openchannelStatus','mailStatus','smsStatus',_0x901d('0x62'),_0x901d('0x5f'),_0x901d('0x4d'),'chatStatusTime',_0x901d('0x75'),'mailStatusTime',_0x901d('0x76'),_0x901d('0x77'),_0x901d('0x78'),_0x901d('0x79'),_0x901d('0x42'),_0x901d('0x7a'),_0x901d('0x7b'),_0x901d('0x7c'),_0x901d('0x7d'),_0x901d('0x7e')],_0x45c730=[_0x901d('0x57'),_0x901d('0x58'),_0x901d('0x69'),_0x901d('0x59'),'whatsappPause','faxPause',_0x901d('0x5a'),_0x901d('0x4c')];Promise[_0x901d('0x7f')]()[_0x901d('0x16')](function(){var _0x109e0a=_[_0x901d('0x3a')](db[_0x901d('0x4e')]['rawAttributes'],function(_0x596a04){return{'name':_0x596a04['fieldName'],'type':_0x596a04[_0x901d('0x80')][_0x901d('0x81')]};});_0x4afe28[_0x901d('0x82')][_0x901d('0x83')]=_0x901d('0x84');_0x4afe28[_0x901d('0x82')][_0x901d('0x4c')]=!![];_0xaa7394=qs[_0x901d('0x85')](_0x109e0a,_0x4afe28);_0xaa7394[_0x901d('0x86')]=!![];if(_0x4afe28['user']['role']===_0x901d('0x87')){var _0x2df0e2={'params':{'id':_0x4afe28[_0x901d('0x87')][_0x901d('0x88')]},'query':{'section':_0x901d('0x15'),'role':_0x901d('0x84'),'online':!![],'nolimit':_0x4afe28[_0x901d('0x82')][_0x901d('0x89')],'sort':_0x4afe28[_0x901d('0x82')][_0x901d('0x8a')],'filter':_0x4afe28['query'][_0x901d('0x41')],'raw':!![]}};return db[_0x901d('0x8b')]['getResources'](_0x2df0e2);}return db['User'][_0x901d('0x8c')](_0xaa7394);})[_0x901d('0x16')](function(_0x4b156c){_0x26e6a2[_0x901d('0xb')]=_0x4b156c[_0x901d('0xb')];_0x2aa9b4=_0x4b156c[_0x901d('0x8d')];return getRealtimeAgents();})[_0x901d('0x16')](function(_0x56c84f){_0x3e3487=_0x56c84f[_0x901d('0x8d')];return _0x2aa9b4[_0x901d('0x3a')](function(_0x461d92){var _0x36f4b2=_[_0x901d('0x48')](_0x3e3487,['id',_0x461d92['id']]);if(_0x36f4b2)_[_0x901d('0x1a')](_0x461d92,_['pick'](_[_0x901d('0x8e')](_0x36f4b2,_0x45c730),_0x21f3bd));_0x461d92[_0x901d('0x8f')]=getAgentStatus(_0x461d92);return _0x461d92;});})[_0x901d('0x16')](function(_0x5763ef){if(_0x4afe28[_0x901d('0x82')][_0x901d('0x90')]){var _0x40ac8e=_['filter'](_0x5763ef,['globalStatus',_0x4afe28['query'][_0x901d('0x90')]]);if(_0x4afe28[_0x901d('0x82')]['pauseTypeFilter']){_0x40ac8e=_['filter'](_0x40ac8e,[_0x901d('0x68'),_0x4afe28[_0x901d('0x82')][_0x901d('0x91')]]);}}_0x26e6a2[_0x901d('0x8d')]=_0x40ac8e||_0x5763ef;return _0x26e6a2;})[_0x901d('0x16')](respondWithFilteredResult(_0xd7fbb3,_0xaa7394))['catch'](handleError(_0xd7fbb3,null));};exports[_0x901d('0x92')]=function(_0x1bd974,_0x1df423){var _0x1db2d9=['mail',_0x901d('0x93'),'sms',_0x901d('0x94'),'fax',_0x901d('0x95'),_0x901d('0x1b')];var _0x2782cf={'count':0x0,'rows':[]},_0x225a90={},_0x1c7b52,_0xb7f695,_0x408194,_0x598a53,_0x4461ab;Promise[_0x901d('0x7f')]()['then'](function(){if(_0x1bd974[_0x901d('0x82')]['channel']){if(!_['includes'](_0x1db2d9,_0x1bd974['query']['channel'][_0x901d('0x96')]()))throw new Error(_0x901d('0x97'));_0x1c7b52=_0x1bd974['query'][_0x901d('0x98')][_0x901d('0x96')]();}var _0x36d240=_[_0x901d('0x51')](_0x1c7b52)+_0x901d('0x4f');var _0x5135b6=_[_0x901d('0x3a')](db[_0x36d240][_0x901d('0x99')],function(_0x412e5b){return{'name':_0x412e5b['fieldName'],'type':_0x412e5b[_0x901d('0x80')][_0x901d('0x81')]};});_0x225a90=qs[_0x901d('0x85')](_0x5135b6,_0x1bd974);if(_0x1bd974[_0x901d('0x87')][_0x901d('0x83')]===_0x901d('0x87')){var _0x283ccf={'params':{'id':_0x1bd974[_0x901d('0x87')][_0x901d('0x88')]},'query':{'section':_0x1c7b52===_0x901d('0x1b')&&_0x1bd974[_0x901d('0x82')][_0x901d('0x80')]===_0x901d('0x9a')?'QueueCampaigns':_[_0x901d('0x51')](_0x1c7b52)+_0x901d('0x1c'),'type':_0x1bd974[_0x901d('0x82')][_0x901d('0x80')],'nolimit':!![],'sort':_0x901d('0x11'),'filter':_0x1bd974[_0x901d('0x82')][_0x901d('0x41')]}};return db[_0x901d('0x8b')]['getResources'](_0x283ccf);}return db[_0x36d240][_0x901d('0x8c')](_0x225a90);})[_0x901d('0x16')](function(_0x448f71){_0x2782cf['count']=_0x448f71[_0x901d('0xb')];_0xb7f695=_0x448f71[_0x901d('0x8d')];return getRealtimeQueues(_0x1bd974,_0x1c7b52);})[_0x901d('0x16')](function(_0x34f33f){_0x598a53=_0x34f33f[_0x901d('0x8d')];return getRealtimeAgents();})[_0x901d('0x16')](function(_0xbcdf2b){_0x408194=_0xbcdf2b[_0x901d('0x8d')];if(_0x1c7b52!=_0x901d('0x1b'))return;return getRealtimeVoiceQueueChannels();})[_0x901d('0x16')](function(_0x28b640){_0x4461ab=_0x28b640?_0x28b640[_0x901d('0x8d')]:[];return initializeQueues(_0xb7f695,_0x598a53,_0x1c7b52,_0x1bd974[_0x901d('0x82')][_0x901d('0x80')]);})[_0x901d('0x16')](function(_0x368b79){var _0x5a95a9=_0x368b79[_0x901d('0x3a')](function(_0x263297){if(_0x1c7b52===_0x901d('0x1b'))return getVoiceQueueAgents(_0x263297,_0xb7f695,_0x408194,_0x4461ab);else return getQueueAgents(_0x263297,_0x408194,_0x1c7b52);});return Promise[_0x901d('0x9b')](_0x5a95a9);})[_0x901d('0x16')](function(_0x35317f){_0x2782cf['rows']=_0x35317f;return _0x2782cf;})[_0x901d('0x16')](respondWithFilteredResult(_0x1df423,_0x225a90))[_0x901d('0x1f')](handleError(_0x1df423,null));};
\ No newline at end of file