71649ec9698543da7b58baceac1f9b5cbac0547d
[motion2.git] / server / services / routing / server / applications / strategy / agent.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 _0x7a2e=['busy','STOP','TIMEOUT','uuid','./util','../../../../../config/logger','routing','notificationId','squeue','agent','realtime','push','handleRun','bind','handleTimeout','timeout','drained','handleDrained','prototype','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','channel','busyQueue','showNotification','writeLog','RINGING','forcedOwnership',':FORCED','info','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification'];(function(_0x5be613,_0x1469db){var _0x2a20fc=function(_0x35e8fe){while(--_0x35e8fe){_0x5be613['push'](_0x5be613['shift']());}};_0x2a20fc(++_0x1469db);}(_0x7a2e,0x69));var _0xe7a2=function(_0x1cc8fe,_0x105328){_0x1cc8fe=_0x1cc8fe-0x0;var _0x230054=_0x7a2e[_0x1cc8fe];return _0x230054;};'use strict';var _=require('lodash');var uuid=require(_0xe7a2('0x0'));var util=require(_0xe7a2('0x1'));var logger=require(_0xe7a2('0x2'))(_0xe7a2('0x3'));var Agent=function(_0x3654aa,_0x1786e0,_0x5af18f,_0x453290){this[_0xe7a2('0x4')]=uuid['v4']();this[_0xe7a2('0x5')]=_0x3654aa;this[_0xe7a2('0x6')]=_0x1786e0;this[_0xe7a2('0x7')]=_0x5af18f;this[_0xe7a2('0x3')]=_0x453290;this[_0xe7a2('0x5')][_0xe7a2('0x8')](this[_0xe7a2('0x9')][_0xe7a2('0xa')](this),this[_0xe7a2('0xb')][_0xe7a2('0xa')](this));this[_0xe7a2('0x5')]['on'](_0xe7a2('0xc'),this['handleTimeout']['bind'](this));this['squeue']['on'](_0xe7a2('0xd'),this[_0xe7a2('0xe')][_0xe7a2('0xa')](this));};Agent[_0xe7a2('0xf')][_0xe7a2('0x8')]=function(){this[_0xe7a2('0x5')][_0xe7a2('0x8')](this[_0xe7a2('0x9')][_0xe7a2('0xa')](this),this[_0xe7a2('0xb')]['bind'](this));};Agent['prototype'][_0xe7a2('0xe')]=function(){this[_0xe7a2('0xb')](!![]);};Agent[_0xe7a2('0xf')][_0xe7a2('0x9')]=function(_0x3c1e26){logger['info'](_0xe7a2('0x10'),this[_0xe7a2('0x5')]['id'],this['agent']['id']);if(_[_0xe7a2('0x11')](this[_0xe7a2('0x7')][_0xe7a2('0x12')][this['agent']['id']])){logger['info'](_0xe7a2('0x13'),this[_0xe7a2('0x5')]['id'],this[_0xe7a2('0x6')]['id']);setTimeout(this[_0xe7a2('0x8')][_0xe7a2('0xa')](this),0x3e8);}else{if(this[_0xe7a2('0x3')]['forcedOwnership']||util[_0xe7a2('0x14')](this[_0xe7a2('0x5')]['id'],this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']],this[_0xe7a2('0x5')][_0xe7a2('0x15')],![])){this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']]['busy']=!![];this[_0xe7a2('0x7')][_0xe7a2('0x12')][this['agent']['id']][_0xe7a2('0x16')]=undefined;util[_0xe7a2('0x17')](this[_0xe7a2('0x4')],this['squeue']['id'],this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']],null,this[_0xe7a2('0x3')]);util[_0xe7a2('0x18')](this[_0xe7a2('0x5')]['id'],this[_0xe7a2('0x7')][_0xe7a2('0x12')][this['agent']['id']],_0xe7a2('0x19')+(this['routing'][_0xe7a2('0x1a')]?_0xe7a2('0x1b'):''));}else{logger['info']('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this['squeue']['id'],this[_0xe7a2('0x6')]['id']);setTimeout(this[_0xe7a2('0x8')]['bind'](this),0x3e8);}}};Agent[_0xe7a2('0xf')][_0xe7a2('0xb')]=function(_0x56bf7d){if(_[_0xe7a2('0x11')](this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']])){return logger[_0xe7a2('0x1c')](_0xe7a2('0x13'),this['squeue']['id'],this['agent']['id']);}else{logger[_0xe7a2('0x1c')](_0xe7a2('0x1d'),this[_0xe7a2('0x5')]['id'],this['agent']['id']);util[_0xe7a2('0x1e')](this['notificationId'],this[_0xe7a2('0x5')]['id'],this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']],null,this[_0xe7a2('0x3')]);this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']][_0xe7a2('0x1f')]=![];this[_0xe7a2('0x7')][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']]['busyQueue']=undefined;util['writeLog'](this[_0xe7a2('0x5')]['id'],this['realtime'][_0xe7a2('0x12')][this[_0xe7a2('0x6')]['id']],_0x56bf7d?_0xe7a2('0x20'):_0xe7a2('0x21'));}if(!_0x56bf7d){setTimeout(this[_0xe7a2('0x8')][_0xe7a2('0xa')](this),0x3e8);}};function agent(_0x357f4f,_0x517f5a,_0x1e192d,_0x5f0165){return new Agent(_0x357f4f,_0x517f5a,_0x1e192d,_0x5f0165);}module['exports']=agent;