8134d2e7549f3b946476f7cc59e1c3e14de0b052
[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 _0xf5d8=['STOP','TIMEOUT','exports','uuid','./util','../../../../../config/logger','notificationId','squeue','agent','routing','handleRun','bind','handleTimeout','timeout','drained','handleDrained','push','prototype','[%s][AGENT]\x20try\x20with\x20%s','realtime','agents','info','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','channel','busyQueue','writeLog','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','isNil','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busy'];(function(_0x3db2d8,_0x3b5f84){var _0x49c2aa=function(_0x33138e){while(--_0x33138e){_0x3db2d8['push'](_0x3db2d8['shift']());}};_0x49c2aa(++_0x3b5f84);}(_0xf5d8,0xf1));var _0x8f5d=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xf5d8[_0x3dd15e];return _0x231fd0;};'use strict';var _=require('lodash');var uuid=require(_0x8f5d('0x0'));var util=require(_0x8f5d('0x1'));var logger=require(_0x8f5d('0x2'))('routing');var Agent=function(_0x49bca3,_0x4f7927,_0x276c67,_0x1e3db7){this[_0x8f5d('0x3')]=uuid['v4']();this[_0x8f5d('0x4')]=_0x49bca3;this[_0x8f5d('0x5')]=_0x4f7927;this['realtime']=_0x276c67;this[_0x8f5d('0x6')]=_0x1e3db7;this[_0x8f5d('0x4')]['push'](this[_0x8f5d('0x7')][_0x8f5d('0x8')](this),this[_0x8f5d('0x9')][_0x8f5d('0x8')](this));this['squeue']['on'](_0x8f5d('0xa'),this[_0x8f5d('0x9')][_0x8f5d('0x8')](this));this[_0x8f5d('0x4')]['on'](_0x8f5d('0xb'),this[_0x8f5d('0xc')][_0x8f5d('0x8')](this));};Agent['prototype'][_0x8f5d('0xd')]=function(){this['squeue']['push'](this[_0x8f5d('0x7')]['bind'](this),this[_0x8f5d('0x9')][_0x8f5d('0x8')](this));};Agent[_0x8f5d('0xe')][_0x8f5d('0xc')]=function(){this[_0x8f5d('0x9')](!![]);};Agent[_0x8f5d('0xe')][_0x8f5d('0x7')]=function(_0x50f01b){logger['info'](_0x8f5d('0xf'),this['squeue']['id'],this[_0x8f5d('0x5')]['id']);if(_['isNil'](this[_0x8f5d('0x10')][_0x8f5d('0x11')][this[_0x8f5d('0x5')]['id']])){logger[_0x8f5d('0x12')](_0x8f5d('0x13'),this['squeue']['id'],this[_0x8f5d('0x5')]['id']);setTimeout(this[_0x8f5d('0xd')][_0x8f5d('0x8')](this),0x3e8);}else{if(this[_0x8f5d('0x6')][_0x8f5d('0x14')]||util['isAgentAvailable'](this[_0x8f5d('0x4')]['id'],this[_0x8f5d('0x10')][_0x8f5d('0x11')][this[_0x8f5d('0x5')]['id']],this[_0x8f5d('0x4')][_0x8f5d('0x15')],![])){this['realtime']['agents'][this[_0x8f5d('0x5')]['id']]['busy']=!![];this['realtime']['agents'][this[_0x8f5d('0x5')]['id']][_0x8f5d('0x16')]=undefined;util['showNotification'](this[_0x8f5d('0x3')],this[_0x8f5d('0x4')]['id'],this['realtime']['agents'][this['agent']['id']],null,this[_0x8f5d('0x6')]);util[_0x8f5d('0x17')](this[_0x8f5d('0x4')]['id'],this['realtime']['agents'][this[_0x8f5d('0x5')]['id']],_0x8f5d('0x18')+(this[_0x8f5d('0x6')][_0x8f5d('0x14')]?_0x8f5d('0x19'):''));}else{logger[_0x8f5d('0x12')](_0x8f5d('0x1a'),this[_0x8f5d('0x4')]['id'],this[_0x8f5d('0x5')]['id']);setTimeout(this['push'][_0x8f5d('0x8')](this),0x3e8);}}};Agent['prototype']['handleTimeout']=function(_0x5abfd4){if(_[_0x8f5d('0x1b')](this['realtime'][_0x8f5d('0x11')][this[_0x8f5d('0x5')]['id']])){return logger[_0x8f5d('0x12')](_0x8f5d('0x13'),this[_0x8f5d('0x4')]['id'],this[_0x8f5d('0x5')]['id']);}else{logger[_0x8f5d('0x12')](_0x8f5d('0x1c'),this[_0x8f5d('0x4')]['id'],this[_0x8f5d('0x5')]['id']);util[_0x8f5d('0x1d')](this[_0x8f5d('0x3')],this[_0x8f5d('0x4')]['id'],this['realtime']['agents'][this[_0x8f5d('0x5')]['id']],null,this[_0x8f5d('0x6')]);this['realtime'][_0x8f5d('0x11')][this[_0x8f5d('0x5')]['id']][_0x8f5d('0x1e')]=![];this['realtime'][_0x8f5d('0x11')][this[_0x8f5d('0x5')]['id']]['busyQueue']=undefined;util[_0x8f5d('0x17')](this[_0x8f5d('0x4')]['id'],this[_0x8f5d('0x10')][_0x8f5d('0x11')][this[_0x8f5d('0x5')]['id']],_0x5abfd4?_0x8f5d('0x1f'):_0x8f5d('0x20'));}if(!_0x5abfd4){setTimeout(this[_0x8f5d('0xd')][_0x8f5d('0x8')](this),0x3e8);}};function agent(_0x259113,_0x58c977,_0x286251,_0x340d24){return new Agent(_0x259113,_0x58c977,_0x286251,_0x340d24);}module[_0x8f5d('0x21')]=agent;