fd2ccda60089bcb1d9aae60d4ef54f6148b5f7c6
[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 _0xbd50=['isNil','agents','agent','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','channel','busyQueue','saveWaitingNotification','notificationId','RINGING',':FORCED','debug','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busy','removeWaitingNotification','STOP','TIMEOUT','exports','lodash','uuid','./util','routing','realtime','squeue','push','handleRun','bind','timeout','handleDrained','handleTimeout','prototype','[%s][AGENT]\x20try\x20with\x20%s'];(function(_0x42cb30,_0x30ac13){var _0x2d886b=function(_0x42d9d4){while(--_0x42d9d4){_0x42cb30['push'](_0x42cb30['shift']());}};_0x2d886b(++_0x30ac13);}(_0xbd50,0x196));var _0x0bd5=function(_0x40df07,_0x2392d2){_0x40df07=_0x40df07-0x0;var _0x2050fe=_0xbd50[_0x40df07];return _0x2050fe;};'use strict';var _=require(_0x0bd5('0x0'));var uuid=require(_0x0bd5('0x1'));var util=require(_0x0bd5('0x2'));var logger=require('../../../../../config/logger')(_0x0bd5('0x3'));var Agent=function(_0x167372,_0x37acba,_0x1e9877,_0x15620d){this['notificationId']=uuid['v4']();this['squeue']=_0x167372;this['agent']=_0x37acba;this[_0x0bd5('0x4')]=_0x1e9877;this[_0x0bd5('0x3')]=_0x15620d;this[_0x0bd5('0x5')][_0x0bd5('0x6')](this[_0x0bd5('0x7')]['bind'](this),this['handleTimeout'][_0x0bd5('0x8')](this));this[_0x0bd5('0x5')]['on'](_0x0bd5('0x9'),this['handleTimeout'][_0x0bd5('0x8')](this));this[_0x0bd5('0x5')]['on']('drained',this[_0x0bd5('0xa')][_0x0bd5('0x8')](this));};Agent['prototype'][_0x0bd5('0x6')]=function(){this[_0x0bd5('0x5')][_0x0bd5('0x6')](this['handleRun'][_0x0bd5('0x8')](this),this[_0x0bd5('0xb')][_0x0bd5('0x8')](this));};Agent[_0x0bd5('0xc')][_0x0bd5('0xa')]=function(){this[_0x0bd5('0xb')](!![]);};Agent[_0x0bd5('0xc')][_0x0bd5('0x7')]=function(){logger['debug'](_0x0bd5('0xd'),this[_0x0bd5('0x5')]['id'],this['agent']['id']);if(_[_0x0bd5('0xe')](this[_0x0bd5('0x4')][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']])){logger['debug'](_0x0bd5('0x11'),this[_0x0bd5('0x5')]['id'],this[_0x0bd5('0x10')]['id']);setTimeout(this[_0x0bd5('0x6')][_0x0bd5('0x8')](this),0x3e8);}else{if(this[_0x0bd5('0x3')][_0x0bd5('0x12')]||util[_0x0bd5('0x13')](this[_0x0bd5('0x5')]['id'],this[_0x0bd5('0x4')][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']],this[_0x0bd5('0x5')][_0x0bd5('0x14')],![])){this['realtime']['agents'][this['agent']['id']]['busy']=!![];this['realtime'][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']][_0x0bd5('0x15')]=undefined;util[_0x0bd5('0x16')](this[_0x0bd5('0x4')],this['routing'],this[_0x0bd5('0x10')],this[_0x0bd5('0x5')][_0x0bd5('0x14')]);util['showNotification'](this[_0x0bd5('0x17')],this['squeue']['id'],this['realtime'][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']],null,this[_0x0bd5('0x3')]);util['writeLog'](this[_0x0bd5('0x5')]['id'],this['realtime'][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']],_0x0bd5('0x18')+(this[_0x0bd5('0x3')][_0x0bd5('0x12')]?_0x0bd5('0x19'):''));}else{logger[_0x0bd5('0x1a')](_0x0bd5('0x1b'),this[_0x0bd5('0x5')]['id'],this[_0x0bd5('0x10')]['id']);setTimeout(this[_0x0bd5('0x6')][_0x0bd5('0x8')](this),0x3e8);}}};Agent[_0x0bd5('0xc')][_0x0bd5('0xb')]=function(_0x5e5a33){if(_[_0x0bd5('0xe')](this[_0x0bd5('0x4')]['agents'][this[_0x0bd5('0x10')]['id']])){return logger[_0x0bd5('0x1a')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x0bd5('0x5')]['id'],this[_0x0bd5('0x10')]['id']);}else{logger[_0x0bd5('0x1a')](_0x0bd5('0x1c'),this['squeue']['id'],this[_0x0bd5('0x10')]['id']);util[_0x0bd5('0x1d')](this[_0x0bd5('0x17')],this[_0x0bd5('0x5')]['id'],this[_0x0bd5('0x4')][_0x0bd5('0xf')][this['agent']['id']],null,this[_0x0bd5('0x3')]);this['realtime'][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']][_0x0bd5('0x1e')]=![];this[_0x0bd5('0x4')][_0x0bd5('0xf')][this[_0x0bd5('0x10')]['id']][_0x0bd5('0x15')]=undefined;util[_0x0bd5('0x1f')](this[_0x0bd5('0x4')],this[_0x0bd5('0x3')],this[_0x0bd5('0x10')],this[_0x0bd5('0x5')][_0x0bd5('0x14')]);util['writeLog'](this[_0x0bd5('0x5')]['id'],this[_0x0bd5('0x4')]['agents'][this['agent']['id']],_0x5e5a33?_0x0bd5('0x20'):_0x0bd5('0x21'));}if(!_0x5e5a33){setTimeout(this[_0x0bd5('0x6')][_0x0bd5('0x8')](this),0x3e8);}};function agent(_0x1dd2e1,_0x387e24,_0x22c10c,_0x1a0c0c){return new Agent(_0x1dd2e1,_0x387e24,_0x22c10c,_0x1a0c0c);}module[_0x0bd5('0x22')]=agent;