Built motion from commit 092f8824.|2.5.49
[motion2.git] / server / api / realtime / realtime.controller.js
index 26c4c1b..0e172bd 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(_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
+var _0x9957=['client','http','offset','limit','undefined','count','status','set','json','error','stack','name','send','request','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','startCase','Queues','Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues','result','catch','VoiceQueuesChannels','Unable\x20to\x20retrieve\x20voice\x20queues\x20channels','loggedIn','available','waiting','paused','outbound','push','pTalking','dialMethod','Trunk','startPredictive','startProgressive','erlangCalls','erlangCallToSecond','dialPredictiveInterval','dialPredictiveIntervalMinThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalAvgHoldtime','predictiveIntervalAvgTalktime','get','agents','loggedInDb','voice','find','pick','queue','length','busy','connectedlinenum','internal','toString','talking','getMembers','UserId','online','User','Queue','idle','unknown','unavailable','ringing','chatPause','mailPause','openchannelPause','smsPause','voicePause','whatsappPause','every','voiceStatus','chatStatus','faxStatus','openchannelStatus','smsStatus','whatsappStatus','*pause','fields','filter','includes','globalStatus','order','startsWith','DESC','ASC','sort','pause','pauseType','getAgents','userpic','lastLoginAt','lastPauseAt','address','chatCapacity','openchannelCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','smsCurrentCapacity','faxCurrentCapacity','mailStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','screenrecording','routealias','resolve','query','join','map','rawAttributes','fieldName','type','key','agent','getOptions','user','role','userProfileId','nolimit','getResources','findAndCountAll','rows','omit','globalStatusFilter','pauseTypeFilter','mail','chat','sms','openchannel','fax','channel','Invalid\x20channel','toLowerCase','UserProfile','all','util','lodash','jayson/promise','../../components/parsers/qs','api','../../mysqldb'];(function(_0x123355,_0x329a59){var _0x167777=function(_0x4bb7b0){while(--_0x4bb7b0){_0x123355['push'](_0x123355['shift']());}};_0x167777(++_0x329a59);}(_0x9957,0x93));var _0x7995=function(_0xbca1b1,_0x33f0ce){_0xbca1b1=_0xbca1b1-0x0;var _0x4e1686=_0x9957[_0xbca1b1];return _0x4e1686;};'use strict';var util=require(_0x7995('0x0'));var _=require(_0x7995('0x1'));var jayson=require(_0x7995('0x2'));var qs=require(_0x7995('0x3'));var logger=require('../../config/logger')(_0x7995('0x4'));var db=require(_0x7995('0x5'))['db'];var amiClient=jayson[_0x7995('0x6')][_0x7995('0x7')]({'port':0x232a});var routingClient=jayson['client'][_0x7995('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x1a36d8,_0x137b6b){return function(_0x219534){if(_0x219534){var _0xbda126=typeof _0x137b6b[_0x7995('0x8')]==='undefined'&&typeof _0x137b6b[_0x7995('0x9')]===_0x7995('0xa');var _0x4a64f7=_0x219534[_0x7995('0xb')];var _0x3116fb=_0xbda126?0x0:_0x137b6b[_0x7995('0x8')];var _0x35b5fe=_0xbda126?_0x219534[_0x7995('0xb')]:_0x137b6b[_0x7995('0x8')]+_0x137b6b[_0x7995('0x9')];var _0x524f7b;if(_0x35b5fe>=_0x4a64f7){_0x35b5fe=_0x4a64f7;_0x524f7b=0xc8;}else{_0x524f7b=0xce;}_0x1a36d8[_0x7995('0xc')](_0x524f7b);return _0x1a36d8[_0x7995('0xd')]('Content-Range',_0x3116fb+'-'+_0x35b5fe+'/'+_0x4a64f7)[_0x7995('0xe')](_0x219534);}return null;};}function handleError(_0x2cb37a,_0x19a27e){_0x19a27e=_0x19a27e||0x1f4;return function(_0x385f00){logger[_0x7995('0xf')](_0x385f00[_0x7995('0x10')]);if(_0x385f00[_0x7995('0x11')]){delete _0x385f00['name'];}_0x2cb37a['status'](_0x19a27e)[_0x7995('0x12')](_0x385f00);};}function getRealtimeAgents(){return new Promise(function(_0x2233dd,_0x24b5bb){return amiClient[_0x7995('0x13')](_0x7995('0x14'),{})[_0x7995('0x15')](function(_0x2202ce){if(_0x2202ce[_0x7995('0xf')])throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)');var _0x2eeacc=_0x2202ce['result'];return routingClient[_0x7995('0x13')](_0x7995('0x14'),{})[_0x7995('0x15')](function(_0x291317){if(_0x291317[_0x7995('0xf')])throw new Error(_0x7995('0x16'));var _0x4faa60=_0x291317['result'];return _0x2233dd(_[_0x7995('0x17')]({},_0x2eeacc,_0x4faa60));});})['catch'](function(_0x555f74){_0x24b5bb(_0x555f74);});});}function getRealtimeQueues(_0x3ec178,_0x3d463e){return new Promise(function(_0x4cbe10,_0x3a9b54){var _0x51f276=_0x3d463e==='voice'?amiClient:routingClient;return _0x51f276[_0x7995('0x13')](_[_0x7995('0x18')](_0x3d463e)+_0x7995('0x19'),_0x3ec178)[_0x7995('0x15')](function(_0x460924){if(_0x460924[_0x7995('0xf')])throw new Error(util['format'](_0x7995('0x1a'),_0x3d463e));return _0x4cbe10(_0x460924[_0x7995('0x1b')]);})[_0x7995('0x1c')](function(_0x285437){_0x3a9b54(_0x285437);});});}function getRealtimeVoiceQueueChannels(){return new Promise(function(_0x563799,_0x13bc35){return amiClient[_0x7995('0x13')](_0x7995('0x1d'),{})['then'](function(_0x39df42){if(_0x39df42[_0x7995('0xf')])throw new Error(_0x7995('0x1e'));return _0x563799(_0x39df42[_0x7995('0x1b')]);})[_0x7995('0x1c')](function(_0x2a307e){_0x13bc35(_0x2a307e);});});}function initializeQueues(_0x56691a,_0x47625f,_0x5911c3,_0x229742){var _0x49bc7e=[_0x7995('0x1f'),_0x7995('0x20'),_0x7995('0x21'),'talking',_0x7995('0x22')];if(_0x5911c3==='voice'&&_0x229742===_0x7995('0x23')){_0x49bc7e[_0x7995('0x24')](_0x7995('0x25'),'originated','message','dialActive',_0x7995('0x26'),_0x7995('0x27'),_0x7995('0x28'),_0x7995('0x29'),_0x7995('0x2a'),_0x7995('0x2b'),'erlangAbandonmentRate','erlangBusyFactor',_0x7995('0x2c'),'dialPredictiveIntervalMaxThreshold',_0x7995('0x2d'),_0x7995('0x2e'),_0x7995('0x2f'),_0x7995('0x30'),_0x7995('0x31'),'predictiveIntervalDroppedCallsCallersExit',_0x7995('0x32'),_0x7995('0x33'));}return _0x56691a['map'](function(_0x48db25){var _0x577412=_0x48db25[_0x7995('0x34')]({'plain':!![]});_0x577412[_0x7995('0x35')]=[];_0x577412['paused']=0x0;_0x577412[_0x7995('0x36')]=0x0;_0x577412['loggedIn']=0x0;_0x577412[_0x7995('0x20')]=0x0;_0x577412[_0x7995('0x21')]=0x0;if(_0x5911c3===_0x7995('0x37')){_0x577412['talking']=0x0;_0x577412['busy']=0x0;if(_0x229742===_0x7995('0x23')){_0x577412['pTalking']=0x0;_0x577412['originated']=0x0;}}var _0x3e99cd=_[_0x7995('0x38')](_0x47625f,['id',_0x577412['id']]);if(_0x3e99cd)_['merge'](_0x577412,_[_0x7995('0x39')](_0x3e99cd,_0x49bc7e));return _0x577412;});}function updateAgentVoiceStatus(_0x1922b4,_0x2b772f,_0x18667c){var _0x1e3dbf=_['filter'](_0x18667c,[_0x7995('0x3a'),_0x2b772f[_0x7995('0x11')]]);if(_0x1e3dbf[_0x7995('0x3b')]===0x0)return _0x1922b4[_0x7995('0x3c')]=!![];if(_['some'](_0x1e3dbf,[_0x7995('0x3d'),_0x1922b4[_0x7995('0x3e')][_0x7995('0x3f')]()]))return _0x1922b4[_0x7995('0x40')]=!![];if(!_0x1922b4[_0x7995('0x40')])return _0x1922b4[_0x7995('0x3c')]=!![];}function getVoiceQueueAgents(_0x5688a1,_0x183a68,_0x3be298,_0x8a1be0){var _0x2ea47f=_[_0x7995('0x38')](_0x183a68,['id',_0x5688a1['id']]);if(!_0x2ea47f)return _0x5688a1;return _0x2ea47f[_0x7995('0x41')]({'raw':!![]})[_0x7995('0x15')](function(_0x270c0e){for(var _0x1234e1=0x0;_0x1234e1<_0x270c0e[_0x7995('0x3b')];_0x1234e1++){var _0x6fe77b=_[_0x7995('0x38')](_0x3be298,['id',_0x270c0e[_0x1234e1][_0x7995('0x42')]]);if(!_0x6fe77b){_0x6fe77b={'id':_0x270c0e[_0x1234e1]['UserId'],'name':_0x270c0e[_0x1234e1]['UserId'],'accountcode':'','online':![]};}var _0x334dff={'id':_0x6fe77b['id'],'name':_0x6fe77b[_0x7995('0x11')],'internal':_0x6fe77b['accountcode'],'online':Boolean(_0x6fe77b['online']),'paused':Boolean(_0x270c0e[_0x1234e1][_0x7995('0x22')])};if(_0x6fe77b['voiceStatus']==='talking')updateAgentVoiceStatus(_0x334dff,_0x5688a1,_0x8a1be0);if(_0x334dff[_0x7995('0x43')])_0x5688a1[_0x7995('0x36')]++;if(_0x334dff[_0x7995('0x3c')])_0x5688a1['busy']++;if(_0x334dff[_0x7995('0x22')]&&!_0x334dff['busy']&&!_0x334dff[_0x7995('0x40')])_0x5688a1['paused']++;_0x5688a1['agents'][_0x7995('0x24')](_0x334dff);}return _0x5688a1;});}function getQueueAgents(_0x403f54,_0xc04e5,_0x3f1c35){var _0x599ecb=_0x7995('0x44')+_[_0x7995('0x18')](_0x3f1c35)+_0x7995('0x45');var _0x6c7bec=_0x3f1c35+'Pause';return db[_0x599ecb]['findAll']({'where':{[_[_0x7995('0x18')](_0x3f1c35)+'QueueId']:_0x403f54['id']},'raw':!![]})[_0x7995('0x15')](function(_0x59c153){for(var _0x2f435e=0x0;_0x2f435e<_0x59c153['length'];_0x2f435e++){var _0x1e795e=_[_0x7995('0x38')](_0xc04e5,['id',_0x59c153[_0x2f435e]['UserId']]);if(!_0x1e795e){_0x1e795e={'id':_0x59c153[_0x2f435e][_0x7995('0x42')],'name':_0x59c153[_0x2f435e][_0x7995('0x42')],'online':![],['pauseField']:![]};}var _0x314145={'id':_0x1e795e['id'],'name':_0x1e795e[_0x7995('0x11')],'online':Boolean(_0x1e795e['online']),'paused':Boolean(_0x1e795e[_0x6c7bec])};if(_0x314145[_0x7995('0x43')])_0x403f54[_0x7995('0x36')]++;_0x403f54[_0x7995('0x35')]['push'](_0x314145);}return _0x403f54;});}function isIdle(_0xe228a5){return _0xe228a5===_0x7995('0x46')||_0xe228a5===_0x7995('0x47')||_0xe228a5===_0x7995('0x48')||_0xe228a5===_0x7995('0x49')||_['isNil'](_0xe228a5);}function isAgentPaused(_0x1a5cec,_0xfb72b2){var _0x5921b9=[_0x1a5cec[_0x7995('0x4a')],_0x1a5cec['faxPause'],_0x1a5cec[_0x7995('0x4b')],_0x1a5cec[_0x7995('0x4c')],_0x1a5cec[_0x7995('0x4d')],_0x1a5cec[_0x7995('0x4e')],_0x1a5cec[_0x7995('0x4f')]];if(!_0xfb72b2)return _[_0x7995('0x50')](_0x5921b9);var _0x1579b9=_['filter'](_0x5921b9);return _0x1579b9[_0x7995('0x3b')]>0x0&&_0x1579b9[_0x7995('0x3b')]<_0x5921b9[_0x7995('0x3b')]?!![]:![];}function isAgentIdle(_0x4ffc8a){if(_0x4ffc8a[_0x7995('0x51')]!==_0x7995('0x46')&&_0x4ffc8a[_0x7995('0x4e')]){_0x4ffc8a['voiceStatus']='pause';return![];}return _['every']([_0x4ffc8a[_0x7995('0x52')],_0x4ffc8a[_0x7995('0x53')],_0x4ffc8a['mailStatus'],_0x4ffc8a[_0x7995('0x54')],_0x4ffc8a[_0x7995('0x55')],_0x4ffc8a[_0x7995('0x51')],_0x4ffc8a[_0x7995('0x56')]],isIdle);}function getAgentStatus(_0xc04004){var _0x528c8e=_0x7995('0x47');if(isAgentPaused(_0xc04004))_0x528c8e='pause';else if(isAgentPaused(_0xc04004,!![]))_0x528c8e=_0x7995('0x57');else if(isAgentIdle(_0xc04004))_0x528c8e=_0x7995('0x46');else _0x528c8e=_0x7995('0x3c');return _0x528c8e;}function getUpdatedSortOptions(_0x50c7b5){var _0x5e1f34={'fields':[],'order':null};var _0x54e2b1=_0x50c7b5['split'](',');_0x5e1f34[_0x7995('0x58')]=_[_0x7995('0x59')](_0x54e2b1,function(_0x1a861c){if(!_0x1a861c[_0x7995('0x5a')](_0x7995('0x5b')))return!![];_0x5e1f34[_0x7995('0x5c')]=_[_0x7995('0x5d')](_0x1a861c,'-')?_0x7995('0x5e'):_0x7995('0x5f');return![];});return _0x5e1f34;}function orderAgentsByStatus(_0x17ecd3,_0xa7af8c){return _0x17ecd3[_0x7995('0x60')](function(_0x3da72b,_0x35bea3){if(_0x3da72b[_0x7995('0x5b')]===_0x35bea3[_0x7995('0x5b')]&&_0x3da72b[_0x7995('0x5b')]===_0x7995('0x61')){if(_0xa7af8c===_0x7995('0x5e'))return(_0x3da72b['pauseType']||'')<(_0x35bea3[_0x7995('0x62')]||'')?0x1:-0x1;return _0x3da72b[_0x7995('0x62')]<_0x35bea3[_0x7995('0x62')]?-0x1:0x1;}else{if(_0xa7af8c===_0x7995('0x5e'))return _0x3da72b['globalStatus']<_0x35bea3['globalStatus']?0x1:-0x1;return _0x3da72b[_0x7995('0x5b')]<_0x35bea3[_0x7995('0x5b')]?-0x1:0x1;}});}exports[_0x7995('0x63')]=function(_0x332a85,_0x51c50b){var _0x13cd7b={'count':0x0,'rows':[]},_0x74ff38={},_0xef5044,_0x33c49c,_0x502d43,_0x5e2d97=[_0x7995('0x64'),_0x7995('0x43'),_0x7995('0x65'),_0x7995('0x66'),_0x7995('0x62'),_0x7995('0x66'),_0x7995('0x3e'),_0x7995('0x67'),'chatPause',_0x7995('0x4c'),_0x7995('0x4b'),_0x7995('0x4d'),_0x7995('0x4f'),'faxPause','voicePause',_0x7995('0x68'),_0x7995('0x69'),'mailCapacity',_0x7995('0x6a'),_0x7995('0x6b'),_0x7995('0x6c'),_0x7995('0x6d'),_0x7995('0x6e'),'mailCurrentCapacity',_0x7995('0x6f'),'whatsappCurrentCapacity',_0x7995('0x70'),_0x7995('0x52'),_0x7995('0x54'),_0x7995('0x71'),_0x7995('0x55'),_0x7995('0x56'),_0x7995('0x53'),_0x7995('0x51'),_0x7995('0x72'),_0x7995('0x73'),_0x7995('0x74'),_0x7995('0x75'),'whatsappStatusTime',_0x7995('0x76'),_0x7995('0x77'),_0x7995('0x3a'),_0x7995('0x78'),_0x7995('0x79'),'phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording',_0x7995('0x7a')],_0x40e5fc=[_0x7995('0x4a'),_0x7995('0x4c'),_0x7995('0x4b'),'smsPause',_0x7995('0x4f'),'faxPause','voicePause',_0x7995('0x43')];Promise[_0x7995('0x7b')]()[_0x7995('0x15')](function(){if(!_0x332a85[_0x7995('0x7c')][_0x7995('0x60')]||!_0x332a85[_0x7995('0x7c')][_0x7995('0x60')][_0x7995('0x5a')](_0x7995('0x5b')))return;var _0x2466df=getUpdatedSortOptions(_0x332a85['query'][_0x7995('0x60')]);_0x332a85[_0x7995('0x7c')][_0x7995('0x60')]=_0x2466df['fields'][_0x7995('0x7d')](',');_0xef5044=_0x2466df[_0x7995('0x5c')];})[_0x7995('0x15')](function(){var _0x3a7d9d=_[_0x7995('0x7e')](db[_0x7995('0x44')][_0x7995('0x7f')],function(_0x3adfd2){return{'name':_0x3adfd2[_0x7995('0x80')],'type':_0x3adfd2[_0x7995('0x81')][_0x7995('0x82')]};});_0x332a85['query']['role']=_0x7995('0x83');_0x332a85[_0x7995('0x7c')][_0x7995('0x43')]=!![];_0x74ff38=qs[_0x7995('0x84')](_0x3a7d9d,_0x332a85);_0x74ff38['raw']=!![];if(_0x332a85[_0x7995('0x85')][_0x7995('0x86')]==='user'){var _0x480fdb={'params':{'id':_0x332a85[_0x7995('0x85')][_0x7995('0x87')]},'query':{'section':'Agents','role':_0x7995('0x83'),'online':!![],'nolimit':_0x332a85['query'][_0x7995('0x88')],'sort':_0x332a85[_0x7995('0x7c')]['sort'],'filter':_0x332a85['query'][_0x7995('0x59')],'raw':!![]}};return db['UserProfile'][_0x7995('0x89')](_0x480fdb);}return db[_0x7995('0x44')][_0x7995('0x8a')](_0x74ff38);})[_0x7995('0x15')](function(_0x1a1873){_0x13cd7b[_0x7995('0xb')]=_0x1a1873[_0x7995('0xb')];_0x33c49c=_0x1a1873[_0x7995('0x8b')];return getRealtimeAgents();})[_0x7995('0x15')](function(_0x117317){_0x502d43=_0x117317[_0x7995('0x8b')];return _0x33c49c[_0x7995('0x7e')](function(_0x10a2f5){var _0x1ff436=_[_0x7995('0x38')](_0x502d43,['id',_0x10a2f5['id']]);if(_0x1ff436)_[_0x7995('0x17')](_0x10a2f5,_[_0x7995('0x39')](_[_0x7995('0x8c')](_0x1ff436,_0x40e5fc),_0x5e2d97));_0x10a2f5[_0x7995('0x5b')]=getAgentStatus(_0x10a2f5);return _0x10a2f5;});})[_0x7995('0x15')](function(_0x306fa9){var _0x1e8dad;if(_0x332a85[_0x7995('0x7c')][_0x7995('0x8d')]){_0x1e8dad=_[_0x7995('0x59')](_0x306fa9,[_0x7995('0x5b'),_0x332a85[_0x7995('0x7c')][_0x7995('0x8d')]]);if(_0x332a85['query'][_0x7995('0x8e')]){_0x1e8dad=_[_0x7995('0x59')](_0x1e8dad,['pauseType',_0x332a85['query'][_0x7995('0x8e')]]);}}if(_0x1e8dad)_0x306fa9=_0x1e8dad;if(!_0xef5044)return _0x306fa9;return orderAgentsByStatus(_0x306fa9,_0xef5044);})[_0x7995('0x15')](function(_0x2d45d5){_0x13cd7b[_0x7995('0x8b')]=_0x2d45d5;return _0x13cd7b;})[_0x7995('0x15')](respondWithFilteredResult(_0x51c50b,_0x74ff38))[_0x7995('0x1c')](handleError(_0x51c50b,null));};exports['getQueues']=function(_0x2f8a2d,_0xb68962){var _0x3fea6a=[_0x7995('0x8f'),_0x7995('0x90'),_0x7995('0x91'),_0x7995('0x92'),_0x7995('0x93'),'whatsapp',_0x7995('0x37')];var _0x2b8217={'count':0x0,'rows':[]},_0x5c04c9={},_0x479271,_0xd24c64,_0xf8c2ed,_0x18e1a2,_0x3db7a9;Promise[_0x7995('0x7b')]()['then'](function(){if(_0x2f8a2d[_0x7995('0x7c')][_0x7995('0x94')]){if(!_['includes'](_0x3fea6a,_0x2f8a2d[_0x7995('0x7c')][_0x7995('0x94')]['toLowerCase']()))throw new Error(_0x7995('0x95'));_0x479271=_0x2f8a2d['query'][_0x7995('0x94')][_0x7995('0x96')]();}var _0x3ab421=_[_0x7995('0x18')](_0x479271)+_0x7995('0x45');var _0x5d16da=_[_0x7995('0x7e')](db[_0x3ab421][_0x7995('0x7f')],function(_0x38b37f){return{'name':_0x38b37f['fieldName'],'type':_0x38b37f[_0x7995('0x81')][_0x7995('0x82')]};});_0x5c04c9=qs[_0x7995('0x84')](_0x5d16da,_0x2f8a2d);if(_0x2f8a2d[_0x7995('0x85')]['role']===_0x7995('0x85')){var _0xf59a39={'params':{'id':_0x2f8a2d[_0x7995('0x85')]['userProfileId']},'query':{'section':_0x479271==='voice'&&_0x2f8a2d[_0x7995('0x7c')][_0x7995('0x81')]==='outbound'?'QueueCampaigns':_[_0x7995('0x18')](_0x479271)+_0x7995('0x19'),'type':_0x2f8a2d[_0x7995('0x7c')][_0x7995('0x81')],'nolimit':!![],'sort':_0x7995('0x11'),'filter':_0x2f8a2d['query']['filter']}};return db[_0x7995('0x97')]['getResources'](_0xf59a39);}return db[_0x3ab421]['findAndCountAll'](_0x5c04c9);})[_0x7995('0x15')](function(_0x3b731e){_0x2b8217[_0x7995('0xb')]=_0x3b731e['count'];_0xd24c64=_0x3b731e[_0x7995('0x8b')];return getRealtimeQueues(_0x2f8a2d,_0x479271);})[_0x7995('0x15')](function(_0x2b0b79){_0x18e1a2=_0x2b0b79[_0x7995('0x8b')];return getRealtimeAgents();})[_0x7995('0x15')](function(_0x5799d1){_0xf8c2ed=_0x5799d1[_0x7995('0x8b')];if(_0x479271!=_0x7995('0x37'))return;return getRealtimeVoiceQueueChannels();})[_0x7995('0x15')](function(_0x14b942){_0x3db7a9=_0x14b942?_0x14b942['rows']:[];return initializeQueues(_0xd24c64,_0x18e1a2,_0x479271,_0x2f8a2d[_0x7995('0x7c')][_0x7995('0x81')]);})['then'](function(_0x310272){var _0x20683e=_0x310272['map'](function(_0x135f7a){if(_0x479271==='voice')return getVoiceQueueAgents(_0x135f7a,_0xd24c64,_0xf8c2ed,_0x3db7a9);else return getQueueAgents(_0x135f7a,_0xf8c2ed,_0x479271);});return Promise[_0x7995('0x98')](_0x20683e);})['then'](function(_0x21f496){_0x2b8217['rows']=_0x21f496;return _0x2b8217;})[_0x7995('0x15')](respondWithFilteredResult(_0xb68962,_0x5c04c9))[_0x7995('0x1c')](handleError(_0xb68962,null));};
\ No newline at end of file