b736775695672e11d204b97d541fafe7a697ab64
[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 _0x1cbc=['pauseType','toLowerCase','sortAgentsByStatus','userpic','lastLoginAt','lastPauseAt','address','chatCapacity','openchannelCapacity','mailCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','mailStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','whatsappStatusTime','faxStatusTime','voiceStatusTime','queue','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','omit','pick','filterAgentAttributes','role','online','onhold','getRealtimeAgentsQueryFields','lodash','../../mysqldb','client','http','chatPause','faxPause','mailPause','openchannelPause','voicePause','every','length','idle','unknown','unavailable','ringing','voiceStatus','pause','chatStatus','faxStatus','openchannelStatus','smsStatus','whatsappStatus','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','catch','getRealtimeAgents','*pause','busy','startCase','Queue','map','findOne','getAgents','flatten','uniq','value','getAgentIdsByQueues','filter','resolve','User','name','smsPause','whatsappPause','find','globalStatus','getSortedAgentsIdsByStatus','split','fields','order','startsWith','DESC','ASC','getUpdatedSortOptions','fullname,internal','fullname','internal','substring','indexOf','validateSortParameter','sort'];(function(_0x3d6cd8,_0x4765aa){var _0x3c6226=function(_0x3a67a8){while(--_0x3a67a8){_0x3d6cd8['push'](_0x3d6cd8['shift']());}};_0x3c6226(++_0x4765aa);}(_0x1cbc,0xf4));var _0xc1cb=function(_0x435592,_0x363aed){_0x435592=_0x435592-0x0;var _0x2d544d=_0x1cbc[_0x435592];return _0x2d544d;};'use strict';var _=require(_0xc1cb('0x0'));var jayson=require('jayson/promise');var db=require(_0xc1cb('0x1'))['db'];var amiClient=jayson[_0xc1cb('0x2')][_0xc1cb('0x3')]({'port':0x232a});var routingClient=jayson[_0xc1cb('0x2')][_0xc1cb('0x3')]({'port':0x232c});function isAgentPaused(_0x439f4c,_0x13a9a0){var _0x71a222=[_0x439f4c[_0xc1cb('0x4')],_0x439f4c[_0xc1cb('0x5')],_0x439f4c[_0xc1cb('0x6')],_0x439f4c[_0xc1cb('0x7')],_0x439f4c['smsPause'],_0x439f4c[_0xc1cb('0x8')],_0x439f4c['whatsappPause']];if(!_0x13a9a0)return _[_0xc1cb('0x9')](_0x71a222);var _0x271f7d=_['filter'](_0x71a222);return _0x271f7d[_0xc1cb('0xa')]>0x0&&_0x271f7d[_0xc1cb('0xa')]<_0x71a222[_0xc1cb('0xa')]?!![]:![];}function isIdle(_0x587e7d){return _0x587e7d===_0xc1cb('0xb')||_0x587e7d===_0xc1cb('0xc')||_0x587e7d===_0xc1cb('0xd')||_0x587e7d===_0xc1cb('0xe')||_['isNil'](_0x587e7d);}function isAgentIdle(_0x2ed6d2){if(_0x2ed6d2['voiceStatus']!==_0xc1cb('0xb')&&_0x2ed6d2[_0xc1cb('0x8')]){_0x2ed6d2[_0xc1cb('0xf')]=_0xc1cb('0x10');return![];}return _[_0xc1cb('0x9')]([_0x2ed6d2[_0xc1cb('0x11')],_0x2ed6d2[_0xc1cb('0x12')],_0x2ed6d2['mailStatus'],_0x2ed6d2[_0xc1cb('0x13')],_0x2ed6d2[_0xc1cb('0x14')],_0x2ed6d2[_0xc1cb('0xf')],_0x2ed6d2[_0xc1cb('0x15')]],isIdle);}function getRealtimeAgents(){return amiClient['request'](_0xc1cb('0x16'),{})[_0xc1cb('0x17')](function(_0x4fd5ea){if(_0x4fd5ea['error']){throw new Error(_0xc1cb('0x18'));}var _0x4630fb=_0x4fd5ea[_0xc1cb('0x19')];return routingClient['request']('Agents',{})['then'](function(_0x5d32ec){if(_0x5d32ec[_0xc1cb('0x1a')]){throw new Error(_0xc1cb('0x1b'));}var _0x345534=_0x5d32ec[_0xc1cb('0x19')];return _[_0xc1cb('0x1c')]({},_0x4630fb,_0x345534);});})[_0xc1cb('0x1d')](function(_0x596f58){throw _0x596f58;});}exports[_0xc1cb('0x1e')]=getRealtimeAgents;function getAgentStatus(_0x11bdb0){var _0x7353ad=_0xc1cb('0xc');if(isAgentPaused(_0x11bdb0))_0x7353ad='pause';else if(isAgentPaused(_0x11bdb0,!![]))_0x7353ad=_0xc1cb('0x1f');else if(isAgentIdle(_0x11bdb0))_0x7353ad=_0xc1cb('0xb');else _0x7353ad=_0xc1cb('0x20');return _0x7353ad;}exports['getAgentStatus']=getAgentStatus;function getAgentIdsByQueues(_0x4ddf55,_0x3b6ca5){var _0x460332=_['isArray'](_0x4ddf55)?_0x4ddf55:[_0x4ddf55];var _0x5e4e33=_[_0xc1cb('0x21')](_0x3b6ca5)+_0xc1cb('0x22');var _0x127712=_[_0xc1cb('0x23')](_0x460332,function(_0x2d27a7){return db[_0x5e4e33][_0xc1cb('0x24')]({'where':{'id':_0x2d27a7}})[_0xc1cb('0x17')](function(_0x532632){if(!_0x532632)return[];return _0x532632[_0xc1cb('0x25')]({'attributes':['id'],'raw':!![]});});});return Promise['all'](_0x127712)[_0xc1cb('0x17')](function(_0x3f6481){var _0x357358=_(_0x3f6481)[_0xc1cb('0x26')]()[_0xc1cb('0x23')]('id')[_0xc1cb('0x27')]()[_0xc1cb('0x28')]();return _0x357358;});}exports[_0xc1cb('0x29')]=getAgentIdsByQueues;function getAgentIdsByStatus(_0x18e9c4,_0xc926c6,_0x39132d){try{if(_0xc926c6[_0xc1cb('0xa')]>0x0){_0x18e9c4=_0x18e9c4['filter'](function(_0x54f42d){return _0xc926c6['includes'](_0x54f42d['id']);});}var _0xf68d03=_0x18e9c4[_0xc1cb('0x2a')](function(_0x300f84){var _0x496093=_0xc1cb('0x20');if(isAgentIdle(_0x300f84)){_0x496093=_0xc1cb('0xb');}return _0x496093===_0x39132d;});return _[_0xc1cb('0x23')](_0xf68d03,'id');}catch(_0x54c5db){throw _0x54c5db;}}exports['getAgentIdsByStatus']=getAgentIdsByStatus;function getSortedAgentsIdsByStatus(_0x3b85d6,_0x2f9acc,_0x139bd3){return Promise[_0xc1cb('0x2b')]()[_0xc1cb('0x17')](function(){if(_0x2f9acc[_0xc1cb('0xa')]>0x0){_0x3b85d6=_0x3b85d6[_0xc1cb('0x2a')](function(_0x31e450){return _0x2f9acc['includes'](_0x31e450['id']);});}return _0x3b85d6;})['then'](function(){return db[_0xc1cb('0x2c')]['findAll']({'attributes':['id',_0xc1cb('0x2d'),'fullname',_0xc1cb('0x4'),_0xc1cb('0x5'),_0xc1cb('0x6'),_0xc1cb('0x7'),_0xc1cb('0x2e'),_0xc1cb('0x8'),_0xc1cb('0x2f'),'pauseType'],'where':{'id':{'$in':_[_0xc1cb('0x23')](_0x3b85d6,'id')}},'raw':!![]});})['then'](function(_0x5d7623){return _0x5d7623['map'](function(_0x12db75){var _0x27f202=_[_0xc1cb('0x30')](_0x3b85d6,['id',_0x12db75['id']]);var _0x668c09=filterAgentAttributes(_0x27f202);_[_0xc1cb('0x1c')](_0x12db75,_0x668c09);_0x12db75[_0xc1cb('0x31')]=getAgentStatus(_0x12db75);return _0x12db75;});})[_0xc1cb('0x17')](function(_0x27f389){var _0x289c9f=sortAgentsByStatus(_0x27f389,_0x139bd3);return _['map'](_0x289c9f,'id');})[_0xc1cb('0x1d')](function(_0x35da0c){throw _0x35da0c;});}exports[_0xc1cb('0x32')]=getSortedAgentsIdsByStatus;function getUpdatedSortOptions(_0x592f42){var _0x49045f={'fields':[],'order':null};var _0x28ca8e=_0x592f42[_0xc1cb('0x33')](',');_0x49045f[_0xc1cb('0x34')]=_[_0xc1cb('0x2a')](_0x28ca8e,function(_0x1e3c85){if(!_0x1e3c85['includes'](_0xc1cb('0x31'))){return!![];}_0x49045f[_0xc1cb('0x35')]=_[_0xc1cb('0x36')](_0x1e3c85,'-')?_0xc1cb('0x37'):_0xc1cb('0x38');return![];});return _0x49045f;}exports[_0xc1cb('0x39')]=getUpdatedSortOptions;function validateSortParameter(_0x3b2979){if(!_0x3b2979){_0x3b2979=_0xc1cb('0x3a');}if(_0x3b2979['includes'](_0xc1cb('0x3b'))&&!_0x3b2979['includes'](_0xc1cb('0x3c'))){var _0x3520b5=_0x3b2979[_0xc1cb('0x3d')](0x0,_0x3b2979[_0xc1cb('0x3e')](_0xc1cb('0x3b')));_0x3b2979+=','+_0x3520b5+_0xc1cb('0x3c');}return _0x3b2979;}exports[_0xc1cb('0x3f')]=validateSortParameter;function sortAgentsByStatus(_0x5ba5da,_0x340892){var _0x48e079=_0x5ba5da[_0xc1cb('0x40')](function(_0x4096d9,_0x30bcb5){if(_0x4096d9['globalStatus']===_0x30bcb5[_0xc1cb('0x31')]){if(_0x4096d9[_0xc1cb('0x31')]==='pause'){if(_0x340892===_0xc1cb('0x37')){return(_0x4096d9[_0xc1cb('0x41')]||'')<(_0x30bcb5[_0xc1cb('0x41')]||'')||_0x4096d9[_0xc1cb('0x3b')]['toLowerCase']()>_0x30bcb5['fullname'][_0xc1cb('0x42')]()?0x1:-0x1;}else{return(_0x4096d9[_0xc1cb('0x41')]||'')<(_0x30bcb5[_0xc1cb('0x41')]||'')||_0x4096d9['fullname'][_0xc1cb('0x42')]()>_0x30bcb5[_0xc1cb('0x3b')][_0xc1cb('0x42')]()?-0x1:0x1;}}else{if(_0x340892===_0xc1cb('0x37')){return _0x4096d9[_0xc1cb('0x3b')][_0xc1cb('0x42')]()<_0x30bcb5['fullname']['toLowerCase']()?0x1:-0x1;}else{return _0x4096d9['fullname']['toLowerCase']()<_0x30bcb5[_0xc1cb('0x3b')][_0xc1cb('0x42')]()?-0x1:0x1;}}}else{if(_0x340892===_0xc1cb('0x37')){return _0x4096d9[_0xc1cb('0x31')]<_0x30bcb5[_0xc1cb('0x31')]?0x1:-0x1;}else{return _0x4096d9[_0xc1cb('0x31')]<_0x30bcb5[_0xc1cb('0x31')]?-0x1:0x1;}}});return _0x48e079;}exports[_0xc1cb('0x43')]=sortAgentsByStatus;function filterAgentAttributes(_0x41e4d9){var _0x49caab=[_0xc1cb('0x44'),'online',_0xc1cb('0x45'),_0xc1cb('0x46'),_0xc1cb('0x41'),'lastPauseAt',_0xc1cb('0x3c'),_0xc1cb('0x47'),_0xc1cb('0x4'),_0xc1cb('0x7'),_0xc1cb('0x6'),'smsPause',_0xc1cb('0x2f'),_0xc1cb('0x5'),'voicePause',_0xc1cb('0x48'),_0xc1cb('0x49'),_0xc1cb('0x4a'),_0xc1cb('0x4b'),_0xc1cb('0x4c'),_0xc1cb('0x4d'),_0xc1cb('0x4e'),_0xc1cb('0x4f'),'mailCurrentCapacity',_0xc1cb('0x50'),_0xc1cb('0x51'),_0xc1cb('0x52'),_0xc1cb('0x11'),_0xc1cb('0x13'),_0xc1cb('0x53'),_0xc1cb('0x14'),_0xc1cb('0x15'),_0xc1cb('0x12'),'voiceStatus',_0xc1cb('0x54'),_0xc1cb('0x55'),_0xc1cb('0x56'),_0xc1cb('0x57'),_0xc1cb('0x58'),_0xc1cb('0x59'),_0xc1cb('0x5a'),_0xc1cb('0x5b'),_0xc1cb('0x5c'),_0xc1cb('0x5d'),_0xc1cb('0x5e'),_0xc1cb('0x5f')];var _0xcd6240=[_0xc1cb('0x4'),_0xc1cb('0x7'),'mailPause',_0xc1cb('0x2e'),_0xc1cb('0x2f'),'faxPause',_0xc1cb('0x8'),'online'];var _0x244029=_(_0x41e4d9)[_0xc1cb('0x60')](_0xcd6240)[_0xc1cb('0x61')](_0x49caab)[_0xc1cb('0x28')]();return _0x244029;}exports[_0xc1cb('0x62')]=filterAgentAttributes;function getRealtimeAgentsQueryFields(){return['id',_0xc1cb('0x2d'),_0xc1cb('0x3b'),_0xc1cb('0x63'),_0xc1cb('0x3c'),_0xc1cb('0x64'),_0xc1cb('0x31'),'userpic',_0xc1cb('0x45'),_0xc1cb('0x41'),_0xc1cb('0x46'),'faxPause',_0xc1cb('0x4'),'mailPause','openchannelPause',_0xc1cb('0x2e'),_0xc1cb('0x8'),_0xc1cb('0x2f'),_0xc1cb('0x11'),'faxStatus',_0xc1cb('0x53'),_0xc1cb('0x13'),'smsStatus',_0xc1cb('0xf'),_0xc1cb('0x15'),_0xc1cb('0x54'),_0xc1cb('0x59'),_0xc1cb('0x56'),_0xc1cb('0x55'),'smsStatusTime',_0xc1cb('0x5a'),'whatsappStatusTime','chatCapacity','faxCapacity','mailCapacity',_0xc1cb('0x49'),_0xc1cb('0x4b'),_0xc1cb('0x4c'),_0xc1cb('0x4e'),_0xc1cb('0x52'),'mailCurrentCapacity',_0xc1cb('0x4f'),_0xc1cb('0x50'),_0xc1cb('0x51'),_0xc1cb('0x5e'),_0xc1cb('0x5f'),_0xc1cb('0x5c'),_0xc1cb('0x65'),_0xc1cb('0x5b'),_0xc1cb('0x5d')];}exports[_0xc1cb('0x66')]=getRealtimeAgentsQueryFields;