52972d7a618b0a64d0e13ed8cbf09168a320c27e
[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 _0x302c=['handleTimeout','timeout','drained','handleDrained','prototype','info','forcedOwnership','isAgentAvailable','agents','busy','busyQueue','notificationId','writeLog','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','[%s][AGENT]\x20timeout\x20with\x20%s','STOP','exports','lodash','uuid','../../../../../config/logger','routing','agent','realtime','squeue','push','handleRun','bind'];(function(_0x1ae56c,_0x412080){var _0x1d5f02=function(_0x45b698){while(--_0x45b698){_0x1ae56c['push'](_0x1ae56c['shift']());}};_0x1d5f02(++_0x412080);}(_0x302c,0x140));var _0xc302=function(_0x315a7b,_0x4a0c39){_0x315a7b=_0x315a7b-0x0;var _0xe88cbe=_0x302c[_0x315a7b];return _0xe88cbe;};'use strict';var _=require(_0xc302('0x0'));var uuid=require(_0xc302('0x1'));var util=require('./util');var logger=require(_0xc302('0x2'))(_0xc302('0x3'));var Agent=function(_0x2b1a44,_0x57b490,_0x386bda,_0x1296a0){this['notificationId']=uuid['v4']();this['squeue']=_0x2b1a44;this[_0xc302('0x4')]=_0x57b490;this[_0xc302('0x5')]=_0x386bda;this[_0xc302('0x3')]=_0x1296a0;this[_0xc302('0x6')][_0xc302('0x7')](this[_0xc302('0x8')][_0xc302('0x9')](this),this[_0xc302('0xa')][_0xc302('0x9')](this));this[_0xc302('0x6')]['on'](_0xc302('0xb'),this['handleTimeout'][_0xc302('0x9')](this));this[_0xc302('0x6')]['on'](_0xc302('0xc'),this[_0xc302('0xd')][_0xc302('0x9')](this));};Agent[_0xc302('0xe')][_0xc302('0x7')]=function(){this[_0xc302('0x6')]['push'](this['handleRun'][_0xc302('0x9')](this),this['handleTimeout'][_0xc302('0x9')](this));};Agent['prototype'][_0xc302('0xd')]=function(){this['handleTimeout'](!![]);};Agent[_0xc302('0xe')][_0xc302('0x8')]=function(_0x3152b5){logger[_0xc302('0xf')]('[%s][AGENT]\x20try\x20with\x20%s',this[_0xc302('0x6')]['id'],this[_0xc302('0x4')]['id']);if(_['isNil'](this[_0xc302('0x5')]['agents'][this[_0xc302('0x4')]['id']])){logger['info']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xc302('0x6')]['id'],this[_0xc302('0x4')]['id']);setTimeout(this[_0xc302('0x7')]['bind'](this),0x3e8);}else{if(this[_0xc302('0x3')][_0xc302('0x10')]||util[_0xc302('0x11')](this['squeue']['id'],this[_0xc302('0x5')][_0xc302('0x12')][this[_0xc302('0x4')]['id']],this['squeue']['channel'],![])){this['realtime']['agents'][this[_0xc302('0x4')]['id']][_0xc302('0x13')]=!![];this[_0xc302('0x5')]['agents'][this[_0xc302('0x4')]['id']][_0xc302('0x14')]=undefined;util['showNotification'](this[_0xc302('0x15')],this['squeue']['id'],this[_0xc302('0x5')]['agents'][this[_0xc302('0x4')]['id']],null,this['routing']);util[_0xc302('0x16')](this[_0xc302('0x6')]['id'],this[_0xc302('0x5')][_0xc302('0x12')][this[_0xc302('0x4')]['id']],_0xc302('0x17')+(this[_0xc302('0x3')]['forcedOwnership']?_0xc302('0x18'):''));}else{logger[_0xc302('0xf')](_0xc302('0x19'),this[_0xc302('0x6')]['id'],this[_0xc302('0x4')]['id']);setTimeout(this[_0xc302('0x7')][_0xc302('0x9')](this),0x3e8);}}};Agent['prototype'][_0xc302('0xa')]=function(_0x2856cc){if(_['isNil'](this['realtime'][_0xc302('0x12')][this[_0xc302('0x4')]['id']])){return logger[_0xc302('0xf')](_0xc302('0x1a'),this[_0xc302('0x6')]['id'],this[_0xc302('0x4')]['id']);}else{logger[_0xc302('0xf')](_0xc302('0x1b'),this[_0xc302('0x6')]['id'],this[_0xc302('0x4')]['id']);util['hideNotification'](this['notificationId'],this[_0xc302('0x6')]['id'],this[_0xc302('0x5')][_0xc302('0x12')][this['agent']['id']],null,this['routing']);this[_0xc302('0x5')][_0xc302('0x12')][this[_0xc302('0x4')]['id']][_0xc302('0x13')]=![];this[_0xc302('0x5')][_0xc302('0x12')][this[_0xc302('0x4')]['id']][_0xc302('0x14')]=undefined;util['writeLog'](this['squeue']['id'],this[_0xc302('0x5')][_0xc302('0x12')][this['agent']['id']],_0x2856cc?_0xc302('0x1c'):'TIMEOUT');}if(!_0x2856cc){setTimeout(this['push'][_0xc302('0x9')](this),0x3e8);}};function agent(_0x3c25dc,_0x576faa,_0x3751b5,_0x5863e6){return new Agent(_0x3c25dc,_0x576faa,_0x3751b5,_0x5863e6);}module[_0xc302('0x1d')]=agent;