beb29f5cb8ca98830ca5abcbe7d552d11b7015cb
[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 _0x6553=[':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','hideNotification','busyQueue','STOP','exports','lodash','uuid','./util','../../../../../config/logger','agent','squeue','push','handleRun','timeout','handleTimeout','bind','drained','handleDrained','prototype','info','[%s][AGENT]\x20try\x20with\x20%s','isNil','realtime','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','routing','forcedOwnership','isAgentAvailable','showNotification','notificationId','writeLog'];(function(_0xb24a3e,_0x4a3594){var _0x4038d7=function(_0x1ea3c3){while(--_0x1ea3c3){_0xb24a3e['push'](_0xb24a3e['shift']());}};_0x4038d7(++_0x4a3594);}(_0x6553,0xe6));var _0x3655=function(_0x5b644e,_0x2e5e07){_0x5b644e=_0x5b644e-0x0;var _0x49c6bf=_0x6553[_0x5b644e];return _0x49c6bf;};'use strict';var _=require(_0x3655('0x0'));var uuid=require(_0x3655('0x1'));var util=require(_0x3655('0x2'));var logger=require(_0x3655('0x3'))('routing');var Agent=function(_0x1529b5,_0xb6d004,_0x53c806,_0xce066b){this['notificationId']=uuid['v4']();this['squeue']=_0x1529b5;this[_0x3655('0x4')]=_0xb6d004;this['realtime']=_0x53c806;this['routing']=_0xce066b;this[_0x3655('0x5')][_0x3655('0x6')](this[_0x3655('0x7')]['bind'](this),this['handleTimeout']['bind'](this));this[_0x3655('0x5')]['on'](_0x3655('0x8'),this[_0x3655('0x9')][_0x3655('0xa')](this));this['squeue']['on'](_0x3655('0xb'),this[_0x3655('0xc')][_0x3655('0xa')](this));};Agent[_0x3655('0xd')][_0x3655('0x6')]=function(){this[_0x3655('0x5')][_0x3655('0x6')](this[_0x3655('0x7')][_0x3655('0xa')](this),this[_0x3655('0x9')]['bind'](this));};Agent[_0x3655('0xd')][_0x3655('0xc')]=function(){this[_0x3655('0x9')](!![]);};Agent[_0x3655('0xd')][_0x3655('0x7')]=function(_0x17e2af){logger[_0x3655('0xe')](_0x3655('0xf'),this[_0x3655('0x5')]['id'],this['agent']['id']);if(_[_0x3655('0x10')](this[_0x3655('0x11')][_0x3655('0x12')][this[_0x3655('0x4')]['id']])){logger[_0x3655('0xe')](_0x3655('0x13'),this['squeue']['id'],this[_0x3655('0x4')]['id']);setTimeout(this['push'][_0x3655('0xa')](this),0x3e8);}else{if(this[_0x3655('0x14')][_0x3655('0x15')]||util[_0x3655('0x16')](this['squeue']['id'],this['realtime']['agents'][this[_0x3655('0x4')]['id']],this[_0x3655('0x5')]['channel'],![])){this['realtime'][_0x3655('0x12')][this['agent']['id']]['busy']=!![];this['realtime']['agents'][this[_0x3655('0x4')]['id']]['busyQueue']=undefined;util[_0x3655('0x17')](this[_0x3655('0x18')],this[_0x3655('0x5')]['id'],this[_0x3655('0x11')][_0x3655('0x12')][this['agent']['id']],null,this['routing']);util[_0x3655('0x19')](this[_0x3655('0x5')]['id'],this[_0x3655('0x11')]['agents'][this[_0x3655('0x4')]['id']],'RINGING'+(this['routing'][_0x3655('0x15')]?_0x3655('0x1a'):''));}else{logger['info'](_0x3655('0x1b'),this[_0x3655('0x5')]['id'],this['agent']['id']);setTimeout(this[_0x3655('0x6')][_0x3655('0xa')](this),0x3e8);}}};Agent['prototype'][_0x3655('0x9')]=function(_0x3b4f09){if(_[_0x3655('0x10')](this[_0x3655('0x11')][_0x3655('0x12')][this[_0x3655('0x4')]['id']])){return logger[_0x3655('0xe')](_0x3655('0x13'),this['squeue']['id'],this[_0x3655('0x4')]['id']);}else{logger[_0x3655('0xe')]('[%s][AGENT]\x20timeout\x20with\x20%s',this[_0x3655('0x5')]['id'],this[_0x3655('0x4')]['id']);util[_0x3655('0x1c')](this[_0x3655('0x18')],this[_0x3655('0x5')]['id'],this['realtime'][_0x3655('0x12')][this[_0x3655('0x4')]['id']],null,this['routing']);this[_0x3655('0x11')][_0x3655('0x12')][this['agent']['id']]['busy']=![];this[_0x3655('0x11')][_0x3655('0x12')][this[_0x3655('0x4')]['id']][_0x3655('0x1d')]=undefined;util['writeLog'](this[_0x3655('0x5')]['id'],this[_0x3655('0x11')][_0x3655('0x12')][this[_0x3655('0x4')]['id']],_0x3b4f09?_0x3655('0x1e'):'TIMEOUT');}if(!_0x3b4f09){setTimeout(this[_0x3655('0x6')][_0x3655('0xa')](this),0x3e8);}};function agent(_0x1f7d01,_0x262621,_0x518c47,_0x17ed45){return new Agent(_0x1f7d01,_0x262621,_0x518c47,_0x17ed45);}module[_0x3655('0x1f')]=agent;