60e224452f12dce38f0ae3d3b410cca494a7f5bc
[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 _0xb62d=['prototype','agent','isNil','realtime','debug','forcedOwnership','agents','busy','busyQueue','showNotification','RINGING','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','writeLog','STOP','TIMEOUT','exports','lodash','uuid','./util','../../../../../config/logger','notificationId','routing','squeue','push','handleRun','bind','handleTimeout','timeout','drained','handleDrained'];(function(_0xefc063,_0x4adcba){var _0xa20bcf=function(_0x1c5bea){while(--_0x1c5bea){_0xefc063['push'](_0xefc063['shift']());}};_0xa20bcf(++_0x4adcba);}(_0xb62d,0x17e));var _0xdb62=function(_0x18be7d,_0x56ffc5){_0x18be7d=_0x18be7d-0x0;var _0x1ac672=_0xb62d[_0x18be7d];return _0x1ac672;};'use strict';var _=require(_0xdb62('0x0'));var uuid=require(_0xdb62('0x1'));var util=require(_0xdb62('0x2'));var logger=require(_0xdb62('0x3'))('routing');var Agent=function(_0xd0ab58,_0x37a40b,_0x38fe27,_0x4d8e4a){this[_0xdb62('0x4')]=uuid['v4']();this['squeue']=_0xd0ab58;this['agent']=_0x37a40b;this['realtime']=_0x38fe27;this[_0xdb62('0x5')]=_0x4d8e4a;this[_0xdb62('0x6')][_0xdb62('0x7')](this[_0xdb62('0x8')][_0xdb62('0x9')](this),this[_0xdb62('0xa')][_0xdb62('0x9')](this));this[_0xdb62('0x6')]['on'](_0xdb62('0xb'),this[_0xdb62('0xa')][_0xdb62('0x9')](this));this[_0xdb62('0x6')]['on'](_0xdb62('0xc'),this[_0xdb62('0xd')][_0xdb62('0x9')](this));};Agent[_0xdb62('0xe')][_0xdb62('0x7')]=function(){this['squeue'][_0xdb62('0x7')](this[_0xdb62('0x8')]['bind'](this),this[_0xdb62('0xa')]['bind'](this));};Agent[_0xdb62('0xe')][_0xdb62('0xd')]=function(){this['handleTimeout'](!![]);};Agent[_0xdb62('0xe')][_0xdb62('0x8')]=function(){logger['debug']('[%s][AGENT]\x20try\x20with\x20%s',this['squeue']['id'],this[_0xdb62('0xf')]['id']);if(_[_0xdb62('0x10')](this[_0xdb62('0x11')]['agents'][this['agent']['id']])){logger[_0xdb62('0x12')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xdb62('0x6')]['id'],this[_0xdb62('0xf')]['id']);setTimeout(this[_0xdb62('0x7')][_0xdb62('0x9')](this),0x3e8);}else{if(this[_0xdb62('0x5')][_0xdb62('0x13')]||util['isAgentAvailable'](this[_0xdb62('0x6')]['id'],this['realtime'][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']],this[_0xdb62('0x6')]['channel'],![])){this[_0xdb62('0x11')]['agents'][this[_0xdb62('0xf')]['id']][_0xdb62('0x15')]=!![];this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']][_0xdb62('0x16')]=undefined;util[_0xdb62('0x17')](this['notificationId'],this[_0xdb62('0x6')]['id'],this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']],null,this[_0xdb62('0x5')]);util['writeLog'](this['squeue']['id'],this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']],_0xdb62('0x18')+(this[_0xdb62('0x5')]['forcedOwnership']?':FORCED':''));}else{logger[_0xdb62('0x12')](_0xdb62('0x19'),this[_0xdb62('0x6')]['id'],this['agent']['id']);setTimeout(this[_0xdb62('0x7')][_0xdb62('0x9')](this),0x3e8);}}};Agent['prototype'][_0xdb62('0xa')]=function(_0xfea23b){if(_[_0xdb62('0x10')](this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']])){return logger[_0xdb62('0x12')](_0xdb62('0x1a'),this['squeue']['id'],this[_0xdb62('0xf')]['id']);}else{logger[_0xdb62('0x12')](_0xdb62('0x1b'),this[_0xdb62('0x6')]['id'],this[_0xdb62('0xf')]['id']);util[_0xdb62('0x1c')](this[_0xdb62('0x4')],this[_0xdb62('0x6')]['id'],this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']],null,this['routing']);this[_0xdb62('0x11')][_0xdb62('0x14')][this['agent']['id']][_0xdb62('0x15')]=![];this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']]['busyQueue']=undefined;util[_0xdb62('0x1d')](this['squeue']['id'],this[_0xdb62('0x11')][_0xdb62('0x14')][this[_0xdb62('0xf')]['id']],_0xfea23b?_0xdb62('0x1e'):_0xdb62('0x1f'));}if(!_0xfea23b){setTimeout(this['push'][_0xdb62('0x9')](this),0x3e8);}};function agent(_0x307691,_0x4b9347,_0x54c433,_0xbc9103){return new Agent(_0x307691,_0x4b9347,_0x54c433,_0xbc9103);}module[_0xdb62('0x20')]=agent;