Built motion from commit 932cf0d0.|2.5.42
[motion2.git] / server / api / realtime / realtime.controller.js
index 91f8de8..cca65e5 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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(_0xd9f102,_0x5a0d28){var _0x2652e4=function(_0x5021a1){while(--_0x5021a1){_0xd9f102['push'](_0xd9f102['shift']());}};_0x2652e4(++_0x5a0d28);}(_0x01d9,0x6c));var _0x901d=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x01d9[_0x321bb2];return _0x9c12ed;};'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
+var _0x2eb2=['voice','then','format','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','available','paused','outbound','push','pTalking','originated','message','dialActive','dialMethod','Trunk','startPredictive','startProgressive','erlangCallToSecond','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime','agents','loggedInDb','waiting','talking','busy','merge','pick','filter','queue','length','connectedlinenum','internal','toString','find','getMembers','UserId','accountcode','online','voiceStatus','User','startCase','Pause','unknown','chatPause','faxPause','openchannelPause','voicePause','whatsappPause','every','idle','pause','chatStatus','faxStatus','openchannelStatus','smsStatus','whatsappStatus','getAgents','lastLoginAt','lastPauseAt','pauseType','address','mailPause','smsPause','chatCapacity','openchannelCapacity','mailCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','mailStatus','openchannelStatusTime','mailStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','resolve','map','rawAttributes','fieldName','type','query','role','getOptions','raw','user','agent','nolimit','sort','UserProfile','findAndCountAll','rows','omit','globalStatus','pauseTypeFilter','getQueues','mail','fax','whatsapp','Invalid\x20channel','key','Queues','getResources','all','lodash','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','http','offset','undefined','limit','count','set','Content-Range','error','stack','name','status','request','Agents','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','result','catch'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x2eb2,0x19f));var _0x22eb=function(_0x54d4fe,_0x55e869){_0x54d4fe=_0x54d4fe-0x0;var _0x1ab5bb=_0x2eb2[_0x54d4fe];return _0x1ab5bb;};'use strict';var util=require('util');var _=require(_0x22eb('0x0'));var jayson=require(_0x22eb('0x1'));var qs=require(_0x22eb('0x2'));var logger=require(_0x22eb('0x3'))(_0x22eb('0x4'));var db=require(_0x22eb('0x5'))['db'];var amiClient=jayson['client'][_0x22eb('0x6')]({'port':0x232a});var routingClient=jayson['client']['http']({'port':0x232c});function respondWithFilteredResult(_0x1dfef7,_0x10e116){return function(_0x35dd5b){if(_0x35dd5b){var _0x2a9850=typeof _0x10e116[_0x22eb('0x7')]===_0x22eb('0x8')&&typeof _0x10e116[_0x22eb('0x9')]===_0x22eb('0x8');var _0x419601=_0x35dd5b[_0x22eb('0xa')];var _0xb9c8a4=_0x2a9850?0x0:_0x10e116[_0x22eb('0x7')];var _0x489260=_0x2a9850?_0x35dd5b[_0x22eb('0xa')]:_0x10e116['offset']+_0x10e116['limit'];var _0x1aa348;if(_0x489260>=_0x419601){_0x489260=_0x419601;_0x1aa348=0xc8;}else{_0x1aa348=0xce;}_0x1dfef7['status'](_0x1aa348);return _0x1dfef7[_0x22eb('0xb')](_0x22eb('0xc'),_0xb9c8a4+'-'+_0x489260+'/'+_0x419601)['json'](_0x35dd5b);}return null;};}function handleError(_0x5068ea,_0x1f286c){_0x1f286c=_0x1f286c||0x1f4;return function(_0x189f05){logger[_0x22eb('0xd')](_0x189f05[_0x22eb('0xe')]);if(_0x189f05[_0x22eb('0xf')]){delete _0x189f05['name'];}_0x5068ea[_0x22eb('0x10')](_0x1f286c)['send'](_0x189f05);};}function getRealtimeAgents(){return new Promise(function(_0x1f5089,_0x55ede8){return amiClient[_0x22eb('0x11')](_0x22eb('0x12'),{})['then'](function(_0x48b63c){if(_0x48b63c['error'])throw new Error(_0x22eb('0x13'));var _0x5245fe=_0x48b63c['result'];return routingClient[_0x22eb('0x11')]('Agents',{})['then'](function(_0xb7a73a){if(_0xb7a73a[_0x22eb('0xd')])throw new Error(_0x22eb('0x14'));var _0x1ff041=_0xb7a73a[_0x22eb('0x15')];return _0x1f5089(_['merge']({},_0x5245fe,_0x1ff041));});})[_0x22eb('0x16')](function(_0x12bbd1){_0x55ede8(_0x12bbd1);});});}function getRealtimeQueues(_0x10d182,_0x410c25){return new Promise(function(_0x36be50,_0x517313){var _0x2eb115=_0x410c25===_0x22eb('0x17')?amiClient:routingClient;return _0x2eb115[_0x22eb('0x11')](_['startCase'](_0x410c25)+'Queues',_0x10d182)[_0x22eb('0x18')](function(_0x267d97){if(_0x267d97[_0x22eb('0xd')])throw new Error(util[_0x22eb('0x19')](_0x22eb('0x1a'),_0x410c25));return _0x36be50(_0x267d97[_0x22eb('0x15')]);})[_0x22eb('0x16')](function(_0x4e7e69){_0x517313(_0x4e7e69);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x2e8f7c,_0x11edbd){return amiClient[_0x22eb('0x11')](_0x22eb('0x1b'),{})[_0x22eb('0x18')](function(_0x4da252){if(_0x4da252[_0x22eb('0xd')])throw new Error(_0x22eb('0x1c'));return _0x2e8f7c(_0x4da252[_0x22eb('0x15')]);})['catch'](function(_0xe0783c){_0x11edbd(_0xe0783c);});});}function initializeQueues(_0x259847,_0x4b409a,_0x32a4b6,_0x222ef3){var _0x1e3015=[_0x22eb('0x1d'),_0x22eb('0x1e'),'waiting','talking',_0x22eb('0x1f')];if(_0x32a4b6===_0x22eb('0x17')&&_0x222ef3===_0x22eb('0x20')){_0x1e3015[_0x22eb('0x21')](_0x22eb('0x22'),_0x22eb('0x23'),_0x22eb('0x24'),_0x22eb('0x25'),_0x22eb('0x26'),_0x22eb('0x27'),_0x22eb('0x28'),_0x22eb('0x29'),'erlangCalls',_0x22eb('0x2a'),'erlangAbandonmentRate',_0x22eb('0x2b'),_0x22eb('0x2c'),_0x22eb('0x2d'),_0x22eb('0x2e'),_0x22eb('0x2f'),_0x22eb('0x30'),_0x22eb('0x31'),_0x22eb('0x32'),_0x22eb('0x33'),_0x22eb('0x34'),'predictiveIntervalAvgTalktime');}return _0x259847['map'](function(_0x239a41){var _0x5ceec1=_0x239a41['get']({'plain':!![]});_0x5ceec1[_0x22eb('0x35')]=[];_0x5ceec1[_0x22eb('0x1f')]=0x0;_0x5ceec1[_0x22eb('0x36')]=0x0;_0x5ceec1[_0x22eb('0x1d')]=0x0;_0x5ceec1[_0x22eb('0x1e')]=0x0;_0x5ceec1[_0x22eb('0x37')]=0x0;if(_0x32a4b6===_0x22eb('0x17')){_0x5ceec1[_0x22eb('0x38')]=0x0;_0x5ceec1[_0x22eb('0x39')]=0x0;if(_0x222ef3===_0x22eb('0x20')){_0x5ceec1['pTalking']=0x0;_0x5ceec1[_0x22eb('0x23')]=0x0;}}var _0x47be01=_['find'](_0x4b409a,['id',_0x5ceec1['id']]);if(_0x47be01)_[_0x22eb('0x3a')](_0x5ceec1,_[_0x22eb('0x3b')](_0x47be01,_0x1e3015));return _0x5ceec1;});}function updateAgentVoiceStatus(_0x48e47e,_0x42e9bd,_0x121c04){var _0x236def=_[_0x22eb('0x3c')](_0x121c04,[_0x22eb('0x3d'),_0x42e9bd['name']]);if(_0x236def[_0x22eb('0x3e')]===0x0)return _0x48e47e[_0x22eb('0x39')]=!![];if(_['some'](_0x236def,[_0x22eb('0x3f'),_0x48e47e[_0x22eb('0x40')][_0x22eb('0x41')]()]))return _0x48e47e[_0x22eb('0x38')]=!![];if(!_0x48e47e[_0x22eb('0x38')])return _0x48e47e['busy']=!![];}function getVoiceQueueAgents(_0x51c8b5,_0x2b1ae1,_0x6cd651,_0x541153){var _0x595d76=_[_0x22eb('0x42')](_0x2b1ae1,['id',_0x51c8b5['id']]);if(!_0x595d76)return _0x51c8b5;return _0x595d76[_0x22eb('0x43')]({'raw':!![]})['then'](function(_0x1d977c){for(var _0x3377eb=0x0;_0x3377eb<_0x1d977c[_0x22eb('0x3e')];_0x3377eb++){var _0x2a8517=_[_0x22eb('0x42')](_0x6cd651,['id',_0x1d977c[_0x3377eb][_0x22eb('0x44')]]);if(!_0x2a8517){_0x2a8517={'id':_0x1d977c[_0x3377eb]['UserId'],'name':_0x1d977c[_0x3377eb][_0x22eb('0x44')],'accountcode':'','online':![]};}var _0x3d2d1d={'id':_0x2a8517['id'],'name':_0x2a8517['name'],'internal':_0x2a8517[_0x22eb('0x45')],'online':Boolean(_0x2a8517[_0x22eb('0x46')]),'paused':Boolean(_0x1d977c[_0x3377eb][_0x22eb('0x1f')])};if(_0x2a8517[_0x22eb('0x47')]===_0x22eb('0x38'))updateAgentVoiceStatus(_0x3d2d1d,_0x51c8b5,_0x541153);if(_0x3d2d1d[_0x22eb('0x46')])_0x51c8b5[_0x22eb('0x36')]++;if(_0x3d2d1d[_0x22eb('0x39')])_0x51c8b5[_0x22eb('0x39')]++;if(_0x3d2d1d[_0x22eb('0x1f')]&&!_0x3d2d1d[_0x22eb('0x39')]&&!_0x3d2d1d[_0x22eb('0x38')])_0x51c8b5[_0x22eb('0x1f')]++;_0x51c8b5[_0x22eb('0x35')][_0x22eb('0x21')](_0x3d2d1d);}return _0x51c8b5;});}function getQueueAgents(_0x471657,_0x6996b4,_0x46e3ec){var _0x507f21=_0x22eb('0x48')+_[_0x22eb('0x49')](_0x46e3ec)+'Queue';var _0x10462d=_0x46e3ec+_0x22eb('0x4a');return db[_0x507f21]['findAll']({'where':{[_['startCase'](_0x46e3ec)+'QueueId']:_0x471657['id']},'raw':!![]})[_0x22eb('0x18')](function(_0x1efc65){for(var _0x4e4c6d=0x0;_0x4e4c6d<_0x1efc65['length'];_0x4e4c6d++){var _0xa7c642=_[_0x22eb('0x42')](_0x6996b4,['id',_0x1efc65[_0x4e4c6d][_0x22eb('0x44')]]);if(!_0xa7c642){_0xa7c642={'id':_0x1efc65[_0x4e4c6d][_0x22eb('0x44')],'name':_0x1efc65[_0x4e4c6d][_0x22eb('0x44')],'online':![],['pauseField']:![]};}var _0x3b30a3={'id':_0xa7c642['id'],'name':_0xa7c642[_0x22eb('0xf')],'online':Boolean(_0xa7c642[_0x22eb('0x46')]),'paused':Boolean(_0xa7c642[_0x10462d])};if(_0x3b30a3['online'])_0x471657['loggedInDb']++;_0x471657[_0x22eb('0x35')]['push'](_0x3b30a3);}return _0x471657;});}function isIdle(_0x5e695c){return _0x5e695c==='idle'||_0x5e695c===_0x22eb('0x4b')||_0x5e695c==='unavailable'||_0x5e695c==='ringing'||_['isNil'](_0x5e695c);}function isAgentPaused(_0x517784,_0x36b174){var _0x4b5c03=[_0x517784[_0x22eb('0x4c')],_0x517784[_0x22eb('0x4d')],_0x517784['mailPause'],_0x517784[_0x22eb('0x4e')],_0x517784['smsPause'],_0x517784[_0x22eb('0x4f')],_0x517784[_0x22eb('0x50')]];if(!_0x36b174)return _[_0x22eb('0x51')](_0x4b5c03);var _0x111cbe=_[_0x22eb('0x3c')](_0x4b5c03);return _0x111cbe[_0x22eb('0x3e')]>0x0&&_0x111cbe[_0x22eb('0x3e')]<_0x4b5c03[_0x22eb('0x3e')]?!![]:![];}function isAgentIdle(_0x11942d){if(_0x11942d['voiceStatus']!==_0x22eb('0x52')&&_0x11942d[_0x22eb('0x4f')]){_0x11942d['voiceStatus']=_0x22eb('0x53');return![];}return _[_0x22eb('0x51')]([_0x11942d[_0x22eb('0x54')],_0x11942d[_0x22eb('0x55')],_0x11942d['mailStatus'],_0x11942d[_0x22eb('0x56')],_0x11942d[_0x22eb('0x57')],_0x11942d[_0x22eb('0x47')],_0x11942d[_0x22eb('0x58')]],isIdle);}function getAgentStatus(_0x447177){var _0x10393b='unknown';if(isAgentPaused(_0x447177))_0x10393b=_0x22eb('0x53');else if(isAgentPaused(_0x447177,!![]))_0x10393b='*pause';else if(isAgentIdle(_0x447177))_0x10393b=_0x22eb('0x52');else _0x10393b='busy';return _0x10393b;}exports[_0x22eb('0x59')]=function(_0x254b53,_0x4028ef){var _0x2c1b87={'count':0x0,'rows':[]},_0x3f03df={},_0x4aa0c5,_0x4896ed,_0xfbf2e7=['userpic',_0x22eb('0x46'),_0x22eb('0x5a'),_0x22eb('0x5b'),_0x22eb('0x5c'),_0x22eb('0x5b'),_0x22eb('0x40'),_0x22eb('0x5d'),_0x22eb('0x4c'),_0x22eb('0x4e'),_0x22eb('0x5e'),_0x22eb('0x5f'),'whatsappPause',_0x22eb('0x4d'),_0x22eb('0x4f'),_0x22eb('0x60'),_0x22eb('0x61'),_0x22eb('0x62'),_0x22eb('0x63'),_0x22eb('0x64'),_0x22eb('0x65'),_0x22eb('0x66'),_0x22eb('0x67'),_0x22eb('0x68'),_0x22eb('0x69'),_0x22eb('0x6a'),_0x22eb('0x6b'),'chatStatus','openchannelStatus',_0x22eb('0x6c'),_0x22eb('0x57'),_0x22eb('0x58'),_0x22eb('0x55'),_0x22eb('0x47'),'chatStatusTime',_0x22eb('0x6d'),_0x22eb('0x6e'),'smsStatusTime','whatsappStatusTime',_0x22eb('0x6f'),_0x22eb('0x70'),_0x22eb('0x3d'),_0x22eb('0x71'),_0x22eb('0x72'),_0x22eb('0x73'),_0x22eb('0x74'),_0x22eb('0x75')],_0x8e3864=[_0x22eb('0x4c'),_0x22eb('0x4e'),_0x22eb('0x5e'),_0x22eb('0x5f'),_0x22eb('0x50'),_0x22eb('0x4d'),'voicePause',_0x22eb('0x46')];Promise[_0x22eb('0x76')]()[_0x22eb('0x18')](function(){var _0x5dbc43=_[_0x22eb('0x77')](db['User'][_0x22eb('0x78')],function(_0x5347b4){return{'name':_0x5347b4[_0x22eb('0x79')],'type':_0x5347b4[_0x22eb('0x7a')]['key']};});_0x254b53[_0x22eb('0x7b')][_0x22eb('0x7c')]='agent';_0x254b53['query'][_0x22eb('0x46')]=!![];_0x3f03df=qs[_0x22eb('0x7d')](_0x5dbc43,_0x254b53);_0x3f03df[_0x22eb('0x7e')]=!![];if(_0x254b53[_0x22eb('0x7f')][_0x22eb('0x7c')]===_0x22eb('0x7f')){var _0x4f5eee={'params':{'id':_0x254b53[_0x22eb('0x7f')]['userProfileId']},'query':{'section':'Agents','role':_0x22eb('0x80'),'online':!![],'nolimit':_0x254b53[_0x22eb('0x7b')][_0x22eb('0x81')],'sort':_0x254b53[_0x22eb('0x7b')][_0x22eb('0x82')],'filter':_0x254b53[_0x22eb('0x7b')][_0x22eb('0x3c')],'raw':!![]}};return db[_0x22eb('0x83')]['getResources'](_0x4f5eee);}return db['User'][_0x22eb('0x84')](_0x3f03df);})[_0x22eb('0x18')](function(_0x49f182){_0x2c1b87[_0x22eb('0xa')]=_0x49f182[_0x22eb('0xa')];_0x4aa0c5=_0x49f182[_0x22eb('0x85')];return getRealtimeAgents();})[_0x22eb('0x18')](function(_0x40faf6){_0x4896ed=_0x40faf6[_0x22eb('0x85')];return _0x4aa0c5['map'](function(_0x3dd49b){var _0x29d4a7=_[_0x22eb('0x42')](_0x4896ed,['id',_0x3dd49b['id']]);if(_0x29d4a7)_['merge'](_0x3dd49b,_['pick'](_[_0x22eb('0x86')](_0x29d4a7,_0x8e3864),_0xfbf2e7));_0x3dd49b[_0x22eb('0x87')]=getAgentStatus(_0x3dd49b);return _0x3dd49b;});})[_0x22eb('0x18')](function(_0x5ebeb5){if(_0x254b53[_0x22eb('0x7b')]['globalStatusFilter']){var _0x1a305d=_[_0x22eb('0x3c')](_0x5ebeb5,[_0x22eb('0x87'),_0x254b53[_0x22eb('0x7b')]['globalStatusFilter']]);if(_0x254b53[_0x22eb('0x7b')][_0x22eb('0x88')]){_0x1a305d=_[_0x22eb('0x3c')](_0x1a305d,[_0x22eb('0x5c'),_0x254b53[_0x22eb('0x7b')][_0x22eb('0x88')]]);}}_0x2c1b87[_0x22eb('0x85')]=_0x1a305d||_0x5ebeb5;return _0x2c1b87;})[_0x22eb('0x18')](respondWithFilteredResult(_0x4028ef,_0x3f03df))[_0x22eb('0x16')](handleError(_0x4028ef,null));};exports[_0x22eb('0x89')]=function(_0x14006f,_0x5b4e6a){var _0x1d0749=[_0x22eb('0x8a'),'chat','sms','openchannel',_0x22eb('0x8b'),_0x22eb('0x8c'),'voice'];var _0x10726f={'count':0x0,'rows':[]},_0x15e08a={},_0xe6e71d,_0x41c50e,_0x8cbc83,_0x4ab4f8,_0x5e01b5;Promise[_0x22eb('0x76')]()[_0x22eb('0x18')](function(){if(_0x14006f[_0x22eb('0x7b')]['channel']){if(!_['includes'](_0x1d0749,_0x14006f[_0x22eb('0x7b')]['channel']['toLowerCase']()))throw new Error(_0x22eb('0x8d'));_0xe6e71d=_0x14006f[_0x22eb('0x7b')]['channel']['toLowerCase']();}var _0x1e393a=_[_0x22eb('0x49')](_0xe6e71d)+'Queue';var _0x17f51b=_[_0x22eb('0x77')](db[_0x1e393a][_0x22eb('0x78')],function(_0x5823d0){return{'name':_0x5823d0[_0x22eb('0x79')],'type':_0x5823d0[_0x22eb('0x7a')][_0x22eb('0x8e')]};});_0x15e08a=qs[_0x22eb('0x7d')](_0x17f51b,_0x14006f);if(_0x14006f[_0x22eb('0x7f')]['role']===_0x22eb('0x7f')){var _0x2ecc24={'params':{'id':_0x14006f[_0x22eb('0x7f')]['userProfileId']},'query':{'section':_0xe6e71d==='voice'&&_0x14006f[_0x22eb('0x7b')][_0x22eb('0x7a')]===_0x22eb('0x20')?'QueueCampaigns':_[_0x22eb('0x49')](_0xe6e71d)+_0x22eb('0x8f'),'type':_0x14006f[_0x22eb('0x7b')]['type'],'nolimit':!![],'sort':_0x22eb('0xf'),'filter':_0x14006f['query']['filter']}};return db[_0x22eb('0x83')][_0x22eb('0x90')](_0x2ecc24);}return db[_0x1e393a][_0x22eb('0x84')](_0x15e08a);})['then'](function(_0x3fc402){_0x10726f[_0x22eb('0xa')]=_0x3fc402[_0x22eb('0xa')];_0x41c50e=_0x3fc402[_0x22eb('0x85')];return getRealtimeQueues(_0x14006f,_0xe6e71d);})[_0x22eb('0x18')](function(_0x545c0a){_0x4ab4f8=_0x545c0a[_0x22eb('0x85')];return getRealtimeAgents();})['then'](function(_0x36dde2){_0x8cbc83=_0x36dde2[_0x22eb('0x85')];if(_0xe6e71d!=_0x22eb('0x17'))return;return getRealtimeVoiceQueueChannels();})['then'](function(_0xe19621){_0x5e01b5=_0xe19621?_0xe19621[_0x22eb('0x85')]:[];return initializeQueues(_0x41c50e,_0x4ab4f8,_0xe6e71d,_0x14006f[_0x22eb('0x7b')][_0x22eb('0x7a')]);})[_0x22eb('0x18')](function(_0xeaf655){var _0x45b691=_0xeaf655[_0x22eb('0x77')](function(_0x1ef974){if(_0xe6e71d===_0x22eb('0x17'))return getVoiceQueueAgents(_0x1ef974,_0x41c50e,_0x8cbc83,_0x5e01b5);else return getQueueAgents(_0x1ef974,_0x8cbc83,_0xe6e71d);});return Promise[_0x22eb('0x91')](_0x45b691);})['then'](function(_0x30e721){_0x10726f[_0x22eb('0x85')]=_0x30e721;return _0x10726f;})[_0x22eb('0x18')](respondWithFilteredResult(_0x5b4e6a,_0x15e08a))[_0x22eb('0x16')](handleError(_0x5b4e6a,null));};
\ No newline at end of file