Built motion from commit f74363e9.|2.6.34
[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 _0xfaf2=['map','findOne','getAgents','all','flatten','uniq','value','getAgentIdsByQueues','filter','includes','busy','resolve','User','findAll','name','openchannelPause','find','globalStatus','getSortedAgentsIdsByStatus','split','startsWith','DESC','ASC','getUpdatedSortOptions','fullname,internal','internal','validateSortParameter','pauseType','fullname','toLowerCase','sortAgentsByStatus','userpic','lastLoginAt','lastPauseAt','address','mailPause','faxPause','chatCapacity','openchannelCapacity','mailCapacity','smsCapacity','openchannelCurrentCapacity','mailCurrentCapacity','whatsappCurrentCapacity','chatStatusTime','openchannelStatusTime','smsStatusTime','voiceStatusTime','queue','screenrecording','phoneBarEnableScreenRecordingByAgent','phoneBarEnableAutomaticScreenRecording','online','omit','pick','filterAgentAttributes','role','mailStatusTime','faxCapacity','whatsappCapacity','faxCurrentCapacity','destconnectedlinenum','onhold','getRealtimeAgentsQueryFields','lodash','jayson/promise','../../mysqldb','client','http','chatPause','smsPause','voicePause','whatsappPause','every','length','unknown','unavailable','ringing','voiceStatus','idle','chatStatus','faxStatus','mailStatus','openchannelStatus','smsStatus','whatsappStatus','request','then','error','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','Agents','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge','catch','pause','isArray','startCase','Queue'];(function(_0x567758,_0x533bba){var _0x1d0e7f=function(_0x1d9d06){while(--_0x1d9d06){_0x567758['push'](_0x567758['shift']());}};_0x1d0e7f(++_0x533bba);}(_0xfaf2,0x169));var _0x2faf=function(_0x42d17d,_0x5cf304){_0x42d17d=_0x42d17d-0x0;var _0x564d94=_0xfaf2[_0x42d17d];return _0x564d94;};'use strict';var _=require(_0x2faf('0x0'));var jayson=require(_0x2faf('0x1'));var db=require(_0x2faf('0x2'))['db'];var amiClient=jayson[_0x2faf('0x3')][_0x2faf('0x4')]({'port':0x232a});var routingClient=jayson['client'][_0x2faf('0x4')]({'port':0x232c});function isAgentPaused(_0xadff87,_0x1be5d0){var _0x4164cc=[_0xadff87[_0x2faf('0x5')],_0xadff87['faxPause'],_0xadff87['mailPause'],_0xadff87['openchannelPause'],_0xadff87[_0x2faf('0x6')],_0xadff87[_0x2faf('0x7')],_0xadff87[_0x2faf('0x8')]];if(!_0x1be5d0)return _[_0x2faf('0x9')](_0x4164cc);var _0x3f5c12=_['filter'](_0x4164cc);return _0x3f5c12['length']>0x0&&_0x3f5c12[_0x2faf('0xa')]<_0x4164cc[_0x2faf('0xa')]?!![]:![];}function isIdle(_0x4ca336){return _0x4ca336==='idle'||_0x4ca336===_0x2faf('0xb')||_0x4ca336===_0x2faf('0xc')||_0x4ca336===_0x2faf('0xd')||_['isNil'](_0x4ca336);}function isAgentIdle(_0x515eb6){if(_0x515eb6[_0x2faf('0xe')]!==_0x2faf('0xf')&&_0x515eb6['voicePause']){_0x515eb6[_0x2faf('0xe')]='pause';return![];}return _[_0x2faf('0x9')]([_0x515eb6[_0x2faf('0x10')],_0x515eb6[_0x2faf('0x11')],_0x515eb6[_0x2faf('0x12')],_0x515eb6[_0x2faf('0x13')],_0x515eb6[_0x2faf('0x14')],_0x515eb6['voiceStatus'],_0x515eb6[_0x2faf('0x15')]],isIdle);}function getRealtimeAgents(){return amiClient[_0x2faf('0x16')]('Agents',{})[_0x2faf('0x17')](function(_0x3be136){if(_0x3be136[_0x2faf('0x18')]){throw new Error(_0x2faf('0x19'));}var _0x4a2dad=_0x3be136[_0x2faf('0x1a')];return routingClient[_0x2faf('0x16')](_0x2faf('0x1b'),{})[_0x2faf('0x17')](function(_0x5a0728){if(_0x5a0728[_0x2faf('0x18')]){throw new Error(_0x2faf('0x1c'));}var _0x934280=_0x5a0728[_0x2faf('0x1a')];return _[_0x2faf('0x1d')]({},_0x4a2dad,_0x934280);});})[_0x2faf('0x1e')](function(_0x2d538a){throw _0x2d538a;});}exports['getRealtimeAgents']=getRealtimeAgents;function getAgentStatus(_0x48627f){var _0x4bf409=_0x2faf('0xb');if(isAgentPaused(_0x48627f))_0x4bf409=_0x2faf('0x1f');else if(isAgentPaused(_0x48627f,!![]))_0x4bf409='*pause';else if(isAgentIdle(_0x48627f))_0x4bf409=_0x2faf('0xf');else _0x4bf409='busy';return _0x4bf409;}exports['getAgentStatus']=getAgentStatus;function getAgentIdsByQueues(_0x328814,_0x2cb862){var _0x5d8cb7=_[_0x2faf('0x20')](_0x328814)?_0x328814:[_0x328814];var _0x3c1e49=_[_0x2faf('0x21')](_0x2cb862)+_0x2faf('0x22');var _0xfe4559=_[_0x2faf('0x23')](_0x5d8cb7,function(_0x1d6649){return db[_0x3c1e49][_0x2faf('0x24')]({'where':{'id':_0x1d6649}})[_0x2faf('0x17')](function(_0x2dd82b){if(!_0x2dd82b)return[];return _0x2dd82b[_0x2faf('0x25')]({'attributes':['id'],'raw':!![]});});});return Promise[_0x2faf('0x26')](_0xfe4559)['then'](function(_0x404f67){var _0x13b655=_(_0x404f67)[_0x2faf('0x27')]()['map']('id')[_0x2faf('0x28')]()[_0x2faf('0x29')]();return _0x13b655;});}exports[_0x2faf('0x2a')]=getAgentIdsByQueues;function getAgentIdsByStatus(_0x3159b8,_0x2b60d7,_0x2bc5e2){try{if(_0x2b60d7['length']>0x0){_0x3159b8=_0x3159b8[_0x2faf('0x2b')](function(_0x583d48){return _0x2b60d7[_0x2faf('0x2c')](_0x583d48['id']);});}var _0x1133a0=_0x3159b8[_0x2faf('0x2b')](function(_0x37398e){var _0x462d9b=_0x2faf('0x2d');if(isAgentIdle(_0x37398e)){_0x462d9b=_0x2faf('0xf');}return _0x462d9b===_0x2bc5e2;});return _[_0x2faf('0x23')](_0x1133a0,'id');}catch(_0x3b504c){throw _0x3b504c;}}exports['getAgentIdsByStatus']=getAgentIdsByStatus;function getSortedAgentsIdsByStatus(_0x2f7522,_0x10216e,_0xfa4391){return Promise[_0x2faf('0x2e')]()[_0x2faf('0x17')](function(){if(_0x10216e['length']>0x0){_0x2f7522=_0x2f7522[_0x2faf('0x2b')](function(_0x3719de){return _0x10216e['includes'](_0x3719de['id']);});}return _0x2f7522;})[_0x2faf('0x17')](function(){return db[_0x2faf('0x2f')][_0x2faf('0x30')]({'attributes':['id',_0x2faf('0x31'),'fullname',_0x2faf('0x5'),'faxPause','mailPause',_0x2faf('0x32'),_0x2faf('0x6'),_0x2faf('0x7'),_0x2faf('0x8'),'pauseType'],'where':{'id':{'$in':_['map'](_0x2f7522,'id')}},'raw':!![]});})[_0x2faf('0x17')](function(_0x1aa654){return _0x1aa654[_0x2faf('0x23')](function(_0x1a34ac){var _0x1a5dbf=_[_0x2faf('0x33')](_0x2f7522,['id',_0x1a34ac['id']]);var _0x5c5d57=filterAgentAttributes(_0x1a5dbf);_[_0x2faf('0x1d')](_0x1a34ac,_0x5c5d57);_0x1a34ac[_0x2faf('0x34')]=getAgentStatus(_0x1a34ac);return _0x1a34ac;});})[_0x2faf('0x17')](function(_0x29eb57){var _0x1c84fd=sortAgentsByStatus(_0x29eb57,_0xfa4391);return _[_0x2faf('0x23')](_0x1c84fd,'id');})[_0x2faf('0x1e')](function(_0x6a2893){throw _0x6a2893;});}exports[_0x2faf('0x35')]=getSortedAgentsIdsByStatus;function getUpdatedSortOptions(_0x108bc7){var _0x2a5660={'fields':[],'order':null};var _0x394948=_0x108bc7[_0x2faf('0x36')](',');_0x2a5660['fields']=_['filter'](_0x394948,function(_0x23f416){if(!_0x23f416[_0x2faf('0x2c')]('globalStatus')){return!![];}_0x2a5660['order']=_[_0x2faf('0x37')](_0x23f416,'-')?_0x2faf('0x38'):_0x2faf('0x39');return![];});return _0x2a5660;}exports[_0x2faf('0x3a')]=getUpdatedSortOptions;function validateSortParameter(_0x14a426){if(!_0x14a426){_0x14a426=_0x2faf('0x3b');}if(_0x14a426[_0x2faf('0x2c')]('fullname')&&!_0x14a426['includes'](_0x2faf('0x3c'))){var _0x596d1b=_0x14a426['substring'](0x0,_0x14a426['indexOf']('fullname'));_0x14a426+=','+_0x596d1b+_0x2faf('0x3c');}return _0x14a426;}exports[_0x2faf('0x3d')]=validateSortParameter;function sortAgentsByStatus(_0x1c2cc7,_0x58b511){var _0x145320=_0x1c2cc7['sort'](function(_0x50c572,_0x22662a){if(_0x50c572[_0x2faf('0x34')]===_0x22662a[_0x2faf('0x34')]){if(_0x50c572[_0x2faf('0x34')]===_0x2faf('0x1f')){if(_0x58b511==='DESC'){return(_0x50c572[_0x2faf('0x3e')]||'')<(_0x22662a[_0x2faf('0x3e')]||'')||_0x50c572[_0x2faf('0x3f')][_0x2faf('0x40')]()>_0x22662a[_0x2faf('0x3f')][_0x2faf('0x40')]()?0x1:-0x1;}else{return(_0x50c572[_0x2faf('0x3e')]||'')<(_0x22662a[_0x2faf('0x3e')]||'')||_0x50c572[_0x2faf('0x3f')][_0x2faf('0x40')]()>_0x22662a[_0x2faf('0x3f')][_0x2faf('0x40')]()?-0x1:0x1;}}else{if(_0x58b511==='DESC'){return _0x50c572[_0x2faf('0x3f')][_0x2faf('0x40')]()<_0x22662a[_0x2faf('0x3f')][_0x2faf('0x40')]()?0x1:-0x1;}else{return _0x50c572[_0x2faf('0x3f')][_0x2faf('0x40')]()<_0x22662a[_0x2faf('0x3f')]['toLowerCase']()?-0x1:0x1;}}}else{if(_0x58b511===_0x2faf('0x38')){return _0x50c572[_0x2faf('0x34')]<_0x22662a[_0x2faf('0x34')]?0x1:-0x1;}else{return _0x50c572[_0x2faf('0x34')]<_0x22662a[_0x2faf('0x34')]?-0x1:0x1;}}});return _0x145320;}exports[_0x2faf('0x41')]=sortAgentsByStatus;function filterAgentAttributes(_0xda4ec6){var _0x541ad5=[_0x2faf('0x42'),'online',_0x2faf('0x43'),_0x2faf('0x44'),_0x2faf('0x3e'),_0x2faf('0x44'),_0x2faf('0x3c'),_0x2faf('0x45'),'chatPause',_0x2faf('0x32'),_0x2faf('0x46'),_0x2faf('0x6'),_0x2faf('0x8'),_0x2faf('0x47'),_0x2faf('0x7'),_0x2faf('0x48'),_0x2faf('0x49'),_0x2faf('0x4a'),_0x2faf('0x4b'),'whatsappCapacity','faxCapacity','chatCurrentCapacity',_0x2faf('0x4c'),_0x2faf('0x4d'),'smsCurrentCapacity',_0x2faf('0x4e'),'faxCurrentCapacity',_0x2faf('0x10'),'openchannelStatus',_0x2faf('0x12'),_0x2faf('0x14'),_0x2faf('0x15'),'faxStatus','voiceStatus',_0x2faf('0x4f'),_0x2faf('0x50'),'mailStatusTime',_0x2faf('0x51'),'whatsappStatusTime','faxStatusTime',_0x2faf('0x52'),_0x2faf('0x53'),'destconnectedlinenum',_0x2faf('0x54'),_0x2faf('0x55'),_0x2faf('0x56')];var _0x3026c4=[_0x2faf('0x5'),_0x2faf('0x32'),_0x2faf('0x46'),_0x2faf('0x6'),_0x2faf('0x8'),_0x2faf('0x47'),'voicePause',_0x2faf('0x57')];var _0x5d966f=_(_0xda4ec6)[_0x2faf('0x58')](_0x3026c4)[_0x2faf('0x59')](_0x541ad5)[_0x2faf('0x29')]();return _0x5d966f;}exports[_0x2faf('0x5a')]=filterAgentAttributes;function getRealtimeAgentsQueryFields(){return['id',_0x2faf('0x31'),_0x2faf('0x3f'),_0x2faf('0x5b'),_0x2faf('0x3c'),'online',_0x2faf('0x34'),'userpic',_0x2faf('0x43'),_0x2faf('0x3e'),_0x2faf('0x44'),'faxPause',_0x2faf('0x5'),'mailPause',_0x2faf('0x32'),_0x2faf('0x6'),'voicePause',_0x2faf('0x8'),_0x2faf('0x10'),'faxStatus',_0x2faf('0x12'),_0x2faf('0x13'),_0x2faf('0x14'),'voiceStatus',_0x2faf('0x15'),_0x2faf('0x4f'),'faxStatusTime',_0x2faf('0x5c'),_0x2faf('0x50'),_0x2faf('0x51'),_0x2faf('0x52'),'whatsappStatusTime',_0x2faf('0x48'),_0x2faf('0x5d'),_0x2faf('0x4a'),'openchannelCapacity',_0x2faf('0x4b'),_0x2faf('0x5e'),'chatCurrentCapacity',_0x2faf('0x5f'),_0x2faf('0x4d'),_0x2faf('0x4c'),'smsCurrentCapacity',_0x2faf('0x4e'),_0x2faf('0x55'),_0x2faf('0x56'),_0x2faf('0x60'),_0x2faf('0x61'),_0x2faf('0x53'),_0x2faf('0x54')];}exports[_0x2faf('0x62')]=getRealtimeAgentsQueryFields;