7765543de63d15c042e3352d1a035fcc047c9807
[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 _0xa29e=[':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busy','STOP','TIMEOUT','exports','./util','../../../../../config/logger','routing','notificationId','agent','squeue','push','bind','handleTimeout','timeout','handleDrained','prototype','handleRun','info','[%s][AGENT]\x20try\x20with\x20%s','isNil','realtime','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','channel','busyQueue','showNotification','writeLog'];(function(_0x164eca,_0x555e28){var _0x2ce562=function(_0x148ca6){while(--_0x148ca6){_0x164eca['push'](_0x164eca['shift']());}};_0x2ce562(++_0x555e28);}(_0xa29e,0x168));var _0xea29=function(_0x37222f,_0x25a5ab){_0x37222f=_0x37222f-0x0;var _0x5c5a6d=_0xa29e[_0x37222f];return _0x5c5a6d;};'use strict';var _=require('lodash');var uuid=require('uuid');var util=require(_0xea29('0x0'));var logger=require(_0xea29('0x1'))(_0xea29('0x2'));var Agent=function(_0xb46426,_0x4ef587,_0x2c564b,_0x5882d7){this[_0xea29('0x3')]=uuid['v4']();this['squeue']=_0xb46426;this[_0xea29('0x4')]=_0x4ef587;this['realtime']=_0x2c564b;this[_0xea29('0x2')]=_0x5882d7;this[_0xea29('0x5')][_0xea29('0x6')](this['handleRun'][_0xea29('0x7')](this),this[_0xea29('0x8')][_0xea29('0x7')](this));this[_0xea29('0x5')]['on'](_0xea29('0x9'),this[_0xea29('0x8')][_0xea29('0x7')](this));this['squeue']['on']('drained',this[_0xea29('0xa')]['bind'](this));};Agent[_0xea29('0xb')][_0xea29('0x6')]=function(){this[_0xea29('0x5')]['push'](this[_0xea29('0xc')][_0xea29('0x7')](this),this['handleTimeout'][_0xea29('0x7')](this));};Agent[_0xea29('0xb')][_0xea29('0xa')]=function(){this[_0xea29('0x8')](!![]);};Agent['prototype'][_0xea29('0xc')]=function(_0x4acb57){logger[_0xea29('0xd')](_0xea29('0xe'),this['squeue']['id'],this[_0xea29('0x4')]['id']);if(_[_0xea29('0xf')](this[_0xea29('0x10')][_0xea29('0x11')][this[_0xea29('0x4')]['id']])){logger[_0xea29('0xd')](_0xea29('0x12'),this['squeue']['id'],this[_0xea29('0x4')]['id']);setTimeout(this['push'][_0xea29('0x7')](this),0x3e8);}else{if(this[_0xea29('0x2')][_0xea29('0x13')]||util['isAgentAvailable'](this[_0xea29('0x5')]['id'],this[_0xea29('0x10')]['agents'][this[_0xea29('0x4')]['id']],this[_0xea29('0x5')][_0xea29('0x14')],![])){this[_0xea29('0x10')]['agents'][this[_0xea29('0x4')]['id']]['busy']=!![];this[_0xea29('0x10')][_0xea29('0x11')][this[_0xea29('0x4')]['id']][_0xea29('0x15')]=undefined;util[_0xea29('0x16')](this[_0xea29('0x3')],this[_0xea29('0x5')]['id'],this[_0xea29('0x10')]['agents'][this[_0xea29('0x4')]['id']],null,this[_0xea29('0x2')]);util[_0xea29('0x17')](this[_0xea29('0x5')]['id'],this[_0xea29('0x10')]['agents'][this[_0xea29('0x4')]['id']],'RINGING'+(this[_0xea29('0x2')]['forcedOwnership']?_0xea29('0x18'):''));}else{logger[_0xea29('0xd')](_0xea29('0x19'),this['squeue']['id'],this['agent']['id']);setTimeout(this['push'][_0xea29('0x7')](this),0x3e8);}}};Agent[_0xea29('0xb')][_0xea29('0x8')]=function(_0x337085){if(_['isNil'](this[_0xea29('0x10')]['agents'][this[_0xea29('0x4')]['id']])){return logger[_0xea29('0xd')](_0xea29('0x12'),this[_0xea29('0x5')]['id'],this['agent']['id']);}else{logger[_0xea29('0xd')](_0xea29('0x1a'),this['squeue']['id'],this[_0xea29('0x4')]['id']);util[_0xea29('0x1b')](this[_0xea29('0x3')],this['squeue']['id'],this[_0xea29('0x10')][_0xea29('0x11')][this[_0xea29('0x4')]['id']],null,this[_0xea29('0x2')]);this[_0xea29('0x10')][_0xea29('0x11')][this[_0xea29('0x4')]['id']][_0xea29('0x1c')]=![];this[_0xea29('0x10')]['agents'][this[_0xea29('0x4')]['id']][_0xea29('0x15')]=undefined;util['writeLog'](this[_0xea29('0x5')]['id'],this[_0xea29('0x10')][_0xea29('0x11')][this[_0xea29('0x4')]['id']],_0x337085?_0xea29('0x1d'):_0xea29('0x1e'));}if(!_0x337085){setTimeout(this['push']['bind'](this),0x3e8);}};function agent(_0x4f4f7f,_0x15ca75,_0x460377,_0x39f1ea){return new Agent(_0x4f4f7f,_0x15ca75,_0x460377,_0x39f1ea);}module[_0xea29('0x1f')]=agent;