Built motion from commit 5ba5b610.|2.5.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 _0xcc1f=['[%s][AGENT]\x20try\x20with\x20%s','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','channel','busy','writeLog',':FORCED','isNil','hideNotification','busyQueue','STOP','TIMEOUT','exports','lodash','uuid','routing','notificationId','squeue','agent','realtime','push','bind','handleTimeout','timeout','handleDrained','prototype','handleRun','info'];(function(_0x122ef9,_0x451d2a){var _0x42fba0=function(_0x17c9d3){while(--_0x17c9d3){_0x122ef9['push'](_0x122ef9['shift']());}};_0x42fba0(++_0x451d2a);}(_0xcc1f,0x69));var _0xfcc1=function(_0x539b87,_0x844695){_0x539b87=_0x539b87-0x0;var _0x3a791d=_0xcc1f[_0x539b87];return _0x3a791d;};'use strict';var _=require(_0xfcc1('0x0'));var uuid=require(_0xfcc1('0x1'));var util=require('./util');var logger=require('../../../../../config/logger')(_0xfcc1('0x2'));var Agent=function(_0x47c078,_0x2f3058,_0x3cd4d1,_0x5866fc){this[_0xfcc1('0x3')]=uuid['v4']();this[_0xfcc1('0x4')]=_0x47c078;this[_0xfcc1('0x5')]=_0x2f3058;this[_0xfcc1('0x6')]=_0x3cd4d1;this[_0xfcc1('0x2')]=_0x5866fc;this[_0xfcc1('0x4')][_0xfcc1('0x7')](this['handleRun'][_0xfcc1('0x8')](this),this[_0xfcc1('0x9')][_0xfcc1('0x8')](this));this[_0xfcc1('0x4')]['on'](_0xfcc1('0xa'),this[_0xfcc1('0x9')][_0xfcc1('0x8')](this));this[_0xfcc1('0x4')]['on']('drained',this[_0xfcc1('0xb')]['bind'](this));};Agent[_0xfcc1('0xc')][_0xfcc1('0x7')]=function(){this[_0xfcc1('0x4')]['push'](this[_0xfcc1('0xd')][_0xfcc1('0x8')](this),this['handleTimeout']['bind'](this));};Agent['prototype'][_0xfcc1('0xb')]=function(){this['handleTimeout'](!![]);};Agent[_0xfcc1('0xc')][_0xfcc1('0xd')]=function(_0x89d186){logger[_0xfcc1('0xe')](_0xfcc1('0xf'),this[_0xfcc1('0x4')]['id'],this['agent']['id']);if(_['isNil'](this[_0xfcc1('0x6')][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']])){logger['info'](_0xfcc1('0x11'),this['squeue']['id'],this[_0xfcc1('0x5')]['id']);setTimeout(this[_0xfcc1('0x7')]['bind'](this),0x3e8);}else{if(this[_0xfcc1('0x2')][_0xfcc1('0x12')]||util[_0xfcc1('0x13')](this[_0xfcc1('0x4')]['id'],this[_0xfcc1('0x6')][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']],this[_0xfcc1('0x4')][_0xfcc1('0x14')],![])){this['realtime']['agents'][this[_0xfcc1('0x5')]['id']][_0xfcc1('0x15')]=!![];this['realtime'][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']]['busyQueue']=undefined;util['showNotification'](this[_0xfcc1('0x3')],this[_0xfcc1('0x4')]['id'],this[_0xfcc1('0x6')][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']],null,this[_0xfcc1('0x2')]);util[_0xfcc1('0x16')](this[_0xfcc1('0x4')]['id'],this['realtime']['agents'][this['agent']['id']],'RINGING'+(this[_0xfcc1('0x2')]['forcedOwnership']?_0xfcc1('0x17'):''));}else{logger['info']('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0xfcc1('0x4')]['id'],this[_0xfcc1('0x5')]['id']);setTimeout(this['push'][_0xfcc1('0x8')](this),0x3e8);}}};Agent['prototype']['handleTimeout']=function(_0x412c1f){if(_[_0xfcc1('0x18')](this['realtime'][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']])){return logger[_0xfcc1('0xe')]('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xfcc1('0x4')]['id'],this['agent']['id']);}else{logger['info']('[%s][AGENT]\x20timeout\x20with\x20%s',this[_0xfcc1('0x4')]['id'],this[_0xfcc1('0x5')]['id']);util[_0xfcc1('0x19')](this[_0xfcc1('0x3')],this['squeue']['id'],this[_0xfcc1('0x6')][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']],null,this['routing']);this['realtime'][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']]['busy']=![];this[_0xfcc1('0x6')]['agents'][this[_0xfcc1('0x5')]['id']][_0xfcc1('0x1a')]=undefined;util[_0xfcc1('0x16')](this[_0xfcc1('0x4')]['id'],this['realtime'][_0xfcc1('0x10')][this[_0xfcc1('0x5')]['id']],_0x412c1f?_0xfcc1('0x1b'):_0xfcc1('0x1c'));}if(!_0x412c1f){setTimeout(this['push'][_0xfcc1('0x8')](this),0x3e8);}};function agent(_0x10e4ba,_0x7c71ce,_0x3265b0,_0x4d3734){return new Agent(_0x10e4ba,_0x7c71ce,_0x3265b0,_0x4d3734);}module[_0xfcc1('0x1d')]=agent;