Built motion from commit 08fb8613.|2.6.31
[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 _0x4b84=['hideNotification','removeWaitingNotification','STOP','TIMEOUT','exports','lodash','uuid','routing','notificationId','push','bind','squeue','timeout','handleTimeout','drained','handleDrained','prototype','handleRun','agent','isNil','realtime','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','channel','agents','busy','busyQueue','saveWaitingNotification','showNotification','writeLog','RINGING',':FORCED','debug','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s'];(function(_0x2472c2,_0x1de83a){var _0x5fb3aa=function(_0x36cccd){while(--_0x36cccd){_0x2472c2['push'](_0x2472c2['shift']());}};_0x5fb3aa(++_0x1de83a);}(_0x4b84,0x1cc));var _0x44b8=function(_0x2ecc65,_0xd75c48){_0x2ecc65=_0x2ecc65-0x0;var _0x103cc3=_0x4b84[_0x2ecc65];return _0x103cc3;};'use strict';var _=require(_0x44b8('0x0'));var uuid=require(_0x44b8('0x1'));var util=require('./util');var logger=require('../../../../../config/logger')(_0x44b8('0x2'));var Agent=function(_0x519db3,_0x4b8ad8,_0x3b26c7,_0x31282a){this[_0x44b8('0x3')]=uuid['v4']();this['squeue']=_0x519db3;this['agent']=_0x4b8ad8;this['realtime']=_0x3b26c7;this[_0x44b8('0x2')]=_0x31282a;this['squeue'][_0x44b8('0x4')](this['handleRun'][_0x44b8('0x5')](this),this['handleTimeout']['bind'](this));this[_0x44b8('0x6')]['on'](_0x44b8('0x7'),this[_0x44b8('0x8')]['bind'](this));this[_0x44b8('0x6')]['on'](_0x44b8('0x9'),this[_0x44b8('0xa')][_0x44b8('0x5')](this));};Agent[_0x44b8('0xb')][_0x44b8('0x4')]=function(){this[_0x44b8('0x6')]['push'](this[_0x44b8('0xc')][_0x44b8('0x5')](this),this['handleTimeout'][_0x44b8('0x5')](this));};Agent['prototype'][_0x44b8('0xa')]=function(){this[_0x44b8('0x8')](!![]);};Agent['prototype'][_0x44b8('0xc')]=function(){logger['debug']('[%s][AGENT]\x20try\x20with\x20%s',this[_0x44b8('0x6')]['id'],this[_0x44b8('0xd')]['id']);if(_[_0x44b8('0xe')](this[_0x44b8('0xf')]['agents'][this['agent']['id']])){logger['debug'](_0x44b8('0x10'),this['squeue']['id'],this[_0x44b8('0xd')]['id']);setTimeout(this[_0x44b8('0x4')]['bind'](this),0x3e8);}else{if(this[_0x44b8('0x2')][_0x44b8('0x11')]||util['isAgentAvailable'](this[_0x44b8('0x6')]['id'],this[_0x44b8('0xf')]['agents'][this[_0x44b8('0xd')]['id']],this[_0x44b8('0x6')][_0x44b8('0x12')],![])){this[_0x44b8('0xf')][_0x44b8('0x13')][this[_0x44b8('0xd')]['id']][_0x44b8('0x14')]=!![];this[_0x44b8('0xf')][_0x44b8('0x13')][this[_0x44b8('0xd')]['id']][_0x44b8('0x15')]=undefined;util[_0x44b8('0x16')](this['realtime'],this[_0x44b8('0x2')],this[_0x44b8('0xd')],this[_0x44b8('0x6')][_0x44b8('0x12')]);util[_0x44b8('0x17')](this['notificationId'],this[_0x44b8('0x6')]['id'],this['realtime'][_0x44b8('0x13')][this[_0x44b8('0xd')]['id']],null,this[_0x44b8('0x2')]);util[_0x44b8('0x18')](this[_0x44b8('0x6')]['id'],this['realtime'][_0x44b8('0x13')][this['agent']['id']],_0x44b8('0x19')+(this[_0x44b8('0x2')]['forcedOwnership']?_0x44b8('0x1a'):''));}else{logger[_0x44b8('0x1b')](_0x44b8('0x1c'),this['squeue']['id'],this[_0x44b8('0xd')]['id']);setTimeout(this[_0x44b8('0x4')]['bind'](this),0x3e8);}}};Agent[_0x44b8('0xb')]['handleTimeout']=function(_0xfb0028){if(_['isNil'](this['realtime']['agents'][this[_0x44b8('0xd')]['id']])){return logger[_0x44b8('0x1b')](_0x44b8('0x10'),this[_0x44b8('0x6')]['id'],this[_0x44b8('0xd')]['id']);}else{logger[_0x44b8('0x1b')](_0x44b8('0x1d'),this[_0x44b8('0x6')]['id'],this[_0x44b8('0xd')]['id']);util[_0x44b8('0x1e')](this[_0x44b8('0x3')],this[_0x44b8('0x6')]['id'],this[_0x44b8('0xf')]['agents'][this[_0x44b8('0xd')]['id']],null,this['routing']);this[_0x44b8('0xf')][_0x44b8('0x13')][this[_0x44b8('0xd')]['id']][_0x44b8('0x14')]=![];this[_0x44b8('0xf')]['agents'][this[_0x44b8('0xd')]['id']][_0x44b8('0x15')]=undefined;util[_0x44b8('0x1f')](this[_0x44b8('0xf')],this[_0x44b8('0x2')],this['agent'],this[_0x44b8('0x6')][_0x44b8('0x12')]);util[_0x44b8('0x18')](this[_0x44b8('0x6')]['id'],this[_0x44b8('0xf')][_0x44b8('0x13')][this[_0x44b8('0xd')]['id']],_0xfb0028?_0x44b8('0x20'):_0x44b8('0x21'));}if(!_0xfb0028){setTimeout(this[_0x44b8('0x4')][_0x44b8('0x5')](this),0x3e8);}};function agent(_0xce304d,_0xa5ac3e,_0xae15f4,_0x1e1a8a){return new Agent(_0xce304d,_0xa5ac3e,_0xae15f4,_0x1e1a8a);}module[_0x44b8('0x22')]=agent;