Built motion from commit b5413ace.|2.6.9
[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 _0x1789=['writeLog','RINGING',':FORCED','[%s][AGENT]\x20timeout\x20with\x20%s','STOP','exports','lodash','./util','../../../../../config/logger','routing','notificationId','squeue','agent','push','bind','handleTimeout','handleDrained','prototype','handleRun','debug','[%s][AGENT]\x20try\x20with\x20%s','isNil','realtime','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','agents','channel','busy','busyQueue','showNotification'];(function(_0x3a3a87,_0x3c5fa2){var _0x79fcd9=function(_0x25f13a){while(--_0x25f13a){_0x3a3a87['push'](_0x3a3a87['shift']());}};_0x79fcd9(++_0x3c5fa2);}(_0x1789,0xfe));var _0x9178=function(_0x45161c,_0x5494fc){_0x45161c=_0x45161c-0x0;var _0x186581=_0x1789[_0x45161c];return _0x186581;};'use strict';var _=require(_0x9178('0x0'));var uuid=require('uuid');var util=require(_0x9178('0x1'));var logger=require(_0x9178('0x2'))(_0x9178('0x3'));var Agent=function(_0x3cad44,_0xe8e825,_0x2c9d98,_0x4f1b53){this[_0x9178('0x4')]=uuid['v4']();this[_0x9178('0x5')]=_0x3cad44;this[_0x9178('0x6')]=_0xe8e825;this['realtime']=_0x2c9d98;this[_0x9178('0x3')]=_0x4f1b53;this[_0x9178('0x5')][_0x9178('0x7')](this['handleRun'][_0x9178('0x8')](this),this[_0x9178('0x9')][_0x9178('0x8')](this));this['squeue']['on']('timeout',this[_0x9178('0x9')][_0x9178('0x8')](this));this[_0x9178('0x5')]['on']('drained',this[_0x9178('0xa')][_0x9178('0x8')](this));};Agent[_0x9178('0xb')]['push']=function(){this['squeue'][_0x9178('0x7')](this['handleRun'][_0x9178('0x8')](this),this[_0x9178('0x9')]['bind'](this));};Agent[_0x9178('0xb')][_0x9178('0xa')]=function(){this[_0x9178('0x9')](!![]);};Agent[_0x9178('0xb')][_0x9178('0xc')]=function(){logger[_0x9178('0xd')](_0x9178('0xe'),this[_0x9178('0x5')]['id'],this['agent']['id']);if(_[_0x9178('0xf')](this[_0x9178('0x10')]['agents'][this[_0x9178('0x6')]['id']])){logger[_0x9178('0xd')](_0x9178('0x11'),this[_0x9178('0x5')]['id'],this[_0x9178('0x6')]['id']);setTimeout(this[_0x9178('0x7')][_0x9178('0x8')](this),0x3e8);}else{if(this['routing'][_0x9178('0x12')]||util[_0x9178('0x13')](this[_0x9178('0x5')]['id'],this[_0x9178('0x10')][_0x9178('0x14')][this[_0x9178('0x6')]['id']],this[_0x9178('0x5')][_0x9178('0x15')],![])){this[_0x9178('0x10')][_0x9178('0x14')][this[_0x9178('0x6')]['id']][_0x9178('0x16')]=!![];this[_0x9178('0x10')][_0x9178('0x14')][this['agent']['id']][_0x9178('0x17')]=undefined;util[_0x9178('0x18')](this['notificationId'],this[_0x9178('0x5')]['id'],this['realtime']['agents'][this[_0x9178('0x6')]['id']],null,this[_0x9178('0x3')]);util[_0x9178('0x19')](this['squeue']['id'],this[_0x9178('0x10')][_0x9178('0x14')][this[_0x9178('0x6')]['id']],_0x9178('0x1a')+(this['routing'][_0x9178('0x12')]?_0x9178('0x1b'):''));}else{logger['debug']('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0x9178('0x5')]['id'],this['agent']['id']);setTimeout(this[_0x9178('0x7')]['bind'](this),0x3e8);}}};Agent[_0x9178('0xb')][_0x9178('0x9')]=function(_0x2ee2c2){if(_[_0x9178('0xf')](this[_0x9178('0x10')][_0x9178('0x14')][this[_0x9178('0x6')]['id']])){return logger['debug']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],this[_0x9178('0x6')]['id']);}else{logger[_0x9178('0xd')](_0x9178('0x1c'),this[_0x9178('0x5')]['id'],this[_0x9178('0x6')]['id']);util['hideNotification'](this['notificationId'],this[_0x9178('0x5')]['id'],this[_0x9178('0x10')][_0x9178('0x14')][this['agent']['id']],null,this[_0x9178('0x3')]);this[_0x9178('0x10')][_0x9178('0x14')][this[_0x9178('0x6')]['id']][_0x9178('0x16')]=![];this[_0x9178('0x10')]['agents'][this[_0x9178('0x6')]['id']]['busyQueue']=undefined;util[_0x9178('0x19')](this['squeue']['id'],this[_0x9178('0x10')]['agents'][this[_0x9178('0x6')]['id']],_0x2ee2c2?_0x9178('0x1d'):'TIMEOUT');}if(!_0x2ee2c2){setTimeout(this['push']['bind'](this),0x3e8);}};function agent(_0x3f7b98,_0xfbbe46,_0x4c2c8d,_0x550195){return new Agent(_0x3f7b98,_0xfbbe46,_0x4c2c8d,_0x550195);}module[_0x9178('0x1e')]=agent;