Built motion from commit (unavailable).|2.5.31
[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 _0xa4b1=['../../../../../config/logger','routing','notificationId','squeue','agent','realtime','push','handleRun','handleTimeout','drained','handleDrained','prototype','bind','isNil','agents','info','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','channel','busyQueue','showNotification','writeLog','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','busy','STOP','exports','lodash','uuid','./util'];(function(_0x5783f4,_0x4a9e0a){var _0x28e380=function(_0x1ffc49){while(--_0x1ffc49){_0x5783f4['push'](_0x5783f4['shift']());}};_0x28e380(++_0x4a9e0a);}(_0xa4b1,0x133));var _0x1a4b=function(_0x126558,_0x143c9a){_0x126558=_0x126558-0x0;var _0x1f6d14=_0xa4b1[_0x126558];return _0x1f6d14;};'use strict';var _=require(_0x1a4b('0x0'));var uuid=require(_0x1a4b('0x1'));var util=require(_0x1a4b('0x2'));var logger=require(_0x1a4b('0x3'))(_0x1a4b('0x4'));var Agent=function(_0x4e2c52,_0x9b913d,_0x243220,_0x4c6e86){this[_0x1a4b('0x5')]=uuid['v4']();this[_0x1a4b('0x6')]=_0x4e2c52;this[_0x1a4b('0x7')]=_0x9b913d;this[_0x1a4b('0x8')]=_0x243220;this['routing']=_0x4c6e86;this[_0x1a4b('0x6')][_0x1a4b('0x9')](this[_0x1a4b('0xa')]['bind'](this),this['handleTimeout']['bind'](this));this[_0x1a4b('0x6')]['on']('timeout',this[_0x1a4b('0xb')]['bind'](this));this['squeue']['on'](_0x1a4b('0xc'),this[_0x1a4b('0xd')]['bind'](this));};Agent[_0x1a4b('0xe')][_0x1a4b('0x9')]=function(){this[_0x1a4b('0x6')][_0x1a4b('0x9')](this[_0x1a4b('0xa')][_0x1a4b('0xf')](this),this[_0x1a4b('0xb')][_0x1a4b('0xf')](this));};Agent[_0x1a4b('0xe')][_0x1a4b('0xd')]=function(){this[_0x1a4b('0xb')](!![]);};Agent[_0x1a4b('0xe')][_0x1a4b('0xa')]=function(_0x3c14a6){logger['info']('[%s][AGENT]\x20try\x20with\x20%s',this[_0x1a4b('0x6')]['id'],this['agent']['id']);if(_[_0x1a4b('0x10')](this[_0x1a4b('0x8')][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']])){logger[_0x1a4b('0x12')](_0x1a4b('0x13'),this[_0x1a4b('0x6')]['id'],this[_0x1a4b('0x7')]['id']);setTimeout(this[_0x1a4b('0x9')][_0x1a4b('0xf')](this),0x3e8);}else{if(this[_0x1a4b('0x4')][_0x1a4b('0x14')]||util[_0x1a4b('0x15')](this[_0x1a4b('0x6')]['id'],this[_0x1a4b('0x8')]['agents'][this[_0x1a4b('0x7')]['id']],this[_0x1a4b('0x6')][_0x1a4b('0x16')],![])){this[_0x1a4b('0x8')][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']]['busy']=!![];this[_0x1a4b('0x8')]['agents'][this[_0x1a4b('0x7')]['id']][_0x1a4b('0x17')]=undefined;util[_0x1a4b('0x18')](this[_0x1a4b('0x5')],this[_0x1a4b('0x6')]['id'],this['realtime'][_0x1a4b('0x11')][this['agent']['id']],null,this[_0x1a4b('0x4')]);util[_0x1a4b('0x19')](this[_0x1a4b('0x6')]['id'],this[_0x1a4b('0x8')][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']],'RINGING'+(this[_0x1a4b('0x4')][_0x1a4b('0x14')]?':FORCED':''));}else{logger[_0x1a4b('0x12')](_0x1a4b('0x1a'),this[_0x1a4b('0x6')]['id'],this[_0x1a4b('0x7')]['id']);setTimeout(this['push'][_0x1a4b('0xf')](this),0x3e8);}}};Agent[_0x1a4b('0xe')][_0x1a4b('0xb')]=function(_0x2a7622){if(_['isNil'](this[_0x1a4b('0x8')][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']])){return logger['info']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],this[_0x1a4b('0x7')]['id']);}else{logger[_0x1a4b('0x12')](_0x1a4b('0x1b'),this[_0x1a4b('0x6')]['id'],this[_0x1a4b('0x7')]['id']);util['hideNotification'](this[_0x1a4b('0x5')],this[_0x1a4b('0x6')]['id'],this['realtime'][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']],null,this[_0x1a4b('0x4')]);this[_0x1a4b('0x8')][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']][_0x1a4b('0x1c')]=![];this[_0x1a4b('0x8')]['agents'][this['agent']['id']]['busyQueue']=undefined;util['writeLog'](this[_0x1a4b('0x6')]['id'],this[_0x1a4b('0x8')][_0x1a4b('0x11')][this[_0x1a4b('0x7')]['id']],_0x2a7622?_0x1a4b('0x1d'):'TIMEOUT');}if(!_0x2a7622){setTimeout(this['push'][_0x1a4b('0xf')](this),0x3e8);}};function agent(_0x1bc074,_0x51a705,_0x4b6553,_0xcc0d71){return new Agent(_0x1bc074,_0x51a705,_0x4b6553,_0xcc0d71);}module[_0x1a4b('0x1e')]=agent;