Built motion from commit 0415ced0.|2.6.28
[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 _0xcb99=['busy','busyQueue','saveWaitingNotification','routing','writeLog','RINGING','forcedOwnership','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','removeWaitingNotification','TIMEOUT','lodash','./util','notificationId','squeue','realtime','push','handleRun','bind','handleTimeout','timeout','drained','handleDrained','prototype','debug','[%s][AGENT]\x20try\x20with\x20%s','agent','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','channel'];(function(_0x1a8be3,_0xa1d303){var _0xac9769=function(_0x3e5ccb){while(--_0x3e5ccb){_0x1a8be3['push'](_0x1a8be3['shift']());}};_0xac9769(++_0xa1d303);}(_0xcb99,0x8b));var _0x9cb9=function(_0x40b48b,_0x5c29e7){_0x40b48b=_0x40b48b-0x0;var _0x5cbd32=_0xcb99[_0x40b48b];return _0x5cbd32;};'use strict';var _=require(_0x9cb9('0x0'));var uuid=require('uuid');var util=require(_0x9cb9('0x1'));var logger=require('../../../../../config/logger')('routing');var Agent=function(_0x3a2f21,_0x1308a8,_0x124c48,_0x51f2ee){this[_0x9cb9('0x2')]=uuid['v4']();this[_0x9cb9('0x3')]=_0x3a2f21;this['agent']=_0x1308a8;this[_0x9cb9('0x4')]=_0x124c48;this['routing']=_0x51f2ee;this[_0x9cb9('0x3')][_0x9cb9('0x5')](this[_0x9cb9('0x6')][_0x9cb9('0x7')](this),this[_0x9cb9('0x8')][_0x9cb9('0x7')](this));this[_0x9cb9('0x3')]['on'](_0x9cb9('0x9'),this['handleTimeout']['bind'](this));this[_0x9cb9('0x3')]['on'](_0x9cb9('0xa'),this[_0x9cb9('0xb')]['bind'](this));};Agent[_0x9cb9('0xc')][_0x9cb9('0x5')]=function(){this['squeue']['push'](this[_0x9cb9('0x6')][_0x9cb9('0x7')](this),this[_0x9cb9('0x8')][_0x9cb9('0x7')](this));};Agent['prototype'][_0x9cb9('0xb')]=function(){this[_0x9cb9('0x8')](!![]);};Agent[_0x9cb9('0xc')][_0x9cb9('0x6')]=function(){logger[_0x9cb9('0xd')](_0x9cb9('0xe'),this[_0x9cb9('0x3')]['id'],this[_0x9cb9('0xf')]['id']);if(_[_0x9cb9('0x10')](this[_0x9cb9('0x4')][_0x9cb9('0x11')][this[_0x9cb9('0xf')]['id']])){logger[_0x9cb9('0xd')](_0x9cb9('0x12'),this[_0x9cb9('0x3')]['id'],this[_0x9cb9('0xf')]['id']);setTimeout(this[_0x9cb9('0x5')][_0x9cb9('0x7')](this),0x3e8);}else{if(this['routing']['forcedOwnership']||util[_0x9cb9('0x13')](this['squeue']['id'],this['realtime']['agents'][this[_0x9cb9('0xf')]['id']],this['squeue'][_0x9cb9('0x14')],![])){this[_0x9cb9('0x4')][_0x9cb9('0x11')][this[_0x9cb9('0xf')]['id']][_0x9cb9('0x15')]=!![];this[_0x9cb9('0x4')][_0x9cb9('0x11')][this[_0x9cb9('0xf')]['id']][_0x9cb9('0x16')]=undefined;util[_0x9cb9('0x17')](this[_0x9cb9('0x4')],this[_0x9cb9('0x18')],this[_0x9cb9('0xf')],this[_0x9cb9('0x3')]['channel']);util['showNotification'](this[_0x9cb9('0x2')],this[_0x9cb9('0x3')]['id'],this[_0x9cb9('0x4')][_0x9cb9('0x11')][this[_0x9cb9('0xf')]['id']],null,this[_0x9cb9('0x18')]);util[_0x9cb9('0x19')](this[_0x9cb9('0x3')]['id'],this[_0x9cb9('0x4')]['agents'][this[_0x9cb9('0xf')]['id']],_0x9cb9('0x1a')+(this[_0x9cb9('0x18')][_0x9cb9('0x1b')]?':FORCED':''));}else{logger[_0x9cb9('0xd')]('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0x9cb9('0x3')]['id'],this[_0x9cb9('0xf')]['id']);setTimeout(this[_0x9cb9('0x5')][_0x9cb9('0x7')](this),0x3e8);}}};Agent['prototype'][_0x9cb9('0x8')]=function(_0x3b7bba){if(_[_0x9cb9('0x10')](this['realtime'][_0x9cb9('0x11')][this['agent']['id']])){return logger[_0x9cb9('0xd')](_0x9cb9('0x12'),this[_0x9cb9('0x3')]['id'],this[_0x9cb9('0xf')]['id']);}else{logger[_0x9cb9('0xd')](_0x9cb9('0x1c'),this['squeue']['id'],this[_0x9cb9('0xf')]['id']);util[_0x9cb9('0x1d')](this[_0x9cb9('0x2')],this['squeue']['id'],this['realtime'][_0x9cb9('0x11')][this[_0x9cb9('0xf')]['id']],null,this[_0x9cb9('0x18')]);this['realtime']['agents'][this[_0x9cb9('0xf')]['id']][_0x9cb9('0x15')]=![];this['realtime'][_0x9cb9('0x11')][this[_0x9cb9('0xf')]['id']][_0x9cb9('0x16')]=undefined;util[_0x9cb9('0x1e')](this[_0x9cb9('0x4')],this['routing'],this[_0x9cb9('0xf')],this[_0x9cb9('0x3')]['channel']);util[_0x9cb9('0x19')](this['squeue']['id'],this[_0x9cb9('0x4')][_0x9cb9('0x11')][this['agent']['id']],_0x3b7bba?'STOP':_0x9cb9('0x1f'));}if(!_0x3b7bba){setTimeout(this[_0x9cb9('0x5')][_0x9cb9('0x7')](this),0x3e8);}};function agent(_0x2595f9,_0x448e2c,_0x2dd463,_0x10a355){return new Agent(_0x2595f9,_0x448e2c,_0x2dd463,_0x10a355);}module['exports']=agent;