Built motion from commit 47436d59.|2.6.7
[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 _0xd829=['faxCurrentCapacity','smsStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','voiceStatusTime','queue','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','routealias','omit','pick','filterAgentAttributes','lodash','jayson/promise','../../mysqldb','http','chatPause','faxPause','mailPause','openchannelPause','smsPause','whatsappPause','every','length','idle','unknown','unavailable','ringing','isNil','voiceStatus','voicePause','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','whatsappStatus','Agents','then','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','request','catch','getRealtimeAgents','*pause','busy','isArray','Queue','map','findOne','getAgents','all','flatten','uniq','value','getAgentIdsByQueues','filter','includes','User','name','fullname','pauseType','find','merge','globalStatus','getSortedAgentsIdsByStatus','order','DESC','ASC','substring','internal','sort','toLowerCase','sortAgentsByStatus','online','lastLoginAt','lastPauseAt','address','chatCapacity','openchannelCapacity','mailCapacity','smsCurrentCapacity','whatsappCurrentCapacity'];(function(_0x362f3d,_0x3f33d4){var _0x442fb2=function(_0x17ef84){while(--_0x17ef84){_0x362f3d['push'](_0x362f3d['shift']());}};_0x442fb2(++_0x3f33d4);}(_0xd829,0x118));var _0x9d82=function(_0x250a8c,_0x33a2c6){_0x250a8c=_0x250a8c-0x0;var _0x5b8b36=_0xd829[_0x250a8c];return _0x5b8b36;};'use strict';var _=require(_0x9d82('0x0'));var jayson=require(_0x9d82('0x1'));var db=require(_0x9d82('0x2'))['db'];var amiClient=jayson['client'][_0x9d82('0x3')]({'port':0x232a});var routingClient=jayson['client'][_0x9d82('0x3')]({'port':0x232c});function isAgentPaused(_0x3bfccb,_0x3cbc49){var _0x148608=[_0x3bfccb[_0x9d82('0x4')],_0x3bfccb[_0x9d82('0x5')],_0x3bfccb[_0x9d82('0x6')],_0x3bfccb[_0x9d82('0x7')],_0x3bfccb[_0x9d82('0x8')],_0x3bfccb['voicePause'],_0x3bfccb[_0x9d82('0x9')]];if(!_0x3cbc49)return _[_0x9d82('0xa')](_0x148608);var _0x35dc36=_['filter'](_0x148608);return _0x35dc36['length']>0x0&&_0x35dc36['length']<_0x148608[_0x9d82('0xb')]?!![]:![];}function isIdle(_0x2bfc53){return _0x2bfc53===_0x9d82('0xc')||_0x2bfc53===_0x9d82('0xd')||_0x2bfc53===_0x9d82('0xe')||_0x2bfc53===_0x9d82('0xf')||_[_0x9d82('0x10')](_0x2bfc53);}function isAgentIdle(_0x4c6430){if(_0x4c6430[_0x9d82('0x11')]!=='idle'&&_0x4c6430[_0x9d82('0x12')]){_0x4c6430[_0x9d82('0x11')]=_0x9d82('0x13');return![];}return _[_0x9d82('0xa')]([_0x4c6430[_0x9d82('0x14')],_0x4c6430[_0x9d82('0x15')],_0x4c6430[_0x9d82('0x16')],_0x4c6430[_0x9d82('0x17')],_0x4c6430['smsStatus'],_0x4c6430[_0x9d82('0x11')],_0x4c6430[_0x9d82('0x18')]],isIdle);}function getRealtimeAgents(){return amiClient['request'](_0x9d82('0x19'),{})[_0x9d82('0x1a')](function(_0x3407c6){if(_0x3407c6[_0x9d82('0x1b')]){throw new Error(_0x9d82('0x1c'));}var _0x58b653=_0x3407c6[_0x9d82('0x1d')];return routingClient[_0x9d82('0x1e')](_0x9d82('0x19'),{})[_0x9d82('0x1a')](function(_0x2f8036){if(_0x2f8036[_0x9d82('0x1b')]){throw new Error('Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)');}var _0x189720=_0x2f8036[_0x9d82('0x1d')];return _['merge']({},_0x58b653,_0x189720);});})[_0x9d82('0x1f')](function(_0x626312){throw _0x626312;});}exports[_0x9d82('0x20')]=getRealtimeAgents;function getAgentStatus(_0x3b3732){var _0x2824fd=_0x9d82('0xd');if(isAgentPaused(_0x3b3732))_0x2824fd='pause';else if(isAgentPaused(_0x3b3732,!![]))_0x2824fd=_0x9d82('0x21');else if(isAgentIdle(_0x3b3732))_0x2824fd=_0x9d82('0xc');else _0x2824fd=_0x9d82('0x22');return _0x2824fd;}exports['getAgentStatus']=getAgentStatus;function getAgentIdsByQueues(_0x1f0047,_0x257db4){var _0x147f47=_[_0x9d82('0x23')](_0x1f0047)?_0x1f0047:[_0x1f0047];var _0x5d73b5=_['startCase'](_0x257db4)+_0x9d82('0x24');var _0xf2459f=_[_0x9d82('0x25')](_0x147f47,function(_0xd4f8d9){return db[_0x5d73b5][_0x9d82('0x26')]({'where':{'id':_0xd4f8d9}})[_0x9d82('0x1a')](function(_0x3b66c5){if(!_0x3b66c5)return[];return _0x3b66c5[_0x9d82('0x27')]({'attributes':['id'],'raw':!![]});});});return Promise[_0x9d82('0x28')](_0xf2459f)[_0x9d82('0x1a')](function(_0x21b4d9){var _0x4f19a1=_(_0x21b4d9)[_0x9d82('0x29')]()['map']('id')[_0x9d82('0x2a')]()[_0x9d82('0x2b')]();return _0x4f19a1;});}exports[_0x9d82('0x2c')]=getAgentIdsByQueues;function getAgentIdsByStatus(_0x42eddc,_0x306f0f,_0x210f90){try{if(_0x306f0f['length']>0x0){_0x42eddc=_0x42eddc[_0x9d82('0x2d')](function(_0x568d01){return _0x306f0f[_0x9d82('0x2e')](_0x568d01['id']);});}var _0x1eb9f4=_0x42eddc[_0x9d82('0x2d')](function(_0x2b08f8){var _0x4ca2c4='busy';if(isAgentIdle(_0x2b08f8)){_0x4ca2c4=_0x9d82('0xc');}return _0x4ca2c4===_0x210f90;});return _[_0x9d82('0x25')](_0x1eb9f4,'id');}catch(_0x1c3d63){throw _0x1c3d63;}}exports['getAgentIdsByStatus']=getAgentIdsByStatus;function getSortedAgentsIdsByStatus(_0x3f4d1f,_0x2193ef,_0x3e9416){return Promise['resolve']()[_0x9d82('0x1a')](function(){if(_0x2193ef['length']>0x0){_0x3f4d1f=_0x3f4d1f['filter'](function(_0x5658ea){return _0x2193ef['includes'](_0x5658ea['id']);});}return _0x3f4d1f;})[_0x9d82('0x1a')](function(){return db[_0x9d82('0x2f')]['findAll']({'attributes':['id',_0x9d82('0x30'),_0x9d82('0x31'),'chatPause',_0x9d82('0x5'),_0x9d82('0x6'),_0x9d82('0x7'),_0x9d82('0x8'),_0x9d82('0x12'),_0x9d82('0x9'),_0x9d82('0x32')],'where':{'id':{'$in':_['map'](_0x3f4d1f,'id')}},'raw':!![]});})[_0x9d82('0x1a')](function(_0x37b87d){return _0x37b87d['map'](function(_0x5ca257){var _0x1aff70=_[_0x9d82('0x33')](_0x3f4d1f,['id',_0x5ca257['id']]);var _0x165b1e=filterAgentAttributes(_0x1aff70);_[_0x9d82('0x34')](_0x5ca257,_0x165b1e);_0x5ca257[_0x9d82('0x35')]=getAgentStatus(_0x5ca257);return _0x5ca257;});})[_0x9d82('0x1a')](function(_0x53e828){var _0x5a2bb2=sortAgentsByStatus(_0x53e828,_0x3e9416);return _[_0x9d82('0x25')](_0x5a2bb2,'id');})[_0x9d82('0x1f')](function(_0x7749eb){throw _0x7749eb;});}exports[_0x9d82('0x36')]=getSortedAgentsIdsByStatus;function getUpdatedSortOptions(_0x5bab75){var _0x36c766={'fields':[],'order':null};var _0x19824e=_0x5bab75['split'](',');_0x36c766['fields']=_[_0x9d82('0x2d')](_0x19824e,function(_0x3aeb1b){if(!_0x3aeb1b[_0x9d82('0x2e')](_0x9d82('0x35'))){return!![];}_0x36c766[_0x9d82('0x37')]=_['startsWith'](_0x3aeb1b,'-')?_0x9d82('0x38'):_0x9d82('0x39');return![];});return _0x36c766;}exports['getUpdatedSortOptions']=getUpdatedSortOptions;function validateSortParameter(_0x200d90){if(_0x200d90[_0x9d82('0x2e')](_0x9d82('0x31'))&&!_0x200d90[_0x9d82('0x2e')]('internal')){var _0x18be97=_0x200d90[_0x9d82('0x3a')](0x0,_0x200d90['indexOf'](_0x9d82('0x31')));_0x200d90+=','+_0x18be97+_0x9d82('0x3b');}return _0x200d90;}exports['validateSortParameter']=validateSortParameter;function sortAgentsByStatus(_0x1a5a98,_0x161ab3){var _0x8bbc9=_0x1a5a98[_0x9d82('0x3c')](function(_0x4f7015,_0x4d0fcd){if(_0x4f7015['globalStatus']===_0x4d0fcd[_0x9d82('0x35')]){if(_0x4f7015[_0x9d82('0x35')]==='pause'){if(_0x161ab3==='DESC'){return(_0x4f7015['pauseType']||'')<(_0x4d0fcd[_0x9d82('0x32')]||'')||_0x4f7015[_0x9d82('0x31')][_0x9d82('0x3d')]()>_0x4d0fcd[_0x9d82('0x31')][_0x9d82('0x3d')]()?0x1:-0x1;}else{return(_0x4f7015[_0x9d82('0x32')]||'')<(_0x4d0fcd[_0x9d82('0x32')]||'')||_0x4f7015[_0x9d82('0x31')][_0x9d82('0x3d')]()>_0x4d0fcd[_0x9d82('0x31')]['toLowerCase']()?-0x1:0x1;}}else{if(_0x161ab3===_0x9d82('0x38')){return _0x4f7015[_0x9d82('0x31')]['toLowerCase']()<_0x4d0fcd[_0x9d82('0x31')][_0x9d82('0x3d')]()?0x1:-0x1;}else{return _0x4f7015[_0x9d82('0x31')]['toLowerCase']()<_0x4d0fcd[_0x9d82('0x31')]['toLowerCase']()?-0x1:0x1;}}}else{if(_0x161ab3==='DESC'){return _0x4f7015['globalStatus']<_0x4d0fcd[_0x9d82('0x35')]?0x1:-0x1;}else{return _0x4f7015[_0x9d82('0x35')]<_0x4d0fcd['globalStatus']?-0x1:0x1;}}});return _0x8bbc9;}exports[_0x9d82('0x3e')]=sortAgentsByStatus;function filterAgentAttributes(_0x5f58de){var _0x14ab9b=['userpic',_0x9d82('0x3f'),_0x9d82('0x40'),_0x9d82('0x41'),_0x9d82('0x32'),_0x9d82('0x41'),_0x9d82('0x3b'),_0x9d82('0x42'),_0x9d82('0x4'),_0x9d82('0x7'),_0x9d82('0x6'),_0x9d82('0x8'),_0x9d82('0x9'),_0x9d82('0x5'),_0x9d82('0x12'),_0x9d82('0x43'),_0x9d82('0x44'),_0x9d82('0x45'),'smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity',_0x9d82('0x46'),_0x9d82('0x47'),_0x9d82('0x48'),_0x9d82('0x14'),'openchannelStatus',_0x9d82('0x16'),_0x9d82('0x49'),_0x9d82('0x18'),'faxStatus',_0x9d82('0x11'),_0x9d82('0x4a'),_0x9d82('0x4b'),_0x9d82('0x4c'),_0x9d82('0x4d'),_0x9d82('0x4e'),'faxStatusTime',_0x9d82('0x4f'),_0x9d82('0x50'),_0x9d82('0x51'),_0x9d82('0x52'),_0x9d82('0x53'),'phoneBarEnableAutomaticScreenRecording',_0x9d82('0x54')];var _0x3a5e5a=['chatPause','openchannelPause',_0x9d82('0x6'),_0x9d82('0x8'),_0x9d82('0x9'),_0x9d82('0x5'),_0x9d82('0x12'),_0x9d82('0x3f')];var _0x125cab=_(_0x5f58de)[_0x9d82('0x55')](_0x3a5e5a)[_0x9d82('0x56')](_0x14ab9b)[_0x9d82('0x2b')]();return _0x125cab;}exports[_0x9d82('0x57')]=filterAgentAttributes;