Built motion from commit b0a9a629.|2.6.33
[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 _0x1cc7=['forcedOwnership','channel','busy','busyQueue','saveWaitingNotification','showNotification','notificationId','writeLog',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','STOP','TIMEOUT','exports','lodash','uuid','./util','realtime','squeue','push','handleRun','bind','handleTimeout','timeout','prototype','handleDrained','debug','agent','isNil','agents','routing'];(function(_0x4a893c,_0x4f05ea){var _0x3a6668=function(_0x48e7e7){while(--_0x48e7e7){_0x4a893c['push'](_0x4a893c['shift']());}};_0x3a6668(++_0x4f05ea);}(_0x1cc7,0x15a));var _0x71cc=function(_0x11ae0b,_0x18a441){_0x11ae0b=_0x11ae0b-0x0;var _0x3e53b9=_0x1cc7[_0x11ae0b];return _0x3e53b9;};'use strict';var _=require(_0x71cc('0x0'));var uuid=require(_0x71cc('0x1'));var util=require(_0x71cc('0x2'));var logger=require('../../../../../config/logger')('routing');var Agent=function(_0x547fe6,_0xe5d54e,_0x1fac93,_0x402191){this['notificationId']=uuid['v4']();this['squeue']=_0x547fe6;this['agent']=_0xe5d54e;this[_0x71cc('0x3')]=_0x1fac93;this['routing']=_0x402191;this[_0x71cc('0x4')][_0x71cc('0x5')](this[_0x71cc('0x6')][_0x71cc('0x7')](this),this[_0x71cc('0x8')]['bind'](this));this[_0x71cc('0x4')]['on'](_0x71cc('0x9'),this[_0x71cc('0x8')]['bind'](this));this['squeue']['on']('drained',this['handleDrained'][_0x71cc('0x7')](this));};Agent[_0x71cc('0xa')][_0x71cc('0x5')]=function(){this['squeue'][_0x71cc('0x5')](this['handleRun'][_0x71cc('0x7')](this),this['handleTimeout'][_0x71cc('0x7')](this));};Agent['prototype'][_0x71cc('0xb')]=function(){this[_0x71cc('0x8')](!![]);};Agent[_0x71cc('0xa')][_0x71cc('0x6')]=function(){logger[_0x71cc('0xc')]('[%s][AGENT]\x20try\x20with\x20%s',this[_0x71cc('0x4')]['id'],this[_0x71cc('0xd')]['id']);if(_[_0x71cc('0xe')](this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']])){logger[_0x71cc('0xc')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x71cc('0x4')]['id'],this[_0x71cc('0xd')]['id']);setTimeout(this[_0x71cc('0x5')][_0x71cc('0x7')](this),0x3e8);}else{if(this[_0x71cc('0x10')][_0x71cc('0x11')]||util['isAgentAvailable'](this[_0x71cc('0x4')]['id'],this[_0x71cc('0x3')]['agents'][this['agent']['id']],this[_0x71cc('0x4')][_0x71cc('0x12')],![])){this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']][_0x71cc('0x13')]=!![];this[_0x71cc('0x3')][_0x71cc('0xf')][this['agent']['id']][_0x71cc('0x14')]=undefined;util[_0x71cc('0x15')](this['realtime'],this[_0x71cc('0x10')],this[_0x71cc('0xd')],this[_0x71cc('0x4')][_0x71cc('0x12')]);util[_0x71cc('0x16')](this[_0x71cc('0x17')],this['squeue']['id'],this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']],null,this[_0x71cc('0x10')]);util[_0x71cc('0x18')](this[_0x71cc('0x4')]['id'],this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']],'RINGING'+(this[_0x71cc('0x10')][_0x71cc('0x11')]?_0x71cc('0x19'):''));}else{logger[_0x71cc('0xc')](_0x71cc('0x1a'),this[_0x71cc('0x4')]['id'],this[_0x71cc('0xd')]['id']);setTimeout(this[_0x71cc('0x5')][_0x71cc('0x7')](this),0x3e8);}}};Agent[_0x71cc('0xa')][_0x71cc('0x8')]=function(_0x35f723){if(_[_0x71cc('0xe')](this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']])){return logger['debug'](_0x71cc('0x1b'),this[_0x71cc('0x4')]['id'],this[_0x71cc('0xd')]['id']);}else{logger[_0x71cc('0xc')](_0x71cc('0x1c'),this[_0x71cc('0x4')]['id'],this['agent']['id']);util[_0x71cc('0x1d')](this[_0x71cc('0x17')],this[_0x71cc('0x4')]['id'],this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']],null,this[_0x71cc('0x10')]);this['realtime'][_0x71cc('0xf')][this['agent']['id']]['busy']=![];this[_0x71cc('0x3')]['agents'][this['agent']['id']][_0x71cc('0x14')]=undefined;util['removeWaitingNotification'](this[_0x71cc('0x3')],this['routing'],this[_0x71cc('0xd')],this[_0x71cc('0x4')]['channel']);util[_0x71cc('0x18')](this[_0x71cc('0x4')]['id'],this[_0x71cc('0x3')][_0x71cc('0xf')][this[_0x71cc('0xd')]['id']],_0x35f723?_0x71cc('0x1e'):_0x71cc('0x1f'));}if(!_0x35f723){setTimeout(this[_0x71cc('0x5')][_0x71cc('0x7')](this),0x3e8);}};function agent(_0x2f8a72,_0x4b7bc6,_0x4330f0,_0x54d16a){return new Agent(_0x2f8a72,_0x4b7bc6,_0x4330f0,_0x54d16a);}module[_0x71cc('0x20')]=agent;