Built motion from commit ffdca78c.|2.6.24
[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 _0x5fc3=['findOne','getAgents','all','flatten','map','getAgentIdsByQueues','includes','getAgentIdsByStatus','resolve','User','fullname','mailPause','openchannelPause','voicePause','globalStatus','getSortedAgentsIdsByStatus','split','order','startsWith','DESC','ASC','getUpdatedSortOptions','fullname,internal','internal','substring','indexOf','validateSortParameter','sort','pauseType','toLowerCase','userpic','online','lastLoginAt','lastPauseAt','address','chatCapacity','openchannelCapacity','mailCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','whatsappStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','voiceStatusTime','queue','destconnectedlinenum','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','omit','value','filterAgentAttributes','name','faxStatusTime','whatsappStatusTime','mailCurrentCapacity','routealias','getRealtimeAgentsQueryFields','lodash','jayson/promise','client','http','chatPause','faxPause','smsPause','whatsappPause','every','filter','length','idle','unknown','ringing','isNil','voiceStatus','pause','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','then','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','Agents','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','catch','*pause','busy','getAgentStatus','isArray','startCase','Queue'];(function(_0x54f3f8,_0x3640bd){var _0x28a4f6=function(_0x16df45){while(--_0x16df45){_0x54f3f8['push'](_0x54f3f8['shift']());}};_0x28a4f6(++_0x3640bd);}(_0x5fc3,0xa8));var _0x35fc=function(_0x34f545,_0x2bd2ee){_0x34f545=_0x34f545-0x0;var _0x1ff6b8=_0x5fc3[_0x34f545];return _0x1ff6b8;};'use strict';var _=require(_0x35fc('0x0'));var jayson=require(_0x35fc('0x1'));var db=require('../../mysqldb')['db'];var amiClient=jayson[_0x35fc('0x2')][_0x35fc('0x3')]({'port':0x232a});var routingClient=jayson[_0x35fc('0x2')][_0x35fc('0x3')]({'port':0x232c});function isAgentPaused(_0xb4f9ce,_0x5e75e6){var _0x2d1404=[_0xb4f9ce[_0x35fc('0x4')],_0xb4f9ce[_0x35fc('0x5')],_0xb4f9ce['mailPause'],_0xb4f9ce['openchannelPause'],_0xb4f9ce[_0x35fc('0x6')],_0xb4f9ce['voicePause'],_0xb4f9ce[_0x35fc('0x7')]];if(!_0x5e75e6)return _[_0x35fc('0x8')](_0x2d1404);var _0xc72d93=_[_0x35fc('0x9')](_0x2d1404);return _0xc72d93[_0x35fc('0xa')]>0x0&&_0xc72d93[_0x35fc('0xa')]<_0x2d1404[_0x35fc('0xa')]?!![]:![];}function isIdle(_0x565f95){return _0x565f95===_0x35fc('0xb')||_0x565f95===_0x35fc('0xc')||_0x565f95==='unavailable'||_0x565f95===_0x35fc('0xd')||_[_0x35fc('0xe')](_0x565f95);}function isAgentIdle(_0x5021d4){if(_0x5021d4[_0x35fc('0xf')]!==_0x35fc('0xb')&&_0x5021d4['voicePause']){_0x5021d4['voiceStatus']=_0x35fc('0x10');return![];}return _['every']([_0x5021d4[_0x35fc('0x11')],_0x5021d4[_0x35fc('0x12')],_0x5021d4[_0x35fc('0x13')],_0x5021d4[_0x35fc('0x14')],_0x5021d4[_0x35fc('0x15')],_0x5021d4['voiceStatus'],_0x5021d4['whatsappStatus']],isIdle);}function getRealtimeAgents(){return amiClient['request']('Agents',{})[_0x35fc('0x16')](function(_0x229d56){if(_0x229d56[_0x35fc('0x17')]){throw new Error(_0x35fc('0x18'));}var _0x227a49=_0x229d56[_0x35fc('0x19')];return routingClient['request'](_0x35fc('0x1a'),{})[_0x35fc('0x16')](function(_0x553677){if(_0x553677[_0x35fc('0x17')]){throw new Error(_0x35fc('0x1b'));}var _0x2e513b=_0x553677['result'];return _[_0x35fc('0x1c')]({},_0x227a49,_0x2e513b);});})[_0x35fc('0x1d')](function(_0x465eb3){throw _0x465eb3;});}exports['getRealtimeAgents']=getRealtimeAgents;function getAgentStatus(_0x402cff){var _0x350a27=_0x35fc('0xc');if(isAgentPaused(_0x402cff))_0x350a27=_0x35fc('0x10');else if(isAgentPaused(_0x402cff,!![]))_0x350a27=_0x35fc('0x1e');else if(isAgentIdle(_0x402cff))_0x350a27=_0x35fc('0xb');else _0x350a27=_0x35fc('0x1f');return _0x350a27;}exports[_0x35fc('0x20')]=getAgentStatus;function getAgentIdsByQueues(_0x2405e8,_0x427eae){var _0x5bd2b8=_[_0x35fc('0x21')](_0x2405e8)?_0x2405e8:[_0x2405e8];var _0xd5399f=_[_0x35fc('0x22')](_0x427eae)+_0x35fc('0x23');var _0x3b4743=_['map'](_0x5bd2b8,function(_0x33f5e8){return db[_0xd5399f][_0x35fc('0x24')]({'where':{'id':_0x33f5e8}})['then'](function(_0x265324){if(!_0x265324)return[];return _0x265324[_0x35fc('0x25')]({'attributes':['id'],'raw':!![]});});});return Promise[_0x35fc('0x26')](_0x3b4743)['then'](function(_0x4086e9){var _0x598d7a=_(_0x4086e9)[_0x35fc('0x27')]()[_0x35fc('0x28')]('id')['uniq']()['value']();return _0x598d7a;});}exports[_0x35fc('0x29')]=getAgentIdsByQueues;function getAgentIdsByStatus(_0x58edb6,_0x274208,_0x1a5d92){try{if(_0x274208['length']>0x0){_0x58edb6=_0x58edb6[_0x35fc('0x9')](function(_0x645eac){return _0x274208[_0x35fc('0x2a')](_0x645eac['id']);});}var _0x9f3c8a=_0x58edb6[_0x35fc('0x9')](function(_0x134dfa){var _0x11ccdb=_0x35fc('0x1f');if(isAgentIdle(_0x134dfa)){_0x11ccdb='idle';}return _0x11ccdb===_0x1a5d92;});return _[_0x35fc('0x28')](_0x9f3c8a,'id');}catch(_0x220931){throw _0x220931;}}exports[_0x35fc('0x2b')]=getAgentIdsByStatus;function getSortedAgentsIdsByStatus(_0x52acc5,_0xe79f52,_0x16f067){return Promise[_0x35fc('0x2c')]()[_0x35fc('0x16')](function(){if(_0xe79f52[_0x35fc('0xa')]>0x0){_0x52acc5=_0x52acc5[_0x35fc('0x9')](function(_0x222ddb){return _0xe79f52[_0x35fc('0x2a')](_0x222ddb['id']);});}return _0x52acc5;})[_0x35fc('0x16')](function(){return db[_0x35fc('0x2d')]['findAll']({'attributes':['id','name',_0x35fc('0x2e'),'chatPause',_0x35fc('0x5'),_0x35fc('0x2f'),_0x35fc('0x30'),_0x35fc('0x6'),_0x35fc('0x31'),_0x35fc('0x7'),'pauseType'],'where':{'id':{'$in':_[_0x35fc('0x28')](_0x52acc5,'id')}},'raw':!![]});})[_0x35fc('0x16')](function(_0x46b9ef){return _0x46b9ef[_0x35fc('0x28')](function(_0x2bbd36){var _0x2f823b=_['find'](_0x52acc5,['id',_0x2bbd36['id']]);var _0x2483be=filterAgentAttributes(_0x2f823b);_[_0x35fc('0x1c')](_0x2bbd36,_0x2483be);_0x2bbd36[_0x35fc('0x32')]=getAgentStatus(_0x2bbd36);return _0x2bbd36;});})['then'](function(_0x2c657d){var _0x48d223=sortAgentsByStatus(_0x2c657d,_0x16f067);return _[_0x35fc('0x28')](_0x48d223,'id');})[_0x35fc('0x1d')](function(_0x266a11){throw _0x266a11;});}exports[_0x35fc('0x33')]=getSortedAgentsIdsByStatus;function getUpdatedSortOptions(_0x4de4b7){var _0x54fcf1={'fields':[],'order':null};var _0x59e4fb=_0x4de4b7[_0x35fc('0x34')](',');_0x54fcf1['fields']=_[_0x35fc('0x9')](_0x59e4fb,function(_0x4b4d4a){if(!_0x4b4d4a[_0x35fc('0x2a')](_0x35fc('0x32'))){return!![];}_0x54fcf1[_0x35fc('0x35')]=_[_0x35fc('0x36')](_0x4b4d4a,'-')?_0x35fc('0x37'):_0x35fc('0x38');return![];});return _0x54fcf1;}exports[_0x35fc('0x39')]=getUpdatedSortOptions;function validateSortParameter(_0x4ec0dc){if(!_0x4ec0dc){_0x4ec0dc=_0x35fc('0x3a');}if(_0x4ec0dc[_0x35fc('0x2a')]('fullname')&&!_0x4ec0dc[_0x35fc('0x2a')](_0x35fc('0x3b'))){var _0x1aac67=_0x4ec0dc[_0x35fc('0x3c')](0x0,_0x4ec0dc[_0x35fc('0x3d')](_0x35fc('0x2e')));_0x4ec0dc+=','+_0x1aac67+'internal';}return _0x4ec0dc;}exports[_0x35fc('0x3e')]=validateSortParameter;function sortAgentsByStatus(_0x267858,_0x392806){var _0x52543b=_0x267858[_0x35fc('0x3f')](function(_0x350a96,_0x596919){if(_0x350a96[_0x35fc('0x32')]===_0x596919[_0x35fc('0x32')]){if(_0x350a96[_0x35fc('0x32')]===_0x35fc('0x10')){if(_0x392806===_0x35fc('0x37')){return(_0x350a96[_0x35fc('0x40')]||'')<(_0x596919[_0x35fc('0x40')]||'')||_0x350a96[_0x35fc('0x2e')]['toLowerCase']()>_0x596919['fullname'][_0x35fc('0x41')]()?0x1:-0x1;}else{return(_0x350a96[_0x35fc('0x40')]||'')<(_0x596919['pauseType']||'')||_0x350a96['fullname']['toLowerCase']()>_0x596919[_0x35fc('0x2e')][_0x35fc('0x41')]()?-0x1:0x1;}}else{if(_0x392806==='DESC'){return _0x350a96[_0x35fc('0x2e')][_0x35fc('0x41')]()<_0x596919[_0x35fc('0x2e')][_0x35fc('0x41')]()?0x1:-0x1;}else{return _0x350a96['fullname']['toLowerCase']()<_0x596919['fullname']['toLowerCase']()?-0x1:0x1;}}}else{if(_0x392806==='DESC'){return _0x350a96[_0x35fc('0x32')]<_0x596919[_0x35fc('0x32')]?0x1:-0x1;}else{return _0x350a96['globalStatus']<_0x596919[_0x35fc('0x32')]?-0x1:0x1;}}});return _0x52543b;}exports['sortAgentsByStatus']=sortAgentsByStatus;function filterAgentAttributes(_0x13d16c){var _0x40797d=[_0x35fc('0x42'),_0x35fc('0x43'),_0x35fc('0x44'),'lastPauseAt',_0x35fc('0x40'),_0x35fc('0x45'),'internal',_0x35fc('0x46'),_0x35fc('0x4'),_0x35fc('0x30'),_0x35fc('0x2f'),'smsPause',_0x35fc('0x7'),'faxPause','voicePause',_0x35fc('0x47'),_0x35fc('0x48'),_0x35fc('0x49'),_0x35fc('0x4a'),_0x35fc('0x4b'),_0x35fc('0x4c'),_0x35fc('0x4d'),_0x35fc('0x4e'),'mailCurrentCapacity',_0x35fc('0x4f'),_0x35fc('0x50'),_0x35fc('0x51'),_0x35fc('0x11'),_0x35fc('0x14'),_0x35fc('0x13'),_0x35fc('0x15'),_0x35fc('0x52'),_0x35fc('0x12'),_0x35fc('0xf'),_0x35fc('0x53'),_0x35fc('0x54'),_0x35fc('0x55'),_0x35fc('0x56'),'whatsappStatusTime','faxStatusTime',_0x35fc('0x57'),_0x35fc('0x58'),_0x35fc('0x59'),_0x35fc('0x5a'),_0x35fc('0x5b'),_0x35fc('0x5c'),'routealias'];var _0x4f024c=[_0x35fc('0x4'),_0x35fc('0x30'),_0x35fc('0x2f'),_0x35fc('0x6'),'whatsappPause',_0x35fc('0x5'),_0x35fc('0x31'),'online'];var _0x199a00=_(_0x13d16c)[_0x35fc('0x5d')](_0x4f024c)['pick'](_0x40797d)[_0x35fc('0x5e')]();return _0x199a00;}exports[_0x35fc('0x5f')]=filterAgentAttributes;function getRealtimeAgentsQueryFields(){return['id',_0x35fc('0x60'),_0x35fc('0x2e'),'role','internal','online',_0x35fc('0x32'),_0x35fc('0x42'),'lastLoginAt',_0x35fc('0x40'),_0x35fc('0x45'),_0x35fc('0x5'),_0x35fc('0x4'),_0x35fc('0x2f'),'openchannelPause',_0x35fc('0x6'),_0x35fc('0x31'),_0x35fc('0x7'),'chatStatus',_0x35fc('0x12'),_0x35fc('0x13'),'openchannelStatus',_0x35fc('0x15'),_0x35fc('0xf'),_0x35fc('0x52'),_0x35fc('0x53'),_0x35fc('0x61'),_0x35fc('0x55'),_0x35fc('0x54'),_0x35fc('0x56'),'voiceStatusTime',_0x35fc('0x62'),_0x35fc('0x47'),_0x35fc('0x4c'),'mailCapacity',_0x35fc('0x48'),'smsCapacity','whatsappCapacity','chatCurrentCapacity',_0x35fc('0x51'),_0x35fc('0x63'),_0x35fc('0x4e'),_0x35fc('0x4f'),_0x35fc('0x50'),'phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','destconnectedlinenum','onhold','queue',_0x35fc('0x64'),_0x35fc('0x5a')];}exports[_0x35fc('0x65')]=getRealtimeAgentsQueryFields;