1e2e1ea98cbba355fa6189004e32b1c405443abe
[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 _0x1553=['routing','notificationId','squeue','agent','realtime','push','handleRun','bind','timeout','handleTimeout','drained','prototype','handleDrained','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','forcedOwnership','channel','busy','busyQueue','showNotification','writeLog','RINGING',':FORCED','debug','hideNotification','TIMEOUT','exports','uuid','./util','../../../../../config/logger'];(function(_0x152121,_0x120c53){var _0x592a85=function(_0x241cab){while(--_0x241cab){_0x152121['push'](_0x152121['shift']());}};_0x592a85(++_0x120c53);}(_0x1553,0x133));var _0x3155=function(_0x50d2db,_0x47481f){_0x50d2db=_0x50d2db-0x0;var _0x1c7e27=_0x1553[_0x50d2db];return _0x1c7e27;};'use strict';var _=require('lodash');var uuid=require(_0x3155('0x0'));var util=require(_0x3155('0x1'));var logger=require(_0x3155('0x2'))(_0x3155('0x3'));var Agent=function(_0x2241cc,_0x1c3340,_0x2c3fc8,_0x14f207){this[_0x3155('0x4')]=uuid['v4']();this[_0x3155('0x5')]=_0x2241cc;this[_0x3155('0x6')]=_0x1c3340;this[_0x3155('0x7')]=_0x2c3fc8;this[_0x3155('0x3')]=_0x14f207;this[_0x3155('0x5')][_0x3155('0x8')](this[_0x3155('0x9')][_0x3155('0xa')](this),this['handleTimeout']['bind'](this));this[_0x3155('0x5')]['on'](_0x3155('0xb'),this[_0x3155('0xc')][_0x3155('0xa')](this));this[_0x3155('0x5')]['on'](_0x3155('0xd'),this['handleDrained'][_0x3155('0xa')](this));};Agent[_0x3155('0xe')][_0x3155('0x8')]=function(){this[_0x3155('0x5')][_0x3155('0x8')](this['handleRun'][_0x3155('0xa')](this),this['handleTimeout']['bind'](this));};Agent[_0x3155('0xe')][_0x3155('0xf')]=function(){this[_0x3155('0xc')](!![]);};Agent[_0x3155('0xe')][_0x3155('0x9')]=function(){logger['debug'](_0x3155('0x10'),this[_0x3155('0x5')]['id'],this['agent']['id']);if(_[_0x3155('0x11')](this[_0x3155('0x7')][_0x3155('0x12')][this[_0x3155('0x6')]['id']])){logger['debug']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x3155('0x5')]['id'],this[_0x3155('0x6')]['id']);setTimeout(this[_0x3155('0x8')]['bind'](this),0x3e8);}else{if(this[_0x3155('0x3')][_0x3155('0x13')]||util['isAgentAvailable'](this['squeue']['id'],this[_0x3155('0x7')][_0x3155('0x12')][this[_0x3155('0x6')]['id']],this[_0x3155('0x5')][_0x3155('0x14')],![])){this['realtime'][_0x3155('0x12')][this[_0x3155('0x6')]['id']][_0x3155('0x15')]=!![];this['realtime'][_0x3155('0x12')][this[_0x3155('0x6')]['id']][_0x3155('0x16')]=undefined;util[_0x3155('0x17')](this[_0x3155('0x4')],this['squeue']['id'],this[_0x3155('0x7')][_0x3155('0x12')][this[_0x3155('0x6')]['id']],null,this[_0x3155('0x3')]);util[_0x3155('0x18')](this[_0x3155('0x5')]['id'],this[_0x3155('0x7')]['agents'][this[_0x3155('0x6')]['id']],_0x3155('0x19')+(this[_0x3155('0x3')][_0x3155('0x13')]?_0x3155('0x1a'):''));}else{logger[_0x3155('0x1b')]('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0x3155('0x5')]['id'],this[_0x3155('0x6')]['id']);setTimeout(this['push']['bind'](this),0x3e8);}}};Agent[_0x3155('0xe')][_0x3155('0xc')]=function(_0xcd32d){if(_[_0x3155('0x11')](this[_0x3155('0x7')][_0x3155('0x12')][this[_0x3155('0x6')]['id']])){return logger[_0x3155('0x1b')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x3155('0x5')]['id'],this[_0x3155('0x6')]['id']);}else{logger[_0x3155('0x1b')]('[%s][AGENT]\x20timeout\x20with\x20%s',this['squeue']['id'],this['agent']['id']);util[_0x3155('0x1c')](this[_0x3155('0x4')],this[_0x3155('0x5')]['id'],this[_0x3155('0x7')][_0x3155('0x12')][this[_0x3155('0x6')]['id']],null,this[_0x3155('0x3')]);this['realtime'][_0x3155('0x12')][this[_0x3155('0x6')]['id']][_0x3155('0x15')]=![];this[_0x3155('0x7')]['agents'][this[_0x3155('0x6')]['id']]['busyQueue']=undefined;util[_0x3155('0x18')](this[_0x3155('0x5')]['id'],this[_0x3155('0x7')][_0x3155('0x12')][this[_0x3155('0x6')]['id']],_0xcd32d?'STOP':_0x3155('0x1d'));}if(!_0xcd32d){setTimeout(this['push']['bind'](this),0x3e8);}};function agent(_0x463084,_0x1a3597,_0x4c1208,_0x3521a6){return new Agent(_0x463084,_0x1a3597,_0x4c1208,_0x3521a6);}module[_0x3155('0x1e')]=agent;