63267bd9800464a064d1cb916ad4ea431e2d15d0
[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 _0x9a19=['prototype','push','handleRun','debug','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','channel','busyQueue','saveWaitingNotification','showNotification','writeLog','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','busy','removeWaitingNotification','STOP','TIMEOUT','exports','lodash','uuid','./util','routing','notificationId','squeue','agent','realtime','handleTimeout','bind','drained','handleDrained'];(function(_0x317785,_0x270bbf){var _0x34af80=function(_0x52d04a){while(--_0x52d04a){_0x317785['push'](_0x317785['shift']());}};_0x34af80(++_0x270bbf);}(_0x9a19,0x114));var _0x99a1=function(_0x60286b,_0x3247c1){_0x60286b=_0x60286b-0x0;var _0x5dff69=_0x9a19[_0x60286b];return _0x5dff69;};'use strict';var _=require(_0x99a1('0x0'));var uuid=require(_0x99a1('0x1'));var util=require(_0x99a1('0x2'));var logger=require('../../../../../config/logger')(_0x99a1('0x3'));var Agent=function(_0x2ba463,_0x112bcc,_0x25da2d,_0x214082){this[_0x99a1('0x4')]=uuid['v4']();this[_0x99a1('0x5')]=_0x2ba463;this[_0x99a1('0x6')]=_0x112bcc;this[_0x99a1('0x7')]=_0x25da2d;this[_0x99a1('0x3')]=_0x214082;this[_0x99a1('0x5')]['push'](this['handleRun']['bind'](this),this[_0x99a1('0x8')][_0x99a1('0x9')](this));this['squeue']['on']('timeout',this[_0x99a1('0x8')][_0x99a1('0x9')](this));this[_0x99a1('0x5')]['on'](_0x99a1('0xa'),this[_0x99a1('0xb')]['bind'](this));};Agent[_0x99a1('0xc')][_0x99a1('0xd')]=function(){this[_0x99a1('0x5')][_0x99a1('0xd')](this[_0x99a1('0xe')][_0x99a1('0x9')](this),this[_0x99a1('0x8')][_0x99a1('0x9')](this));};Agent[_0x99a1('0xc')][_0x99a1('0xb')]=function(){this[_0x99a1('0x8')](!![]);};Agent[_0x99a1('0xc')][_0x99a1('0xe')]=function(){logger[_0x99a1('0xf')](_0x99a1('0x10'),this['squeue']['id'],this[_0x99a1('0x6')]['id']);if(_[_0x99a1('0x11')](this[_0x99a1('0x7')][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']])){logger[_0x99a1('0xf')](_0x99a1('0x13'),this['squeue']['id'],this['agent']['id']);setTimeout(this[_0x99a1('0xd')][_0x99a1('0x9')](this),0x3e8);}else{if(this[_0x99a1('0x3')][_0x99a1('0x14')]||util[_0x99a1('0x15')](this[_0x99a1('0x5')]['id'],this[_0x99a1('0x7')][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']],this[_0x99a1('0x5')][_0x99a1('0x16')],![])){this['realtime'][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']]['busy']=!![];this[_0x99a1('0x7')]['agents'][this[_0x99a1('0x6')]['id']][_0x99a1('0x17')]=undefined;util[_0x99a1('0x18')](this[_0x99a1('0x7')],this['routing'],this[_0x99a1('0x6')],this[_0x99a1('0x5')]['channel']);util[_0x99a1('0x19')](this['notificationId'],this[_0x99a1('0x5')]['id'],this[_0x99a1('0x7')][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']],null,this[_0x99a1('0x3')]);util[_0x99a1('0x1a')](this['squeue']['id'],this[_0x99a1('0x7')]['agents'][this['agent']['id']],_0x99a1('0x1b')+(this[_0x99a1('0x3')][_0x99a1('0x14')]?_0x99a1('0x1c'):''));}else{logger[_0x99a1('0xf')](_0x99a1('0x1d'),this[_0x99a1('0x5')]['id'],this['agent']['id']);setTimeout(this[_0x99a1('0xd')]['bind'](this),0x3e8);}}};Agent[_0x99a1('0xc')][_0x99a1('0x8')]=function(_0x26fbae){if(_['isNil'](this[_0x99a1('0x7')][_0x99a1('0x12')][this['agent']['id']])){return logger[_0x99a1('0xf')](_0x99a1('0x13'),this[_0x99a1('0x5')]['id'],this[_0x99a1('0x6')]['id']);}else{logger[_0x99a1('0xf')](_0x99a1('0x1e'),this[_0x99a1('0x5')]['id'],this[_0x99a1('0x6')]['id']);util['hideNotification'](this['notificationId'],this[_0x99a1('0x5')]['id'],this['realtime'][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']],null,this['routing']);this[_0x99a1('0x7')][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']][_0x99a1('0x1f')]=![];this[_0x99a1('0x7')][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']][_0x99a1('0x17')]=undefined;util[_0x99a1('0x20')](this[_0x99a1('0x7')],this[_0x99a1('0x3')],this[_0x99a1('0x6')],this[_0x99a1('0x5')][_0x99a1('0x16')]);util['writeLog'](this['squeue']['id'],this[_0x99a1('0x7')][_0x99a1('0x12')][this[_0x99a1('0x6')]['id']],_0x26fbae?_0x99a1('0x21'):_0x99a1('0x22'));}if(!_0x26fbae){setTimeout(this[_0x99a1('0xd')][_0x99a1('0x9')](this),0x3e8);}};function agent(_0x54840d,_0x355f9d,_0x506613,_0x551d85){return new Agent(_0x54840d,_0x355f9d,_0x506613,_0x551d85);}module[_0x99a1('0x23')]=agent;