Built motion from commit f67b3b02.|2.6.31
[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 _0xeb3f=['unknown','pause','*pause','busy','getAgentStatus','isArray','startCase','map','findOne','getAgents','flatten','uniq','value','getAgentIdsByQueues','includes','getAgentIdsByStatus','resolve','name','fullname','pauseType','find','globalStatus','catch','split','fields','startsWith','ASC','getUpdatedSortOptions','fullname,internal','internal','substring','indexOf','validateSortParameter','sort','DESC','toLowerCase','userpic','lastLoginAt','lastPauseAt','chatCapacity','mailCapacity','smsCapacity','whatsappCapacity','faxCapacity','chatCurrentCapacity','openchannelCurrentCapacity','mailCurrentCapacity','smsCurrentCapacity','whatsappCurrentCapacity','faxCurrentCapacity','openchannelStatus','chatStatusTime','openchannelStatusTime','mailStatusTime','smsStatusTime','faxStatusTime','voiceStatusTime','destconnectedlinenum','phoneBarEnableScreenRecordingByAgent','online','pick','filterAgentAttributes','whatsappStatusTime','openchannelCapacity','phoneBarEnableAutomaticScreenRecording','onhold','queue','screenrecording','lodash','jayson/promise','../../mysqldb','client','http','chatPause','faxPause','mailPause','openchannelPause','smsPause','whatsappPause','every','filter','length','idle','unavailable','ringing','isNil','voiceStatus','voicePause','chatStatus','faxStatus','mailStatus','smsStatus','whatsappStatus','request','Agents','then','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(AMI)','result','Unable\x20to\x20retrieve\x20RPC\x20agents\x20(Routing)','merge'];(function(_0x5027b1,_0x1409a5){var _0x4a46cf=function(_0x121920){while(--_0x121920){_0x5027b1['push'](_0x5027b1['shift']());}};_0x4a46cf(++_0x1409a5);}(_0xeb3f,0xa8));var _0xfeb3=function(_0x21a9d9,_0x4d5ac8){_0x21a9d9=_0x21a9d9-0x0;var _0x46adce=_0xeb3f[_0x21a9d9];return _0x46adce;};'use strict';var _=require(_0xfeb3('0x0'));var jayson=require(_0xfeb3('0x1'));var db=require(_0xfeb3('0x2'))['db'];var amiClient=jayson[_0xfeb3('0x3')][_0xfeb3('0x4')]({'port':0x232a});var routingClient=jayson[_0xfeb3('0x3')][_0xfeb3('0x4')]({'port':0x232c});function isAgentPaused(_0x1b0d84,_0x1f27f4){var _0x125a2f=[_0x1b0d84[_0xfeb3('0x5')],_0x1b0d84[_0xfeb3('0x6')],_0x1b0d84[_0xfeb3('0x7')],_0x1b0d84[_0xfeb3('0x8')],_0x1b0d84[_0xfeb3('0x9')],_0x1b0d84['voicePause'],_0x1b0d84[_0xfeb3('0xa')]];if(!_0x1f27f4)return _[_0xfeb3('0xb')](_0x125a2f);var _0x45695c=_[_0xfeb3('0xc')](_0x125a2f);return _0x45695c[_0xfeb3('0xd')]>0x0&&_0x45695c[_0xfeb3('0xd')]<_0x125a2f[_0xfeb3('0xd')]?!![]:![];}function isIdle(_0x2b9150){return _0x2b9150===_0xfeb3('0xe')||_0x2b9150==='unknown'||_0x2b9150===_0xfeb3('0xf')||_0x2b9150===_0xfeb3('0x10')||_[_0xfeb3('0x11')](_0x2b9150);}function isAgentIdle(_0x1838b3){if(_0x1838b3[_0xfeb3('0x12')]!==_0xfeb3('0xe')&&_0x1838b3[_0xfeb3('0x13')]){_0x1838b3[_0xfeb3('0x12')]='pause';return![];}return _[_0xfeb3('0xb')]([_0x1838b3[_0xfeb3('0x14')],_0x1838b3[_0xfeb3('0x15')],_0x1838b3[_0xfeb3('0x16')],_0x1838b3['openchannelStatus'],_0x1838b3[_0xfeb3('0x17')],_0x1838b3['voiceStatus'],_0x1838b3[_0xfeb3('0x18')]],isIdle);}function getRealtimeAgents(){return amiClient[_0xfeb3('0x19')](_0xfeb3('0x1a'),{})[_0xfeb3('0x1b')](function(_0x1b6df3){if(_0x1b6df3['error']){throw new Error(_0xfeb3('0x1c'));}var _0x363a9c=_0x1b6df3[_0xfeb3('0x1d')];return routingClient['request']('Agents',{})['then'](function(_0x1465d4){if(_0x1465d4['error']){throw new Error(_0xfeb3('0x1e'));}var _0x1fdb64=_0x1465d4[_0xfeb3('0x1d')];return _[_0xfeb3('0x1f')]({},_0x363a9c,_0x1fdb64);});})['catch'](function(_0x338c37){throw _0x338c37;});}exports['getRealtimeAgents']=getRealtimeAgents;function getAgentStatus(_0x505f02){var _0x4d48a2=_0xfeb3('0x20');if(isAgentPaused(_0x505f02))_0x4d48a2=_0xfeb3('0x21');else if(isAgentPaused(_0x505f02,!![]))_0x4d48a2=_0xfeb3('0x22');else if(isAgentIdle(_0x505f02))_0x4d48a2='idle';else _0x4d48a2=_0xfeb3('0x23');return _0x4d48a2;}exports[_0xfeb3('0x24')]=getAgentStatus;function getAgentIdsByQueues(_0x421ccd,_0x43a21f){var _0x8b1cc1=_[_0xfeb3('0x25')](_0x421ccd)?_0x421ccd:[_0x421ccd];var _0x4704fa=_[_0xfeb3('0x26')](_0x43a21f)+'Queue';var _0x3978eb=_[_0xfeb3('0x27')](_0x8b1cc1,function(_0x9580ae){return db[_0x4704fa][_0xfeb3('0x28')]({'where':{'id':_0x9580ae}})[_0xfeb3('0x1b')](function(_0x17b5f4){if(!_0x17b5f4)return[];return _0x17b5f4[_0xfeb3('0x29')]({'attributes':['id'],'raw':!![]});});});return Promise['all'](_0x3978eb)[_0xfeb3('0x1b')](function(_0x5d6b65){var _0x279c3e=_(_0x5d6b65)[_0xfeb3('0x2a')]()['map']('id')[_0xfeb3('0x2b')]()[_0xfeb3('0x2c')]();return _0x279c3e;});}exports[_0xfeb3('0x2d')]=getAgentIdsByQueues;function getAgentIdsByStatus(_0x2a6df6,_0x4a7478,_0x1d8c33){try{if(_0x4a7478[_0xfeb3('0xd')]>0x0){_0x2a6df6=_0x2a6df6[_0xfeb3('0xc')](function(_0x4c3781){return _0x4a7478[_0xfeb3('0x2e')](_0x4c3781['id']);});}var _0x499096=_0x2a6df6[_0xfeb3('0xc')](function(_0x342a91){var _0x380c98=_0xfeb3('0x23');if(isAgentIdle(_0x342a91)){_0x380c98=_0xfeb3('0xe');}return _0x380c98===_0x1d8c33;});return _[_0xfeb3('0x27')](_0x499096,'id');}catch(_0x27fd16){throw _0x27fd16;}}exports[_0xfeb3('0x2f')]=getAgentIdsByStatus;function getSortedAgentsIdsByStatus(_0x38cbec,_0x3582d8,_0xe35b03){return Promise[_0xfeb3('0x30')]()['then'](function(){if(_0x3582d8['length']>0x0){_0x38cbec=_0x38cbec[_0xfeb3('0xc')](function(_0x31bbff){return _0x3582d8[_0xfeb3('0x2e')](_0x31bbff['id']);});}return _0x38cbec;})[_0xfeb3('0x1b')](function(){return db['User']['findAll']({'attributes':['id',_0xfeb3('0x31'),_0xfeb3('0x32'),_0xfeb3('0x5'),_0xfeb3('0x6'),_0xfeb3('0x7'),_0xfeb3('0x8'),_0xfeb3('0x9'),_0xfeb3('0x13'),_0xfeb3('0xa'),_0xfeb3('0x33')],'where':{'id':{'$in':_[_0xfeb3('0x27')](_0x38cbec,'id')}},'raw':!![]});})[_0xfeb3('0x1b')](function(_0x2539c1){return _0x2539c1[_0xfeb3('0x27')](function(_0x175304){var _0x390bc3=_[_0xfeb3('0x34')](_0x38cbec,['id',_0x175304['id']]);var _0x3500c5=filterAgentAttributes(_0x390bc3);_['merge'](_0x175304,_0x3500c5);_0x175304[_0xfeb3('0x35')]=getAgentStatus(_0x175304);return _0x175304;});})[_0xfeb3('0x1b')](function(_0x88d0d0){var _0x305f29=sortAgentsByStatus(_0x88d0d0,_0xe35b03);return _[_0xfeb3('0x27')](_0x305f29,'id');})[_0xfeb3('0x36')](function(_0x504527){throw _0x504527;});}exports['getSortedAgentsIdsByStatus']=getSortedAgentsIdsByStatus;function getUpdatedSortOptions(_0x8f15a8){var _0x6d3617={'fields':[],'order':null};var _0x1f7941=_0x8f15a8[_0xfeb3('0x37')](',');_0x6d3617[_0xfeb3('0x38')]=_[_0xfeb3('0xc')](_0x1f7941,function(_0x22616e){if(!_0x22616e['includes']('globalStatus')){return!![];}_0x6d3617['order']=_[_0xfeb3('0x39')](_0x22616e,'-')?'DESC':_0xfeb3('0x3a');return![];});return _0x6d3617;}exports[_0xfeb3('0x3b')]=getUpdatedSortOptions;function validateSortParameter(_0xee3ef0){if(!_0xee3ef0){_0xee3ef0=_0xfeb3('0x3c');}if(_0xee3ef0[_0xfeb3('0x2e')](_0xfeb3('0x32'))&&!_0xee3ef0['includes'](_0xfeb3('0x3d'))){var _0x5dc530=_0xee3ef0[_0xfeb3('0x3e')](0x0,_0xee3ef0[_0xfeb3('0x3f')](_0xfeb3('0x32')));_0xee3ef0+=','+_0x5dc530+_0xfeb3('0x3d');}return _0xee3ef0;}exports[_0xfeb3('0x40')]=validateSortParameter;function sortAgentsByStatus(_0x327b37,_0x2fd65c){var _0x452a07=_0x327b37[_0xfeb3('0x41')](function(_0x196b03,_0x11a504){if(_0x196b03['globalStatus']===_0x11a504[_0xfeb3('0x35')]){if(_0x196b03[_0xfeb3('0x35')]==='pause'){if(_0x2fd65c===_0xfeb3('0x42')){return(_0x196b03['pauseType']||'')<(_0x11a504[_0xfeb3('0x33')]||'')||_0x196b03['fullname'][_0xfeb3('0x43')]()>_0x11a504['fullname'][_0xfeb3('0x43')]()?0x1:-0x1;}else{return(_0x196b03['pauseType']||'')<(_0x11a504[_0xfeb3('0x33')]||'')||_0x196b03[_0xfeb3('0x32')]['toLowerCase']()>_0x11a504['fullname'][_0xfeb3('0x43')]()?-0x1:0x1;}}else{if(_0x2fd65c==='DESC'){return _0x196b03[_0xfeb3('0x32')][_0xfeb3('0x43')]()<_0x11a504[_0xfeb3('0x32')][_0xfeb3('0x43')]()?0x1:-0x1;}else{return _0x196b03[_0xfeb3('0x32')][_0xfeb3('0x43')]()<_0x11a504[_0xfeb3('0x32')][_0xfeb3('0x43')]()?-0x1:0x1;}}}else{if(_0x2fd65c===_0xfeb3('0x42')){return _0x196b03[_0xfeb3('0x35')]<_0x11a504[_0xfeb3('0x35')]?0x1:-0x1;}else{return _0x196b03[_0xfeb3('0x35')]<_0x11a504[_0xfeb3('0x35')]?-0x1:0x1;}}});return _0x452a07;}exports['sortAgentsByStatus']=sortAgentsByStatus;function filterAgentAttributes(_0xca6cae){var _0x4c317b=[_0xfeb3('0x44'),'online',_0xfeb3('0x45'),_0xfeb3('0x46'),_0xfeb3('0x33'),_0xfeb3('0x46'),_0xfeb3('0x3d'),'address',_0xfeb3('0x5'),'openchannelPause',_0xfeb3('0x7'),'smsPause',_0xfeb3('0xa'),_0xfeb3('0x6'),_0xfeb3('0x13'),_0xfeb3('0x47'),'openchannelCapacity',_0xfeb3('0x48'),_0xfeb3('0x49'),_0xfeb3('0x4a'),_0xfeb3('0x4b'),_0xfeb3('0x4c'),_0xfeb3('0x4d'),_0xfeb3('0x4e'),_0xfeb3('0x4f'),_0xfeb3('0x50'),_0xfeb3('0x51'),_0xfeb3('0x14'),_0xfeb3('0x52'),'mailStatus',_0xfeb3('0x17'),_0xfeb3('0x18'),_0xfeb3('0x15'),_0xfeb3('0x12'),_0xfeb3('0x53'),_0xfeb3('0x54'),_0xfeb3('0x55'),_0xfeb3('0x56'),'whatsappStatusTime',_0xfeb3('0x57'),_0xfeb3('0x58'),'queue',_0xfeb3('0x59'),'screenrecording',_0xfeb3('0x5a'),'phoneBarEnableAutomaticScreenRecording'];var _0xf61925=[_0xfeb3('0x5'),'openchannelPause',_0xfeb3('0x7'),_0xfeb3('0x9'),_0xfeb3('0xa'),_0xfeb3('0x6'),_0xfeb3('0x13'),_0xfeb3('0x5b')];var _0x138ebd=_(_0xca6cae)['omit'](_0xf61925)[_0xfeb3('0x5c')](_0x4c317b)[_0xfeb3('0x2c')]();return _0x138ebd;}exports[_0xfeb3('0x5d')]=filterAgentAttributes;function getRealtimeAgentsQueryFields(){return['id',_0xfeb3('0x31'),'fullname','role',_0xfeb3('0x3d'),_0xfeb3('0x5b'),'globalStatus','userpic',_0xfeb3('0x45'),_0xfeb3('0x33'),'lastPauseAt',_0xfeb3('0x6'),'chatPause',_0xfeb3('0x7'),_0xfeb3('0x8'),'smsPause',_0xfeb3('0x13'),_0xfeb3('0xa'),_0xfeb3('0x14'),'faxStatus',_0xfeb3('0x16'),_0xfeb3('0x52'),_0xfeb3('0x17'),_0xfeb3('0x12'),_0xfeb3('0x18'),_0xfeb3('0x53'),'faxStatusTime',_0xfeb3('0x55'),_0xfeb3('0x54'),_0xfeb3('0x56'),_0xfeb3('0x58'),_0xfeb3('0x5e'),'chatCapacity',_0xfeb3('0x4b'),_0xfeb3('0x48'),_0xfeb3('0x5f'),'smsCapacity',_0xfeb3('0x4a'),_0xfeb3('0x4c'),'faxCurrentCapacity',_0xfeb3('0x4e'),_0xfeb3('0x4d'),'smsCurrentCapacity','whatsappCurrentCapacity',_0xfeb3('0x5a'),_0xfeb3('0x60'),_0xfeb3('0x59'),_0xfeb3('0x61'),_0xfeb3('0x62'),_0xfeb3('0x63')];}exports['getRealtimeAgentsQueryFields']=getRealtimeAgentsQueryFields;