56c7e7b1e9897ff8351cf9ee5954551db43fd4d4
[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 _0x6ac8=['realtime','handleTimeout','bind','timeout','drained','handleDrained','prototype','push','handleRun','info','[%s][AGENT]\x20try\x20with\x20%s','agent','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','channel','busy','busyQueue','writeLog','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','hideNotification','STOP','exports','uuid','./util','../../../../../config/logger','routing','notificationId','squeue'];(function(_0x5b62d4,_0x33323f){var _0x10f496=function(_0x557f12){while(--_0x557f12){_0x5b62d4['push'](_0x5b62d4['shift']());}};_0x10f496(++_0x33323f);}(_0x6ac8,0x9a));var _0x86ac=function(_0x6c993a,_0x5ea3ab){_0x6c993a=_0x6c993a-0x0;var _0x27f547=_0x6ac8[_0x6c993a];return _0x27f547;};'use strict';var _=require('lodash');var uuid=require(_0x86ac('0x0'));var util=require(_0x86ac('0x1'));var logger=require(_0x86ac('0x2'))(_0x86ac('0x3'));var Agent=function(_0x95ddf6,_0x51bf04,_0x3722dc,_0x230432){this[_0x86ac('0x4')]=uuid['v4']();this[_0x86ac('0x5')]=_0x95ddf6;this['agent']=_0x51bf04;this[_0x86ac('0x6')]=_0x3722dc;this['routing']=_0x230432;this['squeue']['push'](this['handleRun']['bind'](this),this[_0x86ac('0x7')][_0x86ac('0x8')](this));this[_0x86ac('0x5')]['on'](_0x86ac('0x9'),this[_0x86ac('0x7')][_0x86ac('0x8')](this));this[_0x86ac('0x5')]['on'](_0x86ac('0xa'),this[_0x86ac('0xb')]['bind'](this));};Agent[_0x86ac('0xc')][_0x86ac('0xd')]=function(){this[_0x86ac('0x5')][_0x86ac('0xd')](this[_0x86ac('0xe')][_0x86ac('0x8')](this),this[_0x86ac('0x7')][_0x86ac('0x8')](this));};Agent[_0x86ac('0xc')][_0x86ac('0xb')]=function(){this[_0x86ac('0x7')](!![]);};Agent[_0x86ac('0xc')]['handleRun']=function(_0x3afe94){logger[_0x86ac('0xf')](_0x86ac('0x10'),this[_0x86ac('0x5')]['id'],this[_0x86ac('0x11')]['id']);if(_[_0x86ac('0x12')](this[_0x86ac('0x6')][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']])){logger[_0x86ac('0xf')](_0x86ac('0x14'),this['squeue']['id'],this[_0x86ac('0x11')]['id']);setTimeout(this[_0x86ac('0xd')][_0x86ac('0x8')](this),0x3e8);}else{if(this[_0x86ac('0x3')][_0x86ac('0x15')]||util['isAgentAvailable'](this[_0x86ac('0x5')]['id'],this[_0x86ac('0x6')][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']],this[_0x86ac('0x5')][_0x86ac('0x16')],![])){this['realtime'][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']][_0x86ac('0x17')]=!![];this['realtime'][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']][_0x86ac('0x18')]=undefined;util['showNotification'](this['notificationId'],this[_0x86ac('0x5')]['id'],this[_0x86ac('0x6')][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']],null,this[_0x86ac('0x3')]);util[_0x86ac('0x19')](this['squeue']['id'],this[_0x86ac('0x6')][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']],_0x86ac('0x1a')+(this['routing'][_0x86ac('0x15')]?_0x86ac('0x1b'):''));}else{logger['info'](_0x86ac('0x1c'),this['squeue']['id'],this[_0x86ac('0x11')]['id']);setTimeout(this['push'][_0x86ac('0x8')](this),0x3e8);}}};Agent[_0x86ac('0xc')][_0x86ac('0x7')]=function(_0xee39eb){if(_[_0x86ac('0x12')](this[_0x86ac('0x6')]['agents'][this[_0x86ac('0x11')]['id']])){return logger['info']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x86ac('0x5')]['id'],this[_0x86ac('0x11')]['id']);}else{logger[_0x86ac('0xf')]('[%s][AGENT]\x20timeout\x20with\x20%s',this[_0x86ac('0x5')]['id'],this[_0x86ac('0x11')]['id']);util[_0x86ac('0x1d')](this[_0x86ac('0x4')],this['squeue']['id'],this[_0x86ac('0x6')][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']],null,this[_0x86ac('0x3')]);this[_0x86ac('0x6')]['agents'][this[_0x86ac('0x11')]['id']][_0x86ac('0x17')]=![];this[_0x86ac('0x6')][_0x86ac('0x13')][this[_0x86ac('0x11')]['id']][_0x86ac('0x18')]=undefined;util[_0x86ac('0x19')](this[_0x86ac('0x5')]['id'],this[_0x86ac('0x6')][_0x86ac('0x13')][this['agent']['id']],_0xee39eb?_0x86ac('0x1e'):'TIMEOUT');}if(!_0xee39eb){setTimeout(this[_0x86ac('0xd')][_0x86ac('0x8')](this),0x3e8);}};function agent(_0x3e9f5b,_0x1e4031,_0x566329,_0x4727e0){return new Agent(_0x3e9f5b,_0x1e4031,_0x566329,_0x4727e0);}module[_0x86ac('0x1f')]=agent;