c9706bec79cb2d205003c4982690b62306a7054d
[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 _0x3228=['lodash','../../../../../config/logger','routing','notificationId','squeue','agent','handleRun','bind','handleTimeout','timeout','drained','handleDrained','push','prototype','info','[%s][AGENT]\x20try\x20with\x20%s','isNil','realtime','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','agents','channel','busyQueue','showNotification','writeLog','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busy','STOP','TIMEOUT','exports'];(function(_0x26ffb0,_0x41f8ef){var _0x30de1e=function(_0x330e56){while(--_0x330e56){_0x26ffb0['push'](_0x26ffb0['shift']());}};_0x30de1e(++_0x41f8ef);}(_0x3228,0x181));var _0x8322=function(_0x2a7f5e,_0x19dc14){_0x2a7f5e=_0x2a7f5e-0x0;var _0x4696b2=_0x3228[_0x2a7f5e];return _0x4696b2;};'use strict';var _=require(_0x8322('0x0'));var uuid=require('uuid');var util=require('./util');var logger=require(_0x8322('0x1'))(_0x8322('0x2'));var Agent=function(_0x438853,_0x427136,_0x1bbf32,_0xd34918){this[_0x8322('0x3')]=uuid['v4']();this[_0x8322('0x4')]=_0x438853;this[_0x8322('0x5')]=_0x427136;this['realtime']=_0x1bbf32;this[_0x8322('0x2')]=_0xd34918;this[_0x8322('0x4')]['push'](this[_0x8322('0x6')][_0x8322('0x7')](this),this[_0x8322('0x8')][_0x8322('0x7')](this));this[_0x8322('0x4')]['on'](_0x8322('0x9'),this[_0x8322('0x8')][_0x8322('0x7')](this));this[_0x8322('0x4')]['on'](_0x8322('0xa'),this[_0x8322('0xb')]['bind'](this));};Agent['prototype'][_0x8322('0xc')]=function(){this[_0x8322('0x4')][_0x8322('0xc')](this[_0x8322('0x6')][_0x8322('0x7')](this),this[_0x8322('0x8')][_0x8322('0x7')](this));};Agent[_0x8322('0xd')][_0x8322('0xb')]=function(){this[_0x8322('0x8')](!![]);};Agent[_0x8322('0xd')][_0x8322('0x6')]=function(_0x11c3b1){logger[_0x8322('0xe')](_0x8322('0xf'),this[_0x8322('0x4')]['id'],this[_0x8322('0x5')]['id']);if(_[_0x8322('0x10')](this[_0x8322('0x11')]['agents'][this[_0x8322('0x5')]['id']])){logger['info'](_0x8322('0x12'),this[_0x8322('0x4')]['id'],this[_0x8322('0x5')]['id']);setTimeout(this[_0x8322('0xc')][_0x8322('0x7')](this),0x3e8);}else{if(this[_0x8322('0x2')][_0x8322('0x13')]||util[_0x8322('0x14')](this['squeue']['id'],this[_0x8322('0x11')][_0x8322('0x15')][this[_0x8322('0x5')]['id']],this[_0x8322('0x4')][_0x8322('0x16')],![])){this[_0x8322('0x11')][_0x8322('0x15')][this['agent']['id']]['busy']=!![];this['realtime'][_0x8322('0x15')][this[_0x8322('0x5')]['id']][_0x8322('0x17')]=undefined;util[_0x8322('0x18')](this[_0x8322('0x3')],this[_0x8322('0x4')]['id'],this[_0x8322('0x11')][_0x8322('0x15')][this[_0x8322('0x5')]['id']],null,this[_0x8322('0x2')]);util[_0x8322('0x19')](this[_0x8322('0x4')]['id'],this[_0x8322('0x11')][_0x8322('0x15')][this['agent']['id']],_0x8322('0x1a')+(this[_0x8322('0x2')][_0x8322('0x13')]?_0x8322('0x1b'):''));}else{logger[_0x8322('0xe')](_0x8322('0x1c'),this[_0x8322('0x4')]['id'],this[_0x8322('0x5')]['id']);setTimeout(this[_0x8322('0xc')][_0x8322('0x7')](this),0x3e8);}}};Agent[_0x8322('0xd')]['handleTimeout']=function(_0x4e93b2){if(_[_0x8322('0x10')](this['realtime'][_0x8322('0x15')][this['agent']['id']])){return logger[_0x8322('0xe')](_0x8322('0x12'),this['squeue']['id'],this[_0x8322('0x5')]['id']);}else{logger[_0x8322('0xe')](_0x8322('0x1d'),this[_0x8322('0x4')]['id'],this[_0x8322('0x5')]['id']);util[_0x8322('0x1e')](this[_0x8322('0x3')],this[_0x8322('0x4')]['id'],this[_0x8322('0x11')][_0x8322('0x15')][this[_0x8322('0x5')]['id']],null,this[_0x8322('0x2')]);this[_0x8322('0x11')][_0x8322('0x15')][this[_0x8322('0x5')]['id']][_0x8322('0x1f')]=![];this['realtime'][_0x8322('0x15')][this['agent']['id']][_0x8322('0x17')]=undefined;util[_0x8322('0x19')](this['squeue']['id'],this[_0x8322('0x11')][_0x8322('0x15')][this[_0x8322('0x5')]['id']],_0x4e93b2?_0x8322('0x20'):_0x8322('0x21'));}if(!_0x4e93b2){setTimeout(this['push'][_0x8322('0x7')](this),0x3e8);}};function agent(_0x20914b,_0x3b85b0,_0x4459e7,_0x36b687){return new Agent(_0x20914b,_0x3b85b0,_0x4459e7,_0x36b687);}module[_0x8322('0x22')]=agent;