b4b3cb1428345156b11e5811b82356886c728601
[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 _0x7e35=['lodash','uuid','./util','../../../../../config/logger','routing','notificationId','agent','squeue','push','handleRun','bind','timeout','drained','handleDrained','prototype','handleTimeout','info','[%s][AGENT]\x20try\x20with\x20%s','isNil','realtime','agents','forcedOwnership','isAgentAvailable','channel','busyQueue','showNotification','writeLog','RINGING',':FORCED','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busy','TIMEOUT','exports'];(function(_0x208e13,_0x593c91){var _0x59ba4e=function(_0x11635b){while(--_0x11635b){_0x208e13['push'](_0x208e13['shift']());}};_0x59ba4e(++_0x593c91);}(_0x7e35,0xcc));var _0x57e3=function(_0x128865,_0x112a2b){_0x128865=_0x128865-0x0;var _0x28aa74=_0x7e35[_0x128865];return _0x28aa74;};'use strict';var _=require(_0x57e3('0x0'));var uuid=require(_0x57e3('0x1'));var util=require(_0x57e3('0x2'));var logger=require(_0x57e3('0x3'))(_0x57e3('0x4'));var Agent=function(_0x192f4e,_0x4fdfca,_0x32ea38,_0x3d8a6b){this[_0x57e3('0x5')]=uuid['v4']();this['squeue']=_0x192f4e;this[_0x57e3('0x6')]=_0x4fdfca;this['realtime']=_0x32ea38;this[_0x57e3('0x4')]=_0x3d8a6b;this[_0x57e3('0x7')][_0x57e3('0x8')](this[_0x57e3('0x9')][_0x57e3('0xa')](this),this['handleTimeout'][_0x57e3('0xa')](this));this[_0x57e3('0x7')]['on'](_0x57e3('0xb'),this['handleTimeout'][_0x57e3('0xa')](this));this[_0x57e3('0x7')]['on'](_0x57e3('0xc'),this[_0x57e3('0xd')][_0x57e3('0xa')](this));};Agent['prototype'][_0x57e3('0x8')]=function(){this[_0x57e3('0x7')][_0x57e3('0x8')](this['handleRun']['bind'](this),this['handleTimeout'][_0x57e3('0xa')](this));};Agent[_0x57e3('0xe')][_0x57e3('0xd')]=function(){this[_0x57e3('0xf')](!![]);};Agent[_0x57e3('0xe')]['handleRun']=function(_0x33a2e3){logger[_0x57e3('0x10')](_0x57e3('0x11'),this[_0x57e3('0x7')]['id'],this[_0x57e3('0x6')]['id']);if(_[_0x57e3('0x12')](this[_0x57e3('0x13')][_0x57e3('0x14')][this[_0x57e3('0x6')]['id']])){logger[_0x57e3('0x10')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x57e3('0x7')]['id'],this[_0x57e3('0x6')]['id']);setTimeout(this['push']['bind'](this),0x3e8);}else{if(this['routing'][_0x57e3('0x15')]||util[_0x57e3('0x16')](this[_0x57e3('0x7')]['id'],this[_0x57e3('0x13')][_0x57e3('0x14')][this[_0x57e3('0x6')]['id']],this['squeue'][_0x57e3('0x17')],![])){this['realtime'][_0x57e3('0x14')][this[_0x57e3('0x6')]['id']]['busy']=!![];this[_0x57e3('0x13')][_0x57e3('0x14')][this['agent']['id']][_0x57e3('0x18')]=undefined;util[_0x57e3('0x19')](this[_0x57e3('0x5')],this[_0x57e3('0x7')]['id'],this[_0x57e3('0x13')][_0x57e3('0x14')][this['agent']['id']],null,this['routing']);util[_0x57e3('0x1a')](this[_0x57e3('0x7')]['id'],this[_0x57e3('0x13')]['agents'][this[_0x57e3('0x6')]['id']],_0x57e3('0x1b')+(this[_0x57e3('0x4')]['forcedOwnership']?_0x57e3('0x1c'):''));}else{logger[_0x57e3('0x10')]('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0x57e3('0x7')]['id'],this[_0x57e3('0x6')]['id']);setTimeout(this[_0x57e3('0x8')][_0x57e3('0xa')](this),0x3e8);}}};Agent[_0x57e3('0xe')][_0x57e3('0xf')]=function(_0xd6b488){if(_['isNil'](this['realtime'][_0x57e3('0x14')][this['agent']['id']])){return logger['info']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x57e3('0x7')]['id'],this['agent']['id']);}else{logger[_0x57e3('0x10')](_0x57e3('0x1d'),this[_0x57e3('0x7')]['id'],this[_0x57e3('0x6')]['id']);util[_0x57e3('0x1e')](this[_0x57e3('0x5')],this[_0x57e3('0x7')]['id'],this[_0x57e3('0x13')][_0x57e3('0x14')][this['agent']['id']],null,this[_0x57e3('0x4')]);this[_0x57e3('0x13')]['agents'][this['agent']['id']][_0x57e3('0x1f')]=![];this[_0x57e3('0x13')]['agents'][this[_0x57e3('0x6')]['id']]['busyQueue']=undefined;util[_0x57e3('0x1a')](this[_0x57e3('0x7')]['id'],this[_0x57e3('0x13')][_0x57e3('0x14')][this['agent']['id']],_0xd6b488?'STOP':_0x57e3('0x20'));}if(!_0xd6b488){setTimeout(this['push'][_0x57e3('0xa')](this),0x3e8);}};function agent(_0x337dd9,_0x576810,_0x2b3608,_0x2cd365){return new Agent(_0x337dd9,_0x576810,_0x2b3608,_0x2cd365);}module[_0x57e3('0x21')]=agent;