f576376e237f0f8aab015a86b172baabd3daeed2
[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 _0xcac8=['agent','realtime','push','handleRun','bind','handleTimeout','timeout','handleDrained','prototype','info','agents','channel','busy','busyQueue','showNotification','writeLog','RINGING','forcedOwnership','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','isNil','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','STOP','TIMEOUT','exports','lodash','uuid','routing','notificationId','squeue'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0xcac8,0x163));var _0x8cac=function(_0x4da191,_0x2062f1){_0x4da191=_0x4da191-0x0;var _0x53689f=_0xcac8[_0x4da191];return _0x53689f;};'use strict';var _=require(_0x8cac('0x0'));var uuid=require(_0x8cac('0x1'));var util=require('./util');var logger=require('../../../../../config/logger')(_0x8cac('0x2'));var Agent=function(_0x8a6db3,_0xf0da25,_0x193b30,_0x44796a){this[_0x8cac('0x3')]=uuid['v4']();this[_0x8cac('0x4')]=_0x8a6db3;this[_0x8cac('0x5')]=_0xf0da25;this[_0x8cac('0x6')]=_0x193b30;this[_0x8cac('0x2')]=_0x44796a;this[_0x8cac('0x4')][_0x8cac('0x7')](this[_0x8cac('0x8')][_0x8cac('0x9')](this),this[_0x8cac('0xa')][_0x8cac('0x9')](this));this[_0x8cac('0x4')]['on'](_0x8cac('0xb'),this['handleTimeout']['bind'](this));this[_0x8cac('0x4')]['on']('drained',this[_0x8cac('0xc')][_0x8cac('0x9')](this));};Agent['prototype'][_0x8cac('0x7')]=function(){this[_0x8cac('0x4')][_0x8cac('0x7')](this['handleRun'][_0x8cac('0x9')](this),this[_0x8cac('0xa')]['bind'](this));};Agent[_0x8cac('0xd')][_0x8cac('0xc')]=function(){this['handleTimeout'](!![]);};Agent[_0x8cac('0xd')][_0x8cac('0x8')]=function(_0x4d4765){logger['info']('[%s][AGENT]\x20try\x20with\x20%s',this[_0x8cac('0x4')]['id'],this[_0x8cac('0x5')]['id']);if(_['isNil'](this[_0x8cac('0x6')]['agents'][this[_0x8cac('0x5')]['id']])){logger[_0x8cac('0xe')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x8cac('0x4')]['id'],this[_0x8cac('0x5')]['id']);setTimeout(this['push'][_0x8cac('0x9')](this),0x3e8);}else{if(this[_0x8cac('0x2')]['forcedOwnership']||util['isAgentAvailable'](this[_0x8cac('0x4')]['id'],this[_0x8cac('0x6')][_0x8cac('0xf')][this['agent']['id']],this[_0x8cac('0x4')][_0x8cac('0x10')],![])){this['realtime'][_0x8cac('0xf')][this[_0x8cac('0x5')]['id']][_0x8cac('0x11')]=!![];this[_0x8cac('0x6')][_0x8cac('0xf')][this['agent']['id']][_0x8cac('0x12')]=undefined;util[_0x8cac('0x13')](this['notificationId'],this['squeue']['id'],this[_0x8cac('0x6')][_0x8cac('0xf')][this[_0x8cac('0x5')]['id']],null,this[_0x8cac('0x2')]);util[_0x8cac('0x14')](this[_0x8cac('0x4')]['id'],this['realtime'][_0x8cac('0xf')][this[_0x8cac('0x5')]['id']],_0x8cac('0x15')+(this['routing'][_0x8cac('0x16')]?':FORCED':''));}else{logger['info'](_0x8cac('0x17'),this[_0x8cac('0x4')]['id'],this[_0x8cac('0x5')]['id']);setTimeout(this[_0x8cac('0x7')]['bind'](this),0x3e8);}}};Agent['prototype'][_0x8cac('0xa')]=function(_0x1b04a7){if(_[_0x8cac('0x18')](this['realtime'][_0x8cac('0xf')][this[_0x8cac('0x5')]['id']])){return logger[_0x8cac('0xe')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],this[_0x8cac('0x5')]['id']);}else{logger[_0x8cac('0xe')](_0x8cac('0x19'),this[_0x8cac('0x4')]['id'],this[_0x8cac('0x5')]['id']);util[_0x8cac('0x1a')](this[_0x8cac('0x3')],this[_0x8cac('0x4')]['id'],this[_0x8cac('0x6')]['agents'][this[_0x8cac('0x5')]['id']],null,this[_0x8cac('0x2')]);this[_0x8cac('0x6')]['agents'][this[_0x8cac('0x5')]['id']][_0x8cac('0x11')]=![];this[_0x8cac('0x6')]['agents'][this['agent']['id']][_0x8cac('0x12')]=undefined;util['writeLog'](this[_0x8cac('0x4')]['id'],this['realtime']['agents'][this['agent']['id']],_0x1b04a7?_0x8cac('0x1b'):_0x8cac('0x1c'));}if(!_0x1b04a7){setTimeout(this[_0x8cac('0x7')]['bind'](this),0x3e8);}};function agent(_0xa1d666,_0x49f401,_0x3aa580,_0x440848){return new Agent(_0xa1d666,_0x49f401,_0x3aa580,_0x440848);}module[_0x8cac('0x1d')]=agent;