7eb3b5a409e944d285354e7bbf719e775dbbec81
[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 _0xcca7=['busy','busyQueue','saveWaitingNotification','showNotification','writeLog','RINGING','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','hideNotification','TIMEOUT','exports','lodash','uuid','./util','../../../../../config/logger','notificationId','squeue','agent','realtime','routing','handleRun','bind','handleTimeout','timeout','drained','prototype','push','debug','[%s][AGENT]\x20try\x20with\x20%s','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','agents','channel'];(function(_0x1e34a3,_0x551bbe){var _0xda5e49=function(_0x2abb4a){while(--_0x2abb4a){_0x1e34a3['push'](_0x1e34a3['shift']());}};_0xda5e49(++_0x551bbe);}(_0xcca7,0x1aa));var _0x7cca=function(_0x4d9b1f,_0x30d7ee){_0x4d9b1f=_0x4d9b1f-0x0;var _0xa0d1c6=_0xcca7[_0x4d9b1f];return _0xa0d1c6;};'use strict';var _=require(_0x7cca('0x0'));var uuid=require(_0x7cca('0x1'));var util=require(_0x7cca('0x2'));var logger=require(_0x7cca('0x3'))('routing');var Agent=function(_0x4c311e,_0x30823f,_0x533b00,_0x3b86a4){this[_0x7cca('0x4')]=uuid['v4']();this[_0x7cca('0x5')]=_0x4c311e;this[_0x7cca('0x6')]=_0x30823f;this[_0x7cca('0x7')]=_0x533b00;this[_0x7cca('0x8')]=_0x3b86a4;this['squeue']['push'](this[_0x7cca('0x9')][_0x7cca('0xa')](this),this[_0x7cca('0xb')][_0x7cca('0xa')](this));this[_0x7cca('0x5')]['on'](_0x7cca('0xc'),this[_0x7cca('0xb')][_0x7cca('0xa')](this));this[_0x7cca('0x5')]['on'](_0x7cca('0xd'),this['handleDrained'][_0x7cca('0xa')](this));};Agent[_0x7cca('0xe')][_0x7cca('0xf')]=function(){this[_0x7cca('0x5')][_0x7cca('0xf')](this['handleRun'][_0x7cca('0xa')](this),this[_0x7cca('0xb')][_0x7cca('0xa')](this));};Agent['prototype']['handleDrained']=function(){this[_0x7cca('0xb')](!![]);};Agent[_0x7cca('0xe')][_0x7cca('0x9')]=function(){logger[_0x7cca('0x10')](_0x7cca('0x11'),this[_0x7cca('0x5')]['id'],this[_0x7cca('0x6')]['id']);if(_['isNil'](this[_0x7cca('0x7')]['agents'][this['agent']['id']])){logger['debug'](_0x7cca('0x12'),this[_0x7cca('0x5')]['id'],this[_0x7cca('0x6')]['id']);setTimeout(this[_0x7cca('0xf')][_0x7cca('0xa')](this),0x3e8);}else{if(this['routing'][_0x7cca('0x13')]||util['isAgentAvailable'](this['squeue']['id'],this['realtime'][_0x7cca('0x14')][this[_0x7cca('0x6')]['id']],this[_0x7cca('0x5')][_0x7cca('0x15')],![])){this[_0x7cca('0x7')][_0x7cca('0x14')][this[_0x7cca('0x6')]['id']][_0x7cca('0x16')]=!![];this['realtime'][_0x7cca('0x14')][this[_0x7cca('0x6')]['id']][_0x7cca('0x17')]=undefined;util[_0x7cca('0x18')](this['realtime'],this[_0x7cca('0x8')],this[_0x7cca('0x6')],this[_0x7cca('0x5')][_0x7cca('0x15')]);util[_0x7cca('0x19')](this[_0x7cca('0x4')],this[_0x7cca('0x5')]['id'],this[_0x7cca('0x7')]['agents'][this[_0x7cca('0x6')]['id']],null,this[_0x7cca('0x8')]);util[_0x7cca('0x1a')](this[_0x7cca('0x5')]['id'],this[_0x7cca('0x7')][_0x7cca('0x14')][this[_0x7cca('0x6')]['id']],_0x7cca('0x1b')+(this['routing'][_0x7cca('0x13')]?':FORCED':''));}else{logger[_0x7cca('0x10')](_0x7cca('0x1c'),this['squeue']['id'],this[_0x7cca('0x6')]['id']);setTimeout(this[_0x7cca('0xf')]['bind'](this),0x3e8);}}};Agent[_0x7cca('0xe')][_0x7cca('0xb')]=function(_0x100061){if(_['isNil'](this['realtime'][_0x7cca('0x14')][this[_0x7cca('0x6')]['id']])){return logger[_0x7cca('0x10')](_0x7cca('0x12'),this[_0x7cca('0x5')]['id'],this[_0x7cca('0x6')]['id']);}else{logger[_0x7cca('0x10')]('[%s][AGENT]\x20timeout\x20with\x20%s',this['squeue']['id'],this[_0x7cca('0x6')]['id']);util[_0x7cca('0x1d')](this[_0x7cca('0x4')],this['squeue']['id'],this[_0x7cca('0x7')]['agents'][this[_0x7cca('0x6')]['id']],null,this[_0x7cca('0x8')]);this[_0x7cca('0x7')][_0x7cca('0x14')][this['agent']['id']][_0x7cca('0x16')]=![];this[_0x7cca('0x7')][_0x7cca('0x14')][this['agent']['id']]['busyQueue']=undefined;util['removeWaitingNotification'](this[_0x7cca('0x7')],this[_0x7cca('0x8')],this['agent'],this[_0x7cca('0x5')][_0x7cca('0x15')]);util[_0x7cca('0x1a')](this[_0x7cca('0x5')]['id'],this[_0x7cca('0x7')][_0x7cca('0x14')][this[_0x7cca('0x6')]['id']],_0x100061?'STOP':_0x7cca('0x1e'));}if(!_0x100061){setTimeout(this[_0x7cca('0xf')][_0x7cca('0xa')](this),0x3e8);}};function agent(_0x147cf8,_0x4f28ac,_0x213e4f,_0x387287){return new Agent(_0x147cf8,_0x4f28ac,_0x213e4f,_0x387287);}module[_0x7cca('0x1f')]=agent;