07a79501f01ff58a311343f0fc4f9a1049d24408
[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 _0x65d8=['agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','realtime','channel','busy','showNotification','writeLog','RINGING','forcedOwnership',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busyQueue','TIMEOUT','uuid','../../../../../config/logger','routing','notificationId','squeue','push','bind','timeout','handleTimeout','drained','prototype','handleRun','handleDrained','info','[%s][AGENT]\x20try\x20with\x20%s','agent','isNil'];(function(_0x3303bf,_0x51e0ef){var _0x185d3c=function(_0x5d0447){while(--_0x5d0447){_0x3303bf['push'](_0x3303bf['shift']());}};_0x185d3c(++_0x51e0ef);}(_0x65d8,0x139));var _0x865d=function(_0x122ef9,_0x451d2a){_0x122ef9=_0x122ef9-0x0;var _0x42fba0=_0x65d8[_0x122ef9];return _0x42fba0;};'use strict';var _=require('lodash');var uuid=require(_0x865d('0x0'));var util=require('./util');var logger=require(_0x865d('0x1'))(_0x865d('0x2'));var Agent=function(_0x212fd9,_0x2739d6,_0x15a673,_0x474079){this[_0x865d('0x3')]=uuid['v4']();this[_0x865d('0x4')]=_0x212fd9;this['agent']=_0x2739d6;this['realtime']=_0x15a673;this[_0x865d('0x2')]=_0x474079;this[_0x865d('0x4')][_0x865d('0x5')](this['handleRun']['bind'](this),this['handleTimeout'][_0x865d('0x6')](this));this[_0x865d('0x4')]['on'](_0x865d('0x7'),this[_0x865d('0x8')]['bind'](this));this[_0x865d('0x4')]['on'](_0x865d('0x9'),this['handleDrained'][_0x865d('0x6')](this));};Agent[_0x865d('0xa')][_0x865d('0x5')]=function(){this[_0x865d('0x4')]['push'](this[_0x865d('0xb')][_0x865d('0x6')](this),this[_0x865d('0x8')][_0x865d('0x6')](this));};Agent[_0x865d('0xa')][_0x865d('0xc')]=function(){this[_0x865d('0x8')](!![]);};Agent[_0x865d('0xa')][_0x865d('0xb')]=function(_0x13d6f5){logger[_0x865d('0xd')](_0x865d('0xe'),this[_0x865d('0x4')]['id'],this[_0x865d('0xf')]['id']);if(_[_0x865d('0x10')](this['realtime'][_0x865d('0x11')][this[_0x865d('0xf')]['id']])){logger[_0x865d('0xd')](_0x865d('0x12'),this[_0x865d('0x4')]['id'],this[_0x865d('0xf')]['id']);setTimeout(this[_0x865d('0x5')][_0x865d('0x6')](this),0x3e8);}else{if(this['routing']['forcedOwnership']||util[_0x865d('0x13')](this[_0x865d('0x4')]['id'],this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']],this[_0x865d('0x4')][_0x865d('0x15')],![])){this[_0x865d('0x14')]['agents'][this[_0x865d('0xf')]['id']][_0x865d('0x16')]=!![];this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']]['busyQueue']=undefined;util[_0x865d('0x17')](this['notificationId'],this[_0x865d('0x4')]['id'],this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']],null,this[_0x865d('0x2')]);util[_0x865d('0x18')](this[_0x865d('0x4')]['id'],this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']],_0x865d('0x19')+(this[_0x865d('0x2')][_0x865d('0x1a')]?_0x865d('0x1b'):''));}else{logger[_0x865d('0xd')](_0x865d('0x1c'),this[_0x865d('0x4')]['id'],this['agent']['id']);setTimeout(this[_0x865d('0x5')][_0x865d('0x6')](this),0x3e8);}}};Agent[_0x865d('0xa')][_0x865d('0x8')]=function(_0x1dc022){if(_[_0x865d('0x10')](this[_0x865d('0x14')]['agents'][this[_0x865d('0xf')]['id']])){return logger[_0x865d('0xd')](_0x865d('0x12'),this[_0x865d('0x4')]['id'],this[_0x865d('0xf')]['id']);}else{logger['info'](_0x865d('0x1d'),this[_0x865d('0x4')]['id'],this[_0x865d('0xf')]['id']);util[_0x865d('0x1e')](this[_0x865d('0x3')],this[_0x865d('0x4')]['id'],this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']],null,this[_0x865d('0x2')]);this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']]['busy']=![];this['realtime'][_0x865d('0x11')][this['agent']['id']][_0x865d('0x1f')]=undefined;util[_0x865d('0x18')](this[_0x865d('0x4')]['id'],this[_0x865d('0x14')][_0x865d('0x11')][this[_0x865d('0xf')]['id']],_0x1dc022?'STOP':_0x865d('0x20'));}if(!_0x1dc022){setTimeout(this['push'][_0x865d('0x6')](this),0x3e8);}};function agent(_0x14d118,_0x1dfce8,_0x501e7e,_0x3ce807){return new Agent(_0x14d118,_0x1dfce8,_0x501e7e,_0x3ce807);}module['exports']=agent;