2aa248b1ec746778e0d95e31d01178ebf5599f0d
[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 _0xca9e=['handleDrained','prototype','handleTimeout','[%s][AGENT]\x20try\x20with\x20%s','isNil','debug','forcedOwnership','isAgentAvailable','agents','channel','busyQueue','showNotification','writeLog','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','[%s][AGENT]\x20timeout\x20with\x20%s','busy','removeWaitingNotification','TIMEOUT','exports','lodash','uuid','./util','../../../../../config/logger','routing','notificationId','squeue','agent','realtime','push','handleRun','bind','timeout','drained'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xca9e,0x136));var _0xeca9=function(_0x4a4d1b,_0x371bc4){_0x4a4d1b=_0x4a4d1b-0x0;var _0x3486b3=_0xca9e[_0x4a4d1b];return _0x3486b3;};'use strict';var _=require(_0xeca9('0x0'));var uuid=require(_0xeca9('0x1'));var util=require(_0xeca9('0x2'));var logger=require(_0xeca9('0x3'))(_0xeca9('0x4'));var Agent=function(_0x1443e3,_0x8dbabb,_0x2c6185,_0x1b2864){this[_0xeca9('0x5')]=uuid['v4']();this[_0xeca9('0x6')]=_0x1443e3;this[_0xeca9('0x7')]=_0x8dbabb;this[_0xeca9('0x8')]=_0x2c6185;this[_0xeca9('0x4')]=_0x1b2864;this['squeue'][_0xeca9('0x9')](this[_0xeca9('0xa')]['bind'](this),this['handleTimeout'][_0xeca9('0xb')](this));this[_0xeca9('0x6')]['on'](_0xeca9('0xc'),this['handleTimeout'][_0xeca9('0xb')](this));this[_0xeca9('0x6')]['on'](_0xeca9('0xd'),this[_0xeca9('0xe')][_0xeca9('0xb')](this));};Agent[_0xeca9('0xf')]['push']=function(){this[_0xeca9('0x6')][_0xeca9('0x9')](this['handleRun'][_0xeca9('0xb')](this),this['handleTimeout'][_0xeca9('0xb')](this));};Agent[_0xeca9('0xf')]['handleDrained']=function(){this[_0xeca9('0x10')](!![]);};Agent[_0xeca9('0xf')][_0xeca9('0xa')]=function(){logger['debug'](_0xeca9('0x11'),this[_0xeca9('0x6')]['id'],this[_0xeca9('0x7')]['id']);if(_[_0xeca9('0x12')](this['realtime']['agents'][this[_0xeca9('0x7')]['id']])){logger[_0xeca9('0x13')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xeca9('0x6')]['id'],this[_0xeca9('0x7')]['id']);setTimeout(this['push']['bind'](this),0x3e8);}else{if(this['routing'][_0xeca9('0x14')]||util[_0xeca9('0x15')](this[_0xeca9('0x6')]['id'],this['realtime'][_0xeca9('0x16')][this['agent']['id']],this['squeue'][_0xeca9('0x17')],![])){this['realtime'][_0xeca9('0x16')][this[_0xeca9('0x7')]['id']]['busy']=!![];this[_0xeca9('0x8')][_0xeca9('0x16')][this['agent']['id']][_0xeca9('0x18')]=undefined;util['saveWaitingNotification'](this[_0xeca9('0x8')],this[_0xeca9('0x4')],this[_0xeca9('0x7')],this['squeue'][_0xeca9('0x17')]);util[_0xeca9('0x19')](this['notificationId'],this[_0xeca9('0x6')]['id'],this[_0xeca9('0x8')][_0xeca9('0x16')][this[_0xeca9('0x7')]['id']],null,this['routing']);util[_0xeca9('0x1a')](this['squeue']['id'],this[_0xeca9('0x8')][_0xeca9('0x16')][this[_0xeca9('0x7')]['id']],_0xeca9('0x1b')+(this[_0xeca9('0x4')][_0xeca9('0x14')]?_0xeca9('0x1c'):''));}else{logger[_0xeca9('0x13')](_0xeca9('0x1d'),this[_0xeca9('0x6')]['id'],this[_0xeca9('0x7')]['id']);setTimeout(this[_0xeca9('0x9')][_0xeca9('0xb')](this),0x3e8);}}};Agent[_0xeca9('0xf')][_0xeca9('0x10')]=function(_0x4910a3){if(_['isNil'](this['realtime'][_0xeca9('0x16')][this['agent']['id']])){return logger[_0xeca9('0x13')](_0xeca9('0x1e'),this[_0xeca9('0x6')]['id'],this[_0xeca9('0x7')]['id']);}else{logger[_0xeca9('0x13')](_0xeca9('0x1f'),this['squeue']['id'],this[_0xeca9('0x7')]['id']);util['hideNotification'](this[_0xeca9('0x5')],this[_0xeca9('0x6')]['id'],this[_0xeca9('0x8')]['agents'][this[_0xeca9('0x7')]['id']],null,this[_0xeca9('0x4')]);this[_0xeca9('0x8')][_0xeca9('0x16')][this['agent']['id']][_0xeca9('0x20')]=![];this['realtime'][_0xeca9('0x16')][this[_0xeca9('0x7')]['id']][_0xeca9('0x18')]=undefined;util[_0xeca9('0x21')](this[_0xeca9('0x8')],this[_0xeca9('0x4')],this['agent'],this[_0xeca9('0x6')][_0xeca9('0x17')]);util[_0xeca9('0x1a')](this[_0xeca9('0x6')]['id'],this[_0xeca9('0x8')][_0xeca9('0x16')][this[_0xeca9('0x7')]['id']],_0x4910a3?'STOP':_0xeca9('0x22'));}if(!_0x4910a3){setTimeout(this[_0xeca9('0x9')][_0xeca9('0xb')](this),0x3e8);}};function agent(_0x178bd4,_0x3995fd,_0x1eeb0a,_0x576463){return new Agent(_0x178bd4,_0x3995fd,_0x1eeb0a,_0x576463);}module[_0xeca9('0x23')]=agent;