Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / components / realtime / agents.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x78f4=['omit','pick','filterAgentAttributes','jayson/promise','client','http','chatPause','faxPause','mailPause','openchannelPause','smsPause','voicePause','whatsappPause','every','filter','length','unknown','unavailable','ringing','voiceStatus','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','whatsappStatus','Agents','then','result','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','catch','getRealtimeAgents','*pause','idle','getAgentStatus','isArray','startCase','Queue','getAgents','all','map','uniq','value','getAgentIdsByQueues','includes','busy','resolve','User','findAll','name','pauseType','find','globalStatus','getSortedAgentsIdsByStatus','split','fields','order','DESC','ASC','fullname','internal','substring','indexOf','validateSortParameter','sort','toLowerCase','lastLoginAt','lastPauseAt','address','openchannelCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','faxCurrentCapacity','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','queue','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','routealias','online'];(function(_0x5f49b1,_0x2e245c){var _0x59e7a4=function(_0x20fc99){while(--_0x20fc99){_0x5f49b1['push'](_0x5f49b1['shift']());}};_0x59e7a4(++_0x2e245c);}(_0x78f4,0x10b));var _0x478f=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x78f4[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var jayson=require(_0x478f('0x0'));var db=require('../../mysqldb')['db'];var amiClient=jayson[_0x478f('0x1')]['http']({'port':0x232a});var routingClient=jayson[_0x478f('0x1')][_0x478f('0x2')]({'port':0x232c});function isAgentPaused(_0xe2e5dd,_0x4fb936){var _0x36eb4f=[_0xe2e5dd[_0x478f('0x3')],_0xe2e5dd[_0x478f('0x4')],_0xe2e5dd[_0x478f('0x5')],_0xe2e5dd[_0x478f('0x6')],_0xe2e5dd[_0x478f('0x7')],_0xe2e5dd[_0x478f('0x8')],_0xe2e5dd[_0x478f('0x9')]];if(!_0x4fb936)return _[_0x478f('0xa')](_0x36eb4f);var _0x6c924e=_[_0x478f('0xb')](_0x36eb4f);return _0x6c924e[_0x478f('0xc')]>0x0&&_0x6c924e[_0x478f('0xc')]<_0x36eb4f[_0x478f('0xc')]?!![]:![];}function isIdle(_0x304d25){return _0x304d25==='idle'||_0x304d25===_0x478f('0xd')||_0x304d25===_0x478f('0xe')||_0x304d25===_0x478f('0xf')||_['isNil'](_0x304d25);}function isAgentIdle(_0x49b231){if(_0x49b231[_0x478f('0x10')]!=='idle'&&_0x49b231[_0x478f('0x8')]){_0x49b231[_0x478f('0x10')]=_0x478f('0x11');return![];}return _[_0x478f('0xa')]([_0x49b231[_0x478f('0x12')],_0x49b231[_0x478f('0x13')],_0x49b231[_0x478f('0x14')],_0x49b231[_0x478f('0x15')],_0x49b231[_0x478f('0x16')],_0x49b231[_0x478f('0x10')],_0x49b231[_0x478f('0x17')]],isIdle);}function getRealtimeAgents(){return amiClient['request'](_0x478f('0x18'),{})[_0x478f('0x19')](function(_0x1de011){if(_0x1de011['error']){throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)');}var _0xb39e2=_0x1de011[_0x478f('0x1a')];return routingClient['request']('Agents',{})[_0x478f('0x19')](function(_0x385407){if(_0x385407[_0x478f('0x1b')]){throw new Error(_0x478f('0x1c'));}var _0x5808af=_0x385407['result'];return _['merge']({},_0xb39e2,_0x5808af);});})[_0x478f('0x1d')](function(_0x391693){throw _0x391693;});}exports[_0x478f('0x1e')]=getRealtimeAgents;function getAgentStatus(_0x1607b0){var _0x9f3955=_0x478f('0xd');if(isAgentPaused(_0x1607b0))_0x9f3955=_0x478f('0x11');else if(isAgentPaused(_0x1607b0,!![]))_0x9f3955=_0x478f('0x1f');else if(isAgentIdle(_0x1607b0))_0x9f3955=_0x478f('0x20');else _0x9f3955='busy';return _0x9f3955;}exports[_0x478f('0x21')]=getAgentStatus;function getAgentIdsByQueues(_0x4bd053,_0x5dcfb4){var _0x48b144=_[_0x478f('0x22')](_0x4bd053)?_0x4bd053:[_0x4bd053];var _0x1c0b17=_[_0x478f('0x23')](_0x5dcfb4)+_0x478f('0x24');var _0x3fa3e3=_['map'](_0x48b144,function(_0x1e349d){return db[_0x1c0b17]['findOne']({'where':{'id':_0x1e349d}})[_0x478f('0x19')](function(_0x2b2fa6){if(!_0x2b2fa6)return[];return _0x2b2fa6[_0x478f('0x25')]({'attributes':['id'],'raw':!![]});});});return Promise[_0x478f('0x26')](_0x3fa3e3)[_0x478f('0x19')](function(_0x1d658e){var _0x1a2f23=_(_0x1d658e)['flatten']()[_0x478f('0x27')]('id')[_0x478f('0x28')]()[_0x478f('0x29')]();return _0x1a2f23;});}exports[_0x478f('0x2a')]=getAgentIdsByQueues;function getAgentIdsByStatus(_0xbf862a,_0x12bce7,_0x5d67aa){try{if(_0x12bce7[_0x478f('0xc')]>0x0){_0xbf862a=_0xbf862a[_0x478f('0xb')](function(_0x29f9f1){return _0x12bce7[_0x478f('0x2b')](_0x29f9f1['id']);});}var _0x4759cb=_0xbf862a['filter'](function(_0xdcf6ce){var _0x80ca00=_0x478f('0x2c');if(isAgentIdle(_0xdcf6ce)){_0x80ca00=_0x478f('0x20');}return _0x80ca00===_0x5d67aa;});return _['map'](_0x4759cb,'id');}catch(_0x4fa6cf){throw _0x4fa6cf;}}exports['getAgentIdsByStatus']=getAgentIdsByStatus;function getSortedAgentsIdsByStatus(_0x430e5f,_0x2ca3c9,_0xd3ccbe){return Promise[_0x478f('0x2d')]()[_0x478f('0x19')](function(){if(_0x2ca3c9[_0x478f('0xc')]>0x0){_0x430e5f=_0x430e5f['filter'](function(_0xdba608){return _0x2ca3c9[_0x478f('0x2b')](_0xdba608['id']);});}return _0x430e5f;})[_0x478f('0x19')](function(){return db[_0x478f('0x2e')][_0x478f('0x2f')]({'attributes':['id',_0x478f('0x30'),'fullname',_0x478f('0x3'),_0x478f('0x4'),_0x478f('0x5'),_0x478f('0x6'),'smsPause','voicePause',_0x478f('0x9'),_0x478f('0x31')],'where':{'id':{'$in':_[_0x478f('0x27')](_0x430e5f,'id')}},'raw':!![]});})['then'](function(_0x140053){return _0x140053['map'](function(_0x5b77ed){var _0x5745dc=_[_0x478f('0x32')](_0x430e5f,['id',_0x5b77ed['id']]);var _0x4806f1=filterAgentAttributes(_0x5745dc);_['merge'](_0x5b77ed,_0x4806f1);_0x5b77ed[_0x478f('0x33')]=getAgentStatus(_0x5b77ed);return _0x5b77ed;});})['then'](function(_0x2c1c0d){var _0x1a815e=sortAgentsByStatus(_0x2c1c0d,_0xd3ccbe);return _[_0x478f('0x27')](_0x1a815e,'id');})['catch'](function(_0x11e040){throw _0x11e040;});}exports[_0x478f('0x34')]=getSortedAgentsIdsByStatus;function getUpdatedSortOptions(_0x5948f8){var _0x121431={'fields':[],'order':null};var _0x3e7d64=_0x5948f8[_0x478f('0x35')](',');_0x121431[_0x478f('0x36')]=_['filter'](_0x3e7d64,function(_0x5ac85a){if(!_0x5ac85a['includes'](_0x478f('0x33'))){return!![];}_0x121431[_0x478f('0x37')]=_['startsWith'](_0x5ac85a,'-')?_0x478f('0x38'):_0x478f('0x39');return![];});return _0x121431;}exports['getUpdatedSortOptions']=getUpdatedSortOptions;function validateSortParameter(_0x5bdd73){if(_0x5bdd73['includes'](_0x478f('0x3a'))&&!_0x5bdd73[_0x478f('0x2b')](_0x478f('0x3b'))){var _0xd07fa8=_0x5bdd73[_0x478f('0x3c')](0x0,_0x5bdd73[_0x478f('0x3d')](_0x478f('0x3a')));_0x5bdd73+=','+_0xd07fa8+_0x478f('0x3b');}return _0x5bdd73;}exports[_0x478f('0x3e')]=validateSortParameter;function sortAgentsByStatus(_0x17363b,_0xd28798){var _0x353dee=_0x17363b[_0x478f('0x3f')](function(_0x41aefb,_0x2ccdcd){if(_0x41aefb[_0x478f('0x33')]===_0x2ccdcd[_0x478f('0x33')]){if(_0x41aefb[_0x478f('0x33')]==='pause'){if(_0xd28798==='DESC'){return(_0x41aefb['pauseType']||'')<(_0x2ccdcd['pauseType']||'')||_0x41aefb[_0x478f('0x3a')]['toLowerCase']()>_0x2ccdcd[_0x478f('0x3a')][_0x478f('0x40')]()?0x1:-0x1;}else{return(_0x41aefb[_0x478f('0x31')]||'')<(_0x2ccdcd[_0x478f('0x31')]||'')||_0x41aefb['fullname']['toLowerCase']()>_0x2ccdcd[_0x478f('0x3a')]['toLowerCase']()?-0x1:0x1;}}else{if(_0xd28798==='DESC'){return _0x41aefb['fullname'][_0x478f('0x40')]()<_0x2ccdcd[_0x478f('0x3a')]['toLowerCase']()?0x1:-0x1;}else{return _0x41aefb[_0x478f('0x3a')][_0x478f('0x40')]()<_0x2ccdcd[_0x478f('0x3a')]['toLowerCase']()?-0x1:0x1;}}}else{if(_0xd28798==='DESC'){return _0x41aefb[_0x478f('0x33')]<_0x2ccdcd[_0x478f('0x33')]?0x1:-0x1;}else{return _0x41aefb['globalStatus']<_0x2ccdcd[_0x478f('0x33')]?-0x1:0x1;}}});return _0x353dee;}exports['sortAgentsByStatus']=sortAgentsByStatus;function filterAgentAttributes(_0x3eb1af){var _0x55f7f0=['userpic','online',_0x478f('0x41'),'lastPauseAt',_0x478f('0x31'),_0x478f('0x42'),_0x478f('0x3b'),_0x478f('0x43'),_0x478f('0x3'),_0x478f('0x6'),_0x478f('0x5'),'smsPause',_0x478f('0x9'),'faxPause',_0x478f('0x8'),'chatCapacity',_0x478f('0x44'),'mailCapacity','smsCapacity',_0x478f('0x45'),_0x478f('0x46'),_0x478f('0x47'),_0x478f('0x48'),'mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity',_0x478f('0x49'),'chatStatus','openchannelStatus',_0x478f('0x14'),_0x478f('0x16'),_0x478f('0x17'),_0x478f('0x13'),_0x478f('0x10'),'chatStatusTime',_0x478f('0x4a'),_0x478f('0x4b'),_0x478f('0x4c'),_0x478f('0x4d'),_0x478f('0x4e'),_0x478f('0x4f'),_0x478f('0x50'),'destconnectedlinenum','screenrecording',_0x478f('0x51'),_0x478f('0x52'),_0x478f('0x53')];var _0x221b19=[_0x478f('0x3'),'openchannelPause',_0x478f('0x5'),'smsPause','whatsappPause','faxPause',_0x478f('0x8'),_0x478f('0x54')];var _0x5b5dce=_(_0x3eb1af)[_0x478f('0x55')](_0x221b19)[_0x478f('0x56')](_0x55f7f0)[_0x478f('0x29')]();return _0x5b5dce;}exports[_0x478f('0x57')]=filterAgentAttributes;