1483068263c98053e2025fe16f9dc258d2c9e93c
[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 _0xee14=['RINGING',':FORCED','isNil','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','removeWaitingNotification','STOP','TIMEOUT','./util','../../../../../config/logger','routing','notificationId','squeue','realtime','push','handleRun','bind','handleTimeout','timeout','drained','handleDrained','prototype','debug','[%s][AGENT]\x20try\x20with\x20%s','agent','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','channel','busy','busyQueue','saveWaitingNotification','showNotification','writeLog'];(function(_0x22816c,_0x4e43d){var _0x81784a=function(_0x4deef3){while(--_0x4deef3){_0x22816c['push'](_0x22816c['shift']());}};_0x81784a(++_0x4e43d);}(_0xee14,0x13a));var _0x4ee1=function(_0x3f10a7,_0x3ad9c5){_0x3f10a7=_0x3f10a7-0x0;var _0x1506b5=_0xee14[_0x3f10a7];return _0x1506b5;};'use strict';var _=require('lodash');var uuid=require('uuid');var util=require(_0x4ee1('0x0'));var logger=require(_0x4ee1('0x1'))(_0x4ee1('0x2'));var Agent=function(_0x1fa407,_0x18e3c4,_0x236ccd,_0x34a0ae){this[_0x4ee1('0x3')]=uuid['v4']();this[_0x4ee1('0x4')]=_0x1fa407;this['agent']=_0x18e3c4;this[_0x4ee1('0x5')]=_0x236ccd;this['routing']=_0x34a0ae;this[_0x4ee1('0x4')][_0x4ee1('0x6')](this[_0x4ee1('0x7')][_0x4ee1('0x8')](this),this[_0x4ee1('0x9')][_0x4ee1('0x8')](this));this['squeue']['on'](_0x4ee1('0xa'),this[_0x4ee1('0x9')]['bind'](this));this[_0x4ee1('0x4')]['on'](_0x4ee1('0xb'),this[_0x4ee1('0xc')][_0x4ee1('0x8')](this));};Agent['prototype'][_0x4ee1('0x6')]=function(){this[_0x4ee1('0x4')][_0x4ee1('0x6')](this[_0x4ee1('0x7')][_0x4ee1('0x8')](this),this[_0x4ee1('0x9')]['bind'](this));};Agent[_0x4ee1('0xd')][_0x4ee1('0xc')]=function(){this[_0x4ee1('0x9')](!![]);};Agent[_0x4ee1('0xd')][_0x4ee1('0x7')]=function(){logger[_0x4ee1('0xe')](_0x4ee1('0xf'),this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x10')]['id']);if(_['isNil'](this[_0x4ee1('0x5')][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']])){logger[_0x4ee1('0xe')](_0x4ee1('0x12'),this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x10')]['id']);setTimeout(this[_0x4ee1('0x6')][_0x4ee1('0x8')](this),0x3e8);}else{if(this[_0x4ee1('0x2')][_0x4ee1('0x13')]||util['isAgentAvailable'](this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x5')][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']],this[_0x4ee1('0x4')][_0x4ee1('0x14')],![])){this['realtime'][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']][_0x4ee1('0x15')]=!![];this[_0x4ee1('0x5')][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']][_0x4ee1('0x16')]=undefined;util[_0x4ee1('0x17')](this[_0x4ee1('0x5')],this[_0x4ee1('0x2')],this['agent'],this['squeue'][_0x4ee1('0x14')]);util[_0x4ee1('0x18')](this[_0x4ee1('0x3')],this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x5')][_0x4ee1('0x11')][this['agent']['id']],null,this['routing']);util[_0x4ee1('0x19')](this[_0x4ee1('0x4')]['id'],this['realtime'][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']],_0x4ee1('0x1a')+(this[_0x4ee1('0x2')][_0x4ee1('0x13')]?_0x4ee1('0x1b'):''));}else{logger[_0x4ee1('0xe')]('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0x4ee1('0x4')]['id'],this['agent']['id']);setTimeout(this[_0x4ee1('0x6')]['bind'](this),0x3e8);}}};Agent[_0x4ee1('0xd')][_0x4ee1('0x9')]=function(_0x59a34e){if(_[_0x4ee1('0x1c')](this[_0x4ee1('0x5')]['agents'][this[_0x4ee1('0x10')]['id']])){return logger['debug'](_0x4ee1('0x12'),this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x10')]['id']);}else{logger[_0x4ee1('0xe')](_0x4ee1('0x1d'),this['squeue']['id'],this[_0x4ee1('0x10')]['id']);util[_0x4ee1('0x1e')](this[_0x4ee1('0x3')],this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x5')][_0x4ee1('0x11')][this['agent']['id']],null,this['routing']);this[_0x4ee1('0x5')][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']]['busy']=![];this[_0x4ee1('0x5')][_0x4ee1('0x11')][this[_0x4ee1('0x10')]['id']][_0x4ee1('0x16')]=undefined;util[_0x4ee1('0x1f')](this[_0x4ee1('0x5')],this[_0x4ee1('0x2')],this[_0x4ee1('0x10')],this[_0x4ee1('0x4')][_0x4ee1('0x14')]);util[_0x4ee1('0x19')](this[_0x4ee1('0x4')]['id'],this[_0x4ee1('0x5')]['agents'][this[_0x4ee1('0x10')]['id']],_0x59a34e?_0x4ee1('0x20'):_0x4ee1('0x21'));}if(!_0x59a34e){setTimeout(this['push']['bind'](this),0x3e8);}};function agent(_0x257f67,_0x84480e,_0x74e6e2,_0x1f2b4b){return new Agent(_0x257f67,_0x84480e,_0x74e6e2,_0x1f2b4b);}module['exports']=agent;