Built motion from commit ab870f9e.|2.5.44
[motion2.git] / server / api / realtime / realtime.controller.js
index eebae17..18bbafe 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4975=['undefined','limit','count','status','error','stack','name','send','request','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','catch','voice','Queues','format','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','VoiceQueuesChannels','talking','outbound','push','pTalking','dialMethod','Trunk','startPredictive','erlangAbandonmentRate','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','get','agents','paused','loggedIn','available','busy','originated','find','pick','filter','queue','length','some','internal','toString','getMembers','UserId','accountcode','online','voiceStatus','loggedInDb','User','startCase','Pause','idle','unknown','unavailable','isNil','chatPause','mailPause','openchannelPause','smsPause','whatsappPause','every','voicePause','pause','chatStatus','mailStatus','whatsappStatus','*pause','userpic','lastLoginAt','pauseType','lastPauseAt','address','faxPause','chatCapacity','openchannelCapacity','mailCapacity','smsCapacity','faxCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatus','faxStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','map','rawAttributes','fieldName','type','query','role','agent','getOptions','raw','user','userProfileId','Agents','UserProfile','findAndCountAll','rows','omit','globalStatusFilter','globalStatus','pauseTypeFilter','mail','chat','sms','openchannel','fax','resolve','channel','includes','toLowerCase','key','QueueCampaigns','getResources','all','util','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','offset'];(function(_0x30197d,_0x23e443){var _0x3d8b5b=function(_0x398c54){while(--_0x398c54){_0x30197d['push'](_0x30197d['shift']());}};_0x3d8b5b(++_0x23e443);}(_0x4975,0x86));var _0x5497=function(_0x443835,_0x2b20fd){_0x443835=_0x443835-0x0;var _0x3cd51f=_0x4975[_0x443835];return _0x3cd51f;};'use strict';var util=require(_0x5497('0x0'));var _=require('lodash');var jayson=require(_0x5497('0x1'));var qs=require(_0x5497('0x2'));var logger=require(_0x5497('0x3'))(_0x5497('0x4'));var db=require(_0x5497('0x5'))['db'];var amiClient=jayson[_0x5497('0x6')][_0x5497('0x7')]({'port':0x232a});var routingClient=jayson[_0x5497('0x6')][_0x5497('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x5d5272,_0x539a27){return function(_0x37e48d){if(_0x37e48d){var _0x4f563d=typeof _0x539a27[_0x5497('0x8')]===_0x5497('0x9')&&typeof _0x539a27[_0x5497('0xa')]==='undefined';var _0x42af11=_0x37e48d['count'];var _0x1f63d8=_0x4f563d?0x0:_0x539a27[_0x5497('0x8')];var _0x2ec5a4=_0x4f563d?_0x37e48d[_0x5497('0xb')]:_0x539a27[_0x5497('0x8')]+_0x539a27[_0x5497('0xa')];var _0x3e7886;if(_0x2ec5a4>=_0x42af11){_0x2ec5a4=_0x42af11;_0x3e7886=0xc8;}else{_0x3e7886=0xce;}_0x5d5272[_0x5497('0xc')](_0x3e7886);return _0x5d5272['set']('Content-Range',_0x1f63d8+'-'+_0x2ec5a4+'/'+_0x42af11)['json'](_0x37e48d);}return null;};}function handleError(_0xc250bb,_0x1b23df){_0x1b23df=_0x1b23df||0x1f4;return function(_0x1bb794){logger[_0x5497('0xd')](_0x1bb794[_0x5497('0xe')]);if(_0x1bb794[_0x5497('0xf')]){delete _0x1bb794[_0x5497('0xf')];}_0xc250bb[_0x5497('0xc')](_0x1b23df)[_0x5497('0x10')](_0x1bb794);};}function getRealtimeAgents(){return new Promise(function(_0x1a4c74,_0x55f590){return amiClient[_0x5497('0x11')]('Agents',{})[_0x5497('0x12')](function(_0x2bfd8a){if(_0x2bfd8a[_0x5497('0xd')])throw new Error(_0x5497('0x13'));var _0x37c18e=_0x2bfd8a[_0x5497('0x14')];return routingClient[_0x5497('0x11')]('Agents',{})['then'](function(_0x3f4d20){if(_0x3f4d20[_0x5497('0xd')])throw new Error(_0x5497('0x15'));var _0x5d9e24=_0x3f4d20[_0x5497('0x14')];return _0x1a4c74(_[_0x5497('0x16')]({},_0x37c18e,_0x5d9e24));});})[_0x5497('0x17')](function(_0x43da2c){_0x55f590(_0x43da2c);});});}function getRealtimeQueues(_0x1b1b43,_0x1f6f18){return new Promise(function(_0x16d378,_0x10226f){var _0x2e3960=_0x1f6f18===_0x5497('0x18')?amiClient:routingClient;return _0x2e3960[_0x5497('0x11')](_['startCase'](_0x1f6f18)+_0x5497('0x19'),_0x1b1b43)['then'](function(_0x19200a){if(_0x19200a[_0x5497('0xd')])throw new Error(util[_0x5497('0x1a')](_0x5497('0x1b'),_0x1f6f18));return _0x16d378(_0x19200a[_0x5497('0x14')]);})[_0x5497('0x17')](function(_0x5018fa){_0x10226f(_0x5018fa);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x54043a,_0x1eefce){return amiClient[_0x5497('0x11')](_0x5497('0x1c'),{})[_0x5497('0x12')](function(_0x5223b5){if(_0x5223b5[_0x5497('0xd')])throw new Error('Unable\x20to\x20retrieve\x20voice\x20queues\x20channels');return _0x54043a(_0x5223b5[_0x5497('0x14')]);})[_0x5497('0x17')](function(_0x429d36){_0x1eefce(_0x429d36);});});}function initializeQueues(_0x34a1a5,_0x163a30,_0x31cd01,_0x48b835){var _0x4af5f4=['loggedIn','available','waiting',_0x5497('0x1d'),'paused'];if(_0x31cd01==='voice'&&_0x48b835===_0x5497('0x1e')){_0x4af5f4[_0x5497('0x1f')](_0x5497('0x20'),'originated','message','dialActive',_0x5497('0x21'),_0x5497('0x22'),_0x5497('0x23'),'startProgressive','erlangCalls','erlangCallToSecond',_0x5497('0x24'),'erlangBusyFactor',_0x5497('0x25'),_0x5497('0x26'),_0x5497('0x27'),'predictiveIntervalAvailable',_0x5497('0x28'),_0x5497('0x29'),'predictiveIntervalDroppedCallsTimeout',_0x5497('0x2a'),_0x5497('0x2b'),_0x5497('0x2c'));}return _0x34a1a5['map'](function(_0x3395f6){var _0x2fe1f2=_0x3395f6[_0x5497('0x2d')]({'plain':!![]});_0x2fe1f2[_0x5497('0x2e')]=[];_0x2fe1f2[_0x5497('0x2f')]=0x0;_0x2fe1f2['loggedInDb']=0x0;_0x2fe1f2[_0x5497('0x30')]=0x0;_0x2fe1f2[_0x5497('0x31')]=0x0;_0x2fe1f2['waiting']=0x0;if(_0x31cd01===_0x5497('0x18')){_0x2fe1f2[_0x5497('0x1d')]=0x0;_0x2fe1f2[_0x5497('0x32')]=0x0;if(_0x48b835===_0x5497('0x1e')){_0x2fe1f2[_0x5497('0x20')]=0x0;_0x2fe1f2[_0x5497('0x33')]=0x0;}}var _0x580e86=_[_0x5497('0x34')](_0x163a30,['id',_0x2fe1f2['id']]);if(_0x580e86)_['merge'](_0x2fe1f2,_[_0x5497('0x35')](_0x580e86,_0x4af5f4));return _0x2fe1f2;});}function updateAgentVoiceStatus(_0x212199,_0x2751f5,_0x5ab18c){var _0x4ec5f7=_[_0x5497('0x36')](_0x5ab18c,[_0x5497('0x37'),_0x2751f5[_0x5497('0xf')]]);if(_0x4ec5f7[_0x5497('0x38')]===0x0)return _0x212199[_0x5497('0x32')]=!![];if(_[_0x5497('0x39')](_0x4ec5f7,['connectedlinenum',_0x212199[_0x5497('0x3a')][_0x5497('0x3b')]()]))return _0x212199[_0x5497('0x1d')]=!![];if(!_0x212199[_0x5497('0x1d')])return _0x212199[_0x5497('0x32')]=!![];}function getVoiceQueueAgents(_0x468902,_0x1e3b6a,_0x179635,_0x59627b){var _0x544065=_[_0x5497('0x34')](_0x1e3b6a,['id',_0x468902['id']]);if(!_0x544065)return _0x468902;return _0x544065[_0x5497('0x3c')]({'raw':!![]})[_0x5497('0x12')](function(_0x3c0339){for(var _0x15029d=0x0;_0x15029d<_0x3c0339[_0x5497('0x38')];_0x15029d++){var _0x4299be=_['find'](_0x179635,['id',_0x3c0339[_0x15029d][_0x5497('0x3d')]]);if(!_0x4299be){_0x4299be={'id':_0x3c0339[_0x15029d][_0x5497('0x3d')],'name':_0x3c0339[_0x15029d][_0x5497('0x3d')],'accountcode':'','online':![]};}var _0x35993c={'id':_0x4299be['id'],'name':_0x4299be[_0x5497('0xf')],'internal':_0x4299be[_0x5497('0x3e')],'online':Boolean(_0x4299be[_0x5497('0x3f')]),'paused':Boolean(_0x3c0339[_0x15029d]['paused'])};if(_0x4299be[_0x5497('0x40')]===_0x5497('0x1d'))updateAgentVoiceStatus(_0x35993c,_0x468902,_0x59627b);if(_0x35993c[_0x5497('0x3f')])_0x468902[_0x5497('0x41')]++;if(_0x35993c[_0x5497('0x32')])_0x468902[_0x5497('0x32')]++;if(_0x35993c[_0x5497('0x2f')]&&!_0x35993c[_0x5497('0x32')]&&!_0x35993c[_0x5497('0x1d')])_0x468902[_0x5497('0x2f')]++;_0x468902['agents'][_0x5497('0x1f')](_0x35993c);}return _0x468902;});}function getQueueAgents(_0x4a9fd7,_0x40822a,_0x9fc24){var _0x26ef01=_0x5497('0x42')+_[_0x5497('0x43')](_0x9fc24)+'Queue';var _0x1f7c90=_0x9fc24+_0x5497('0x44');return db[_0x26ef01]['findAll']({'where':{[_[_0x5497('0x43')](_0x9fc24)+'QueueId']:_0x4a9fd7['id']},'raw':!![]})[_0x5497('0x12')](function(_0x4aa6b8){for(var _0x133606=0x0;_0x133606<_0x4aa6b8[_0x5497('0x38')];_0x133606++){var _0x2e8c6a=_[_0x5497('0x34')](_0x40822a,['id',_0x4aa6b8[_0x133606][_0x5497('0x3d')]]);if(!_0x2e8c6a){_0x2e8c6a={'id':_0x4aa6b8[_0x133606]['UserId'],'name':_0x4aa6b8[_0x133606]['UserId'],'online':![],['pauseField']:![]};}var _0x498de5={'id':_0x2e8c6a['id'],'name':_0x2e8c6a['name'],'online':Boolean(_0x2e8c6a[_0x5497('0x3f')]),'paused':Boolean(_0x2e8c6a[_0x1f7c90])};if(_0x498de5[_0x5497('0x3f')])_0x4a9fd7[_0x5497('0x41')]++;_0x4a9fd7[_0x5497('0x2e')][_0x5497('0x1f')](_0x498de5);}return _0x4a9fd7;});}function isIdle(_0x33a733){return _0x33a733===_0x5497('0x45')||_0x33a733===_0x5497('0x46')||_0x33a733===_0x5497('0x47')||_0x33a733==='ringing'||_[_0x5497('0x48')](_0x33a733);}function isAgentPaused(_0x18db5b,_0x1a9138){var _0x52a189=[_0x18db5b[_0x5497('0x49')],_0x18db5b['faxPause'],_0x18db5b[_0x5497('0x4a')],_0x18db5b[_0x5497('0x4b')],_0x18db5b[_0x5497('0x4c')],_0x18db5b['voicePause'],_0x18db5b[_0x5497('0x4d')]];if(!_0x1a9138)return _[_0x5497('0x4e')](_0x52a189);var _0x515c3e=_[_0x5497('0x36')](_0x52a189);return _0x515c3e['length']>0x0&&_0x515c3e[_0x5497('0x38')]<_0x52a189['length']?!![]:![];}function isAgentIdle(_0x416f76){if(_0x416f76[_0x5497('0x40')]!==_0x5497('0x45')&&_0x416f76[_0x5497('0x4f')]){_0x416f76[_0x5497('0x40')]=_0x5497('0x50');return![];}return _[_0x5497('0x4e')]([_0x416f76[_0x5497('0x51')],_0x416f76['faxStatus'],_0x416f76[_0x5497('0x52')],_0x416f76['openchannelStatus'],_0x416f76['smsStatus'],_0x416f76[_0x5497('0x40')],_0x416f76[_0x5497('0x53')]],isIdle);}function getAgentStatus(_0x592120){var _0x2ddccd=_0x5497('0x46');if(isAgentPaused(_0x592120))_0x2ddccd=_0x5497('0x50');else if(isAgentPaused(_0x592120,!![]))_0x2ddccd=_0x5497('0x54');else if(isAgentIdle(_0x592120))_0x2ddccd='idle';else _0x2ddccd=_0x5497('0x32');return _0x2ddccd;}exports['getAgents']=function(_0x493dd0,_0xf9ebd3){var _0x33dd07={'count':0x0,'rows':[]},_0x2f7ec8={},_0x49c85a,_0x4b37d2,_0x2e2ac9=[_0x5497('0x55'),'online',_0x5497('0x56'),'lastPauseAt',_0x5497('0x57'),_0x5497('0x58'),'internal',_0x5497('0x59'),'chatPause','openchannelPause',_0x5497('0x4a'),_0x5497('0x4c'),'whatsappPause',_0x5497('0x5a'),_0x5497('0x4f'),_0x5497('0x5b'),_0x5497('0x5c'),_0x5497('0x5d'),_0x5497('0x5e'),'whatsappCapacity',_0x5497('0x5f'),'chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity',_0x5497('0x60'),_0x5497('0x61'),_0x5497('0x62'),'chatStatus',_0x5497('0x63'),'mailStatus','smsStatus',_0x5497('0x53'),_0x5497('0x64'),_0x5497('0x40'),_0x5497('0x65'),_0x5497('0x66'),_0x5497('0x67'),'smsStatusTime',_0x5497('0x68'),_0x5497('0x69'),_0x5497('0x6a'),_0x5497('0x37'),'destconnectedlinenum',_0x5497('0x6b'),_0x5497('0x6c'),_0x5497('0x6d'),_0x5497('0x6e')],_0x5acedf=['chatPause',_0x5497('0x4b'),_0x5497('0x4a'),_0x5497('0x4c'),'whatsappPause',_0x5497('0x5a'),'voicePause','online'];Promise['resolve']()[_0x5497('0x12')](function(){var _0x1ca4d8=_[_0x5497('0x6f')](db['User'][_0x5497('0x70')],function(_0x1e1b12){return{'name':_0x1e1b12[_0x5497('0x71')],'type':_0x1e1b12[_0x5497('0x72')]['key']};});_0x493dd0[_0x5497('0x73')][_0x5497('0x74')]=_0x5497('0x75');_0x493dd0['query'][_0x5497('0x3f')]=!![];_0x2f7ec8=qs[_0x5497('0x76')](_0x1ca4d8,_0x493dd0);_0x2f7ec8[_0x5497('0x77')]=!![];if(_0x493dd0[_0x5497('0x78')][_0x5497('0x74')]===_0x5497('0x78')){var _0x15c05b={'params':{'id':_0x493dd0['user'][_0x5497('0x79')]},'query':{'section':_0x5497('0x7a'),'role':_0x5497('0x75'),'online':!![],'nolimit':_0x493dd0[_0x5497('0x73')]['nolimit'],'sort':_0x493dd0['query']['sort'],'filter':_0x493dd0[_0x5497('0x73')][_0x5497('0x36')],'raw':!![]}};return db[_0x5497('0x7b')]['getResources'](_0x15c05b);}return db[_0x5497('0x42')][_0x5497('0x7c')](_0x2f7ec8);})[_0x5497('0x12')](function(_0x464df3){_0x33dd07[_0x5497('0xb')]=_0x464df3[_0x5497('0xb')];_0x49c85a=_0x464df3[_0x5497('0x7d')];return getRealtimeAgents();})[_0x5497('0x12')](function(_0x21da3d){_0x4b37d2=_0x21da3d[_0x5497('0x7d')];return _0x49c85a[_0x5497('0x6f')](function(_0x5a8b3a){var _0x15d5a4=_[_0x5497('0x34')](_0x4b37d2,['id',_0x5a8b3a['id']]);if(_0x15d5a4)_[_0x5497('0x16')](_0x5a8b3a,_['pick'](_[_0x5497('0x7e')](_0x15d5a4,_0x5acedf),_0x2e2ac9));_0x5a8b3a['globalStatus']=getAgentStatus(_0x5a8b3a);return _0x5a8b3a;});})[_0x5497('0x12')](function(_0x469e97){if(_0x493dd0['query'][_0x5497('0x7f')]){var _0x2c07bb=_[_0x5497('0x36')](_0x469e97,[_0x5497('0x80'),_0x493dd0['query'][_0x5497('0x7f')]]);if(_0x493dd0[_0x5497('0x73')][_0x5497('0x81')]){_0x2c07bb=_['filter'](_0x2c07bb,[_0x5497('0x57'),_0x493dd0[_0x5497('0x73')]['pauseTypeFilter']]);}}_0x33dd07[_0x5497('0x7d')]=_0x2c07bb||_0x469e97;return _0x33dd07;})[_0x5497('0x12')](respondWithFilteredResult(_0xf9ebd3,_0x2f7ec8))[_0x5497('0x17')](handleError(_0xf9ebd3,null));};exports['getQueues']=function(_0x4dbd4e,_0x3cc968){var _0x3faf97=[_0x5497('0x82'),_0x5497('0x83'),_0x5497('0x84'),_0x5497('0x85'),_0x5497('0x86'),'whatsapp','voice'];var _0x166daa={'count':0x0,'rows':[]},_0x24a160={},_0x540362,_0x15ca59,_0x268722,_0x7415ba,_0x510078;Promise[_0x5497('0x87')]()[_0x5497('0x12')](function(){if(_0x4dbd4e['query'][_0x5497('0x88')]){if(!_[_0x5497('0x89')](_0x3faf97,_0x4dbd4e[_0x5497('0x73')][_0x5497('0x88')][_0x5497('0x8a')]()))throw new Error('Invalid\x20channel');_0x540362=_0x4dbd4e[_0x5497('0x73')][_0x5497('0x88')][_0x5497('0x8a')]();}var _0x23e259=_[_0x5497('0x43')](_0x540362)+'Queue';var _0x394bf3=_[_0x5497('0x6f')](db[_0x23e259][_0x5497('0x70')],function(_0x9e3f4){return{'name':_0x9e3f4['fieldName'],'type':_0x9e3f4[_0x5497('0x72')][_0x5497('0x8b')]};});_0x24a160=qs['getOptions'](_0x394bf3,_0x4dbd4e);if(_0x4dbd4e[_0x5497('0x78')][_0x5497('0x74')]===_0x5497('0x78')){var _0x3a8cf9={'params':{'id':_0x4dbd4e['user']['userProfileId']},'query':{'section':_0x540362==='voice'&&_0x4dbd4e['query']['type']===_0x5497('0x1e')?_0x5497('0x8c'):_[_0x5497('0x43')](_0x540362)+_0x5497('0x19'),'type':_0x4dbd4e[_0x5497('0x73')]['type'],'nolimit':!![],'sort':'name','filter':_0x4dbd4e[_0x5497('0x73')][_0x5497('0x36')]}};return db[_0x5497('0x7b')][_0x5497('0x8d')](_0x3a8cf9);}return db[_0x23e259][_0x5497('0x7c')](_0x24a160);})[_0x5497('0x12')](function(_0x1f31fb){_0x166daa[_0x5497('0xb')]=_0x1f31fb[_0x5497('0xb')];_0x15ca59=_0x1f31fb[_0x5497('0x7d')];return getRealtimeQueues(_0x4dbd4e,_0x540362);})['then'](function(_0x1515f1){_0x7415ba=_0x1515f1[_0x5497('0x7d')];return getRealtimeAgents();})[_0x5497('0x12')](function(_0x25f06e){_0x268722=_0x25f06e[_0x5497('0x7d')];if(_0x540362!=_0x5497('0x18'))return;return getRealtimeVoiceQueueChannels();})['then'](function(_0x1ef7fc){_0x510078=_0x1ef7fc?_0x1ef7fc['rows']:[];return initializeQueues(_0x15ca59,_0x7415ba,_0x540362,_0x4dbd4e[_0x5497('0x73')][_0x5497('0x72')]);})[_0x5497('0x12')](function(_0x5b0f9d){var _0x59960b=_0x5b0f9d[_0x5497('0x6f')](function(_0x27ca0f){if(_0x540362===_0x5497('0x18'))return getVoiceQueueAgents(_0x27ca0f,_0x15ca59,_0x268722,_0x510078);else return getQueueAgents(_0x27ca0f,_0x268722,_0x540362);});return Promise[_0x5497('0x8e')](_0x59960b);})[_0x5497('0x12')](function(_0x1876d2){_0x166daa[_0x5497('0x7d')]=_0x1876d2;return _0x166daa;})[_0x5497('0x12')](respondWithFilteredResult(_0x3cc968,_0x24a160))['catch'](handleError(_0x3cc968,null));};
\ No newline at end of file
+var _0x5fab=['pause','every','faxStatus','mailStatus','whatsappStatus','*pause','getAgents','lastLoginAt','lastPauseAt','pauseType','internal','address','mailPause','faxPause','chatCapacity','mailCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','smsPause','resolve','fieldName','type','role','agent','query','getOptions','raw','user','userProfileId','nolimit','sort','UserProfile','getResources','findAndCountAll','rows','globalStatus','globalStatusFilter','pauseTypeFilter','getQueues','mail','sms','openchannel','fax','channel','includes','toLowerCase','rawAttributes','key','QueueCampaigns','all','util','lodash','../../components/parsers/qs','../../config/logger','api','../../mysqldb','client','http','offset','undefined','limit','count','status','set','Content-Range','json','error','name','send','request','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','result','merge','catch','voice','startCase','Queues','format','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','available','waiting','talking','paused','outbound','push','pTalking','originated','message','dialActive','dialMethod','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond','erlangAbandonmentRate','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalTotalCalls','predictiveIntervalAvgHoldtime','map','get','agents','busy','pick','filter','queue','toString','find','UserId','accountcode','online','voiceStatus','User','Queue','QueueId','length','loggedInDb','idle','unknown','unavailable','ringing','isNil','chatPause','openchannelPause','voicePause','whatsappPause'];(function(_0x6acb69,_0xd36dbf){var _0x29a021=function(_0x374293){while(--_0x374293){_0x6acb69['push'](_0x6acb69['shift']());}};_0x29a021(++_0xd36dbf);}(_0x5fab,0x177));var _0xb5fa=function(_0x4e9df2,_0x36818e){_0x4e9df2=_0x4e9df2-0x0;var _0x9fe790=_0x5fab[_0x4e9df2];return _0x9fe790;};'use strict';var util=require(_0xb5fa('0x0'));var _=require(_0xb5fa('0x1'));var jayson=require('jayson/promise');var qs=require(_0xb5fa('0x2'));var logger=require(_0xb5fa('0x3'))(_0xb5fa('0x4'));var db=require(_0xb5fa('0x5'))['db'];var amiClient=jayson[_0xb5fa('0x6')][_0xb5fa('0x7')]({'port':0x232a});var routingClient=jayson[_0xb5fa('0x6')][_0xb5fa('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x10361d,_0x44df89){return function(_0x4a0249){if(_0x4a0249){var _0x5d70f6=typeof _0x44df89[_0xb5fa('0x8')]===_0xb5fa('0x9')&&typeof _0x44df89[_0xb5fa('0xa')]==='undefined';var _0x410eff=_0x4a0249[_0xb5fa('0xb')];var _0x2cf4a5=_0x5d70f6?0x0:_0x44df89['offset'];var _0x5b5ea8=_0x5d70f6?_0x4a0249[_0xb5fa('0xb')]:_0x44df89[_0xb5fa('0x8')]+_0x44df89[_0xb5fa('0xa')];var _0x44e6c8;if(_0x5b5ea8>=_0x410eff){_0x5b5ea8=_0x410eff;_0x44e6c8=0xc8;}else{_0x44e6c8=0xce;}_0x10361d[_0xb5fa('0xc')](_0x44e6c8);return _0x10361d[_0xb5fa('0xd')](_0xb5fa('0xe'),_0x2cf4a5+'-'+_0x5b5ea8+'/'+_0x410eff)[_0xb5fa('0xf')](_0x4a0249);}return null;};}function handleError(_0x309740,_0x4d3576){_0x4d3576=_0x4d3576||0x1f4;return function(_0x2ad830){logger[_0xb5fa('0x10')](_0x2ad830['stack']);if(_0x2ad830[_0xb5fa('0x11')]){delete _0x2ad830['name'];}_0x309740[_0xb5fa('0xc')](_0x4d3576)[_0xb5fa('0x12')](_0x2ad830);};}function getRealtimeAgents(){return new Promise(function(_0x40c914,_0xca8d82){return amiClient[_0xb5fa('0x13')]('Agents',{})['then'](function(_0x38e964){if(_0x38e964[_0xb5fa('0x10')])throw new Error(_0xb5fa('0x14'));var _0x27c8f7=_0x38e964['result'];return routingClient['request'](_0xb5fa('0x15'),{})[_0xb5fa('0x16')](function(_0x32e9e5){if(_0x32e9e5[_0xb5fa('0x10')])throw new Error(_0xb5fa('0x17'));var _0x13e82b=_0x32e9e5[_0xb5fa('0x18')];return _0x40c914(_[_0xb5fa('0x19')]({},_0x27c8f7,_0x13e82b));});})[_0xb5fa('0x1a')](function(_0x368cb1){_0xca8d82(_0x368cb1);});});}function getRealtimeQueues(_0x3c8d53,_0x1f5064){return new Promise(function(_0x5cd822,_0x432bfa){var _0x519e20=_0x1f5064===_0xb5fa('0x1b')?amiClient:routingClient;return _0x519e20['request'](_[_0xb5fa('0x1c')](_0x1f5064)+_0xb5fa('0x1d'),_0x3c8d53)['then'](function(_0x40dfdf){if(_0x40dfdf[_0xb5fa('0x10')])throw new Error(util[_0xb5fa('0x1e')]('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0x1f5064));return _0x5cd822(_0x40dfdf[_0xb5fa('0x18')]);})[_0xb5fa('0x1a')](function(_0x444237){_0x432bfa(_0x444237);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x542348,_0x224ec8){return amiClient['request'](_0xb5fa('0x1f'),{})[_0xb5fa('0x16')](function(_0x11053a){if(_0x11053a[_0xb5fa('0x10')])throw new Error(_0xb5fa('0x20'));return _0x542348(_0x11053a[_0xb5fa('0x18')]);})[_0xb5fa('0x1a')](function(_0x20d649){_0x224ec8(_0x20d649);});});}function initializeQueues(_0x568870,_0x4ec294,_0x5bdf11,_0x5a1c39){var _0x28a350=[_0xb5fa('0x21'),_0xb5fa('0x22'),_0xb5fa('0x23'),_0xb5fa('0x24'),_0xb5fa('0x25')];if(_0x5bdf11===_0xb5fa('0x1b')&&_0x5a1c39===_0xb5fa('0x26')){_0x28a350[_0xb5fa('0x27')](_0xb5fa('0x28'),_0xb5fa('0x29'),_0xb5fa('0x2a'),_0xb5fa('0x2b'),_0xb5fa('0x2c'),_0xb5fa('0x2d'),_0xb5fa('0x2e'),_0xb5fa('0x2f'),_0xb5fa('0x30'),_0xb5fa('0x31'),_0xb5fa('0x32'),_0xb5fa('0x33'),_0xb5fa('0x34'),_0xb5fa('0x35'),_0xb5fa('0x36'),'predictiveIntervalAvailable',_0xb5fa('0x37'),'predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit',_0xb5fa('0x38'),'predictiveIntervalAvgTalktime');}return _0x568870[_0xb5fa('0x39')](function(_0x5876f1){var _0x5518b1=_0x5876f1[_0xb5fa('0x3a')]({'plain':!![]});_0x5518b1[_0xb5fa('0x3b')]=[];_0x5518b1['paused']=0x0;_0x5518b1['loggedInDb']=0x0;_0x5518b1[_0xb5fa('0x21')]=0x0;_0x5518b1[_0xb5fa('0x22')]=0x0;_0x5518b1[_0xb5fa('0x23')]=0x0;if(_0x5bdf11==='voice'){_0x5518b1[_0xb5fa('0x24')]=0x0;_0x5518b1[_0xb5fa('0x3c')]=0x0;if(_0x5a1c39==='outbound'){_0x5518b1[_0xb5fa('0x28')]=0x0;_0x5518b1[_0xb5fa('0x29')]=0x0;}}var _0x204d6b=_['find'](_0x4ec294,['id',_0x5518b1['id']]);if(_0x204d6b)_[_0xb5fa('0x19')](_0x5518b1,_[_0xb5fa('0x3d')](_0x204d6b,_0x28a350));return _0x5518b1;});}function updateAgentVoiceStatus(_0x24ef11,_0x55bdb7,_0x117694){var _0x1c818f=_[_0xb5fa('0x3e')](_0x117694,[_0xb5fa('0x3f'),_0x55bdb7['name']]);if(_0x1c818f['length']===0x0)return _0x24ef11['busy']=!![];if(_['some'](_0x1c818f,['connectedlinenum',_0x24ef11['internal'][_0xb5fa('0x40')]()]))return _0x24ef11['talking']=!![];if(!_0x24ef11[_0xb5fa('0x24')])return _0x24ef11[_0xb5fa('0x3c')]=!![];}function getVoiceQueueAgents(_0x36db1a,_0x30b288,_0x40c1c0,_0x269d21){var _0x4b4c4c=_['find'](_0x30b288,['id',_0x36db1a['id']]);if(!_0x4b4c4c)return _0x36db1a;return _0x4b4c4c['getMembers']({'raw':!![]})[_0xb5fa('0x16')](function(_0x4d23f1){for(var _0x73d425=0x0;_0x73d425<_0x4d23f1['length'];_0x73d425++){var _0x58aa97=_[_0xb5fa('0x41')](_0x40c1c0,['id',_0x4d23f1[_0x73d425][_0xb5fa('0x42')]]);if(!_0x58aa97){_0x58aa97={'id':_0x4d23f1[_0x73d425][_0xb5fa('0x42')],'name':_0x4d23f1[_0x73d425][_0xb5fa('0x42')],'accountcode':'','online':![]};}var _0x5bc93f={'id':_0x58aa97['id'],'name':_0x58aa97[_0xb5fa('0x11')],'internal':_0x58aa97[_0xb5fa('0x43')],'online':Boolean(_0x58aa97[_0xb5fa('0x44')]),'paused':Boolean(_0x4d23f1[_0x73d425][_0xb5fa('0x25')])};if(_0x58aa97[_0xb5fa('0x45')]==='talking')updateAgentVoiceStatus(_0x5bc93f,_0x36db1a,_0x269d21);if(_0x5bc93f[_0xb5fa('0x44')])_0x36db1a['loggedInDb']++;if(_0x5bc93f[_0xb5fa('0x3c')])_0x36db1a[_0xb5fa('0x3c')]++;if(_0x5bc93f[_0xb5fa('0x25')]&&!_0x5bc93f[_0xb5fa('0x3c')]&&!_0x5bc93f[_0xb5fa('0x24')])_0x36db1a[_0xb5fa('0x25')]++;_0x36db1a[_0xb5fa('0x3b')][_0xb5fa('0x27')](_0x5bc93f);}return _0x36db1a;});}function getQueueAgents(_0x4da448,_0x1c3c2c,_0xc03e44){var _0x59ae64=_0xb5fa('0x46')+_['startCase'](_0xc03e44)+_0xb5fa('0x47');var _0x5ae45a=_0xc03e44+'Pause';return db[_0x59ae64]['findAll']({'where':{[_[_0xb5fa('0x1c')](_0xc03e44)+_0xb5fa('0x48')]:_0x4da448['id']},'raw':!![]})[_0xb5fa('0x16')](function(_0x19e662){for(var _0x430f46=0x0;_0x430f46<_0x19e662[_0xb5fa('0x49')];_0x430f46++){var _0x10f354=_[_0xb5fa('0x41')](_0x1c3c2c,['id',_0x19e662[_0x430f46]['UserId']]);if(!_0x10f354){_0x10f354={'id':_0x19e662[_0x430f46][_0xb5fa('0x42')],'name':_0x19e662[_0x430f46][_0xb5fa('0x42')],'online':![],['pauseField']:![]};}var _0x4e0fe7={'id':_0x10f354['id'],'name':_0x10f354[_0xb5fa('0x11')],'online':Boolean(_0x10f354[_0xb5fa('0x44')]),'paused':Boolean(_0x10f354[_0x5ae45a])};if(_0x4e0fe7[_0xb5fa('0x44')])_0x4da448[_0xb5fa('0x4a')]++;_0x4da448[_0xb5fa('0x3b')][_0xb5fa('0x27')](_0x4e0fe7);}return _0x4da448;});}function isIdle(_0x1e1c2){return _0x1e1c2===_0xb5fa('0x4b')||_0x1e1c2===_0xb5fa('0x4c')||_0x1e1c2===_0xb5fa('0x4d')||_0x1e1c2===_0xb5fa('0x4e')||_[_0xb5fa('0x4f')](_0x1e1c2);}function isAgentPaused(_0x6ae261,_0x23be4c){var _0x42a359=[_0x6ae261[_0xb5fa('0x50')],_0x6ae261['faxPause'],_0x6ae261['mailPause'],_0x6ae261[_0xb5fa('0x51')],_0x6ae261['smsPause'],_0x6ae261[_0xb5fa('0x52')],_0x6ae261[_0xb5fa('0x53')]];if(!_0x23be4c)return _['every'](_0x42a359);var _0x4ef1d0=_[_0xb5fa('0x3e')](_0x42a359);return _0x4ef1d0[_0xb5fa('0x49')]>0x0&&_0x4ef1d0[_0xb5fa('0x49')]<_0x42a359[_0xb5fa('0x49')]?!![]:![];}function isAgentIdle(_0x3ffee0){if(_0x3ffee0['voiceStatus']!==_0xb5fa('0x4b')&&_0x3ffee0['voicePause']){_0x3ffee0[_0xb5fa('0x45')]=_0xb5fa('0x54');return![];}return _[_0xb5fa('0x55')]([_0x3ffee0['chatStatus'],_0x3ffee0[_0xb5fa('0x56')],_0x3ffee0[_0xb5fa('0x57')],_0x3ffee0['openchannelStatus'],_0x3ffee0['smsStatus'],_0x3ffee0[_0xb5fa('0x45')],_0x3ffee0[_0xb5fa('0x58')]],isIdle);}function getAgentStatus(_0x320745){var _0x3ffdb5=_0xb5fa('0x4c');if(isAgentPaused(_0x320745))_0x3ffdb5=_0xb5fa('0x54');else if(isAgentPaused(_0x320745,!![]))_0x3ffdb5=_0xb5fa('0x59');else if(isAgentIdle(_0x320745))_0x3ffdb5=_0xb5fa('0x4b');else _0x3ffdb5=_0xb5fa('0x3c');return _0x3ffdb5;}exports[_0xb5fa('0x5a')]=function(_0x25de19,_0x35cf5a){var _0x3ccfd1={'count':0x0,'rows':[]},_0x2799e7={},_0x23f235,_0x42c34f,_0x10830a=['userpic',_0xb5fa('0x44'),_0xb5fa('0x5b'),_0xb5fa('0x5c'),_0xb5fa('0x5d'),_0xb5fa('0x5c'),_0xb5fa('0x5e'),_0xb5fa('0x5f'),_0xb5fa('0x50'),_0xb5fa('0x51'),_0xb5fa('0x60'),'smsPause','whatsappPause',_0xb5fa('0x61'),_0xb5fa('0x52'),_0xb5fa('0x62'),'openchannelCapacity',_0xb5fa('0x63'),_0xb5fa('0x64'),_0xb5fa('0x65'),_0xb5fa('0x66'),_0xb5fa('0x67'),_0xb5fa('0x68'),_0xb5fa('0x69'),'smsCurrentCapacity',_0xb5fa('0x6a'),_0xb5fa('0x6b'),'chatStatus',_0xb5fa('0x6c'),_0xb5fa('0x57'),'smsStatus',_0xb5fa('0x58'),_0xb5fa('0x56'),_0xb5fa('0x45'),_0xb5fa('0x6d'),_0xb5fa('0x6e'),_0xb5fa('0x6f'),_0xb5fa('0x70'),_0xb5fa('0x71'),_0xb5fa('0x72'),_0xb5fa('0x73'),_0xb5fa('0x3f'),_0xb5fa('0x74'),_0xb5fa('0x75'),_0xb5fa('0x76'),_0xb5fa('0x77'),_0xb5fa('0x78')],_0x24acea=[_0xb5fa('0x50'),_0xb5fa('0x51'),_0xb5fa('0x60'),_0xb5fa('0x79'),_0xb5fa('0x53'),_0xb5fa('0x61'),'voicePause',_0xb5fa('0x44')];Promise[_0xb5fa('0x7a')]()[_0xb5fa('0x16')](function(){var _0x580d1a=_[_0xb5fa('0x39')](db[_0xb5fa('0x46')]['rawAttributes'],function(_0x44fd4a){return{'name':_0x44fd4a[_0xb5fa('0x7b')],'type':_0x44fd4a[_0xb5fa('0x7c')]['key']};});_0x25de19['query'][_0xb5fa('0x7d')]=_0xb5fa('0x7e');_0x25de19[_0xb5fa('0x7f')]['online']=!![];_0x2799e7=qs[_0xb5fa('0x80')](_0x580d1a,_0x25de19);_0x2799e7[_0xb5fa('0x81')]=!![];if(_0x25de19[_0xb5fa('0x82')][_0xb5fa('0x7d')]==='user'){var _0x55000b={'params':{'id':_0x25de19['user'][_0xb5fa('0x83')]},'query':{'section':_0xb5fa('0x15'),'role':_0xb5fa('0x7e'),'online':!![],'nolimit':_0x25de19['query'][_0xb5fa('0x84')],'sort':_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x85')],'filter':_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x3e')],'raw':!![]}};return db[_0xb5fa('0x86')][_0xb5fa('0x87')](_0x55000b);}return db[_0xb5fa('0x46')][_0xb5fa('0x88')](_0x2799e7);})[_0xb5fa('0x16')](function(_0x3a1db9){_0x3ccfd1[_0xb5fa('0xb')]=_0x3a1db9[_0xb5fa('0xb')];_0x23f235=_0x3a1db9[_0xb5fa('0x89')];return getRealtimeAgents();})[_0xb5fa('0x16')](function(_0x5eeaa1){_0x42c34f=_0x5eeaa1[_0xb5fa('0x89')];return _0x23f235['map'](function(_0x47193c){var _0x209213=_[_0xb5fa('0x41')](_0x42c34f,['id',_0x47193c['id']]);if(_0x209213)_[_0xb5fa('0x19')](_0x47193c,_[_0xb5fa('0x3d')](_['omit'](_0x209213,_0x24acea),_0x10830a));_0x47193c[_0xb5fa('0x8a')]=getAgentStatus(_0x47193c);return _0x47193c;});})['then'](function(_0x77a831){if(_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x8b')]){var _0x394386=_['filter'](_0x77a831,['globalStatus',_0x25de19['query'][_0xb5fa('0x8b')]]);if(_0x25de19[_0xb5fa('0x7f')][_0xb5fa('0x8c')]){_0x394386=_[_0xb5fa('0x3e')](_0x394386,[_0xb5fa('0x5d'),_0x25de19[_0xb5fa('0x7f')]['pauseTypeFilter']]);}}_0x3ccfd1[_0xb5fa('0x89')]=_0x394386||_0x77a831;return _0x3ccfd1;})['then'](respondWithFilteredResult(_0x35cf5a,_0x2799e7))['catch'](handleError(_0x35cf5a,null));};exports[_0xb5fa('0x8d')]=function(_0x4cba86,_0x5d11bb){var _0x4e2253=[_0xb5fa('0x8e'),'chat',_0xb5fa('0x8f'),_0xb5fa('0x90'),_0xb5fa('0x91'),'whatsapp','voice'];var _0xb1fcac={'count':0x0,'rows':[]},_0x2abe24={},_0x4c70d1,_0x2d0c95,_0x3c7cb4,_0x244892,_0x2aaa2c;Promise['resolve']()[_0xb5fa('0x16')](function(){if(_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x92')]){if(!_[_0xb5fa('0x93')](_0x4e2253,_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x92')][_0xb5fa('0x94')]()))throw new Error('Invalid\x20channel');_0x4c70d1=_0x4cba86[_0xb5fa('0x7f')]['channel'][_0xb5fa('0x94')]();}var _0x45790c=_['startCase'](_0x4c70d1)+_0xb5fa('0x47');var _0x212d4e=_[_0xb5fa('0x39')](db[_0x45790c][_0xb5fa('0x95')],function(_0x3034b0){return{'name':_0x3034b0[_0xb5fa('0x7b')],'type':_0x3034b0[_0xb5fa('0x7c')][_0xb5fa('0x96')]};});_0x2abe24=qs['getOptions'](_0x212d4e,_0x4cba86);if(_0x4cba86[_0xb5fa('0x82')][_0xb5fa('0x7d')]===_0xb5fa('0x82')){var _0x20ffa1={'params':{'id':_0x4cba86['user']['userProfileId']},'query':{'section':_0x4c70d1==='voice'&&_0x4cba86['query'][_0xb5fa('0x7c')]===_0xb5fa('0x26')?_0xb5fa('0x97'):_[_0xb5fa('0x1c')](_0x4c70d1)+'Queues','type':_0x4cba86['query'][_0xb5fa('0x7c')],'nolimit':!![],'sort':'name','filter':_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x3e')]}};return db[_0xb5fa('0x86')][_0xb5fa('0x87')](_0x20ffa1);}return db[_0x45790c]['findAndCountAll'](_0x2abe24);})[_0xb5fa('0x16')](function(_0x5c6b09){_0xb1fcac[_0xb5fa('0xb')]=_0x5c6b09[_0xb5fa('0xb')];_0x2d0c95=_0x5c6b09['rows'];return getRealtimeQueues(_0x4cba86,_0x4c70d1);})['then'](function(_0x391412){_0x244892=_0x391412[_0xb5fa('0x89')];return getRealtimeAgents();})[_0xb5fa('0x16')](function(_0x1bcca7){_0x3c7cb4=_0x1bcca7[_0xb5fa('0x89')];if(_0x4c70d1!=_0xb5fa('0x1b'))return;return getRealtimeVoiceQueueChannels();})[_0xb5fa('0x16')](function(_0x25b278){_0x2aaa2c=_0x25b278?_0x25b278[_0xb5fa('0x89')]:[];return initializeQueues(_0x2d0c95,_0x244892,_0x4c70d1,_0x4cba86[_0xb5fa('0x7f')][_0xb5fa('0x7c')]);})[_0xb5fa('0x16')](function(_0x86dfe9){var _0x53c7b5=_0x86dfe9['map'](function(_0x3dd9ab){if(_0x4c70d1==='voice')return getVoiceQueueAgents(_0x3dd9ab,_0x2d0c95,_0x3c7cb4,_0x2aaa2c);else return getQueueAgents(_0x3dd9ab,_0x3c7cb4,_0x4c70d1);});return Promise[_0xb5fa('0x98')](_0x53c7b5);})[_0xb5fa('0x16')](function(_0x502946){_0xb1fcac[_0xb5fa('0x89')]=_0x502946;return _0xb1fcac;})[_0xb5fa('0x16')](respondWithFilteredResult(_0x5d11bb,_0x2abe24))['catch'](handleError(_0x5d11bb,null));};
\ No newline at end of file