Built motion from commit 0d14f64c.|2.6.34
[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 _0x0a9a=['writeLog','STOP','exports','uuid','../../../../../config/logger','routing','notificationId','agent','realtime','squeue','handleRun','handleTimeout','bind','timeout','prototype','handleDrained','debug','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','push','forcedOwnership','isAgentAvailable','channel','busy','saveWaitingNotification',':FORCED','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busyQueue','removeWaitingNotification'];(function(_0x46b9bf,_0x3c9e5d){var _0xe4b4ac=function(_0x59da47){while(--_0x59da47){_0x46b9bf['push'](_0x46b9bf['shift']());}};_0xe4b4ac(++_0x3c9e5d);}(_0x0a9a,0x183));var _0xa0a9=function(_0x48ba23,_0x45401b){_0x48ba23=_0x48ba23-0x0;var _0x4d39ef=_0x0a9a[_0x48ba23];return _0x4d39ef;};'use strict';var _=require('lodash');var uuid=require(_0xa0a9('0x0'));var util=require('./util');var logger=require(_0xa0a9('0x1'))(_0xa0a9('0x2'));var Agent=function(_0x34801b,_0x49162f,_0x4ba993,_0x317a94){this[_0xa0a9('0x3')]=uuid['v4']();this['squeue']=_0x34801b;this[_0xa0a9('0x4')]=_0x49162f;this[_0xa0a9('0x5')]=_0x4ba993;this[_0xa0a9('0x2')]=_0x317a94;this[_0xa0a9('0x6')]['push'](this[_0xa0a9('0x7')]['bind'](this),this[_0xa0a9('0x8')][_0xa0a9('0x9')](this));this[_0xa0a9('0x6')]['on'](_0xa0a9('0xa'),this['handleTimeout'][_0xa0a9('0x9')](this));this[_0xa0a9('0x6')]['on']('drained',this['handleDrained'][_0xa0a9('0x9')](this));};Agent[_0xa0a9('0xb')]['push']=function(){this[_0xa0a9('0x6')]['push'](this[_0xa0a9('0x7')]['bind'](this),this[_0xa0a9('0x8')][_0xa0a9('0x9')](this));};Agent[_0xa0a9('0xb')][_0xa0a9('0xc')]=function(){this[_0xa0a9('0x8')](!![]);};Agent['prototype'][_0xa0a9('0x7')]=function(){logger[_0xa0a9('0xd')](_0xa0a9('0xe'),this[_0xa0a9('0x6')]['id'],this[_0xa0a9('0x4')]['id']);if(_[_0xa0a9('0xf')](this['realtime'][_0xa0a9('0x10')][this['agent']['id']])){logger['debug'](_0xa0a9('0x11'),this[_0xa0a9('0x6')]['id'],this[_0xa0a9('0x4')]['id']);setTimeout(this[_0xa0a9('0x12')]['bind'](this),0x3e8);}else{if(this[_0xa0a9('0x2')][_0xa0a9('0x13')]||util[_0xa0a9('0x14')](this[_0xa0a9('0x6')]['id'],this[_0xa0a9('0x5')][_0xa0a9('0x10')][this['agent']['id']],this[_0xa0a9('0x6')][_0xa0a9('0x15')],![])){this['realtime']['agents'][this[_0xa0a9('0x4')]['id']][_0xa0a9('0x16')]=!![];this[_0xa0a9('0x5')]['agents'][this[_0xa0a9('0x4')]['id']]['busyQueue']=undefined;util[_0xa0a9('0x17')](this['realtime'],this[_0xa0a9('0x2')],this[_0xa0a9('0x4')],this[_0xa0a9('0x6')][_0xa0a9('0x15')]);util['showNotification'](this[_0xa0a9('0x3')],this['squeue']['id'],this[_0xa0a9('0x5')][_0xa0a9('0x10')][this[_0xa0a9('0x4')]['id']],null,this[_0xa0a9('0x2')]);util['writeLog'](this[_0xa0a9('0x6')]['id'],this[_0xa0a9('0x5')][_0xa0a9('0x10')][this[_0xa0a9('0x4')]['id']],'RINGING'+(this[_0xa0a9('0x2')][_0xa0a9('0x13')]?_0xa0a9('0x18'):''));}else{logger['debug']('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0xa0a9('0x6')]['id'],this[_0xa0a9('0x4')]['id']);setTimeout(this[_0xa0a9('0x12')][_0xa0a9('0x9')](this),0x3e8);}}};Agent[_0xa0a9('0xb')][_0xa0a9('0x8')]=function(_0x2386c9){if(_[_0xa0a9('0xf')](this[_0xa0a9('0x5')][_0xa0a9('0x10')][this[_0xa0a9('0x4')]['id']])){return logger['debug'](_0xa0a9('0x11'),this[_0xa0a9('0x6')]['id'],this['agent']['id']);}else{logger[_0xa0a9('0xd')](_0xa0a9('0x19'),this['squeue']['id'],this['agent']['id']);util[_0xa0a9('0x1a')](this['notificationId'],this['squeue']['id'],this[_0xa0a9('0x5')][_0xa0a9('0x10')][this[_0xa0a9('0x4')]['id']],null,this[_0xa0a9('0x2')]);this[_0xa0a9('0x5')][_0xa0a9('0x10')][this[_0xa0a9('0x4')]['id']]['busy']=![];this[_0xa0a9('0x5')][_0xa0a9('0x10')][this['agent']['id']][_0xa0a9('0x1b')]=undefined;util[_0xa0a9('0x1c')](this[_0xa0a9('0x5')],this['routing'],this['agent'],this[_0xa0a9('0x6')][_0xa0a9('0x15')]);util[_0xa0a9('0x1d')](this[_0xa0a9('0x6')]['id'],this['realtime'][_0xa0a9('0x10')][this[_0xa0a9('0x4')]['id']],_0x2386c9?_0xa0a9('0x1e'):'TIMEOUT');}if(!_0x2386c9){setTimeout(this[_0xa0a9('0x12')][_0xa0a9('0x9')](this),0x3e8);}};function agent(_0x4e121e,_0x53dfd1,_0x3ae735,_0x2ed673){return new Agent(_0x4e121e,_0x53dfd1,_0x3ae735,_0x2ed673);}module[_0xa0a9('0x1f')]=agent;