Built motion from commit 3c2ce842.|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 _0x5c12=['squeue','realtime','bind','handleTimeout','timeout','drained','handleDrained','push','handleRun','debug','[%s][AGENT]\x20try\x20with\x20%s','agent','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership','isAgentAvailable','channel','busy','agents','saveWaitingNotification','showNotification','RINGING',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','prototype','isNil','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busyQueue','writeLog','STOP','TIMEOUT','exports','uuid','./util','routing','notificationId'];(function(_0x4ecb36,_0x84bab4){var _0x21784c=function(_0xf071a0){while(--_0xf071a0){_0x4ecb36['push'](_0x4ecb36['shift']());}};_0x21784c(++_0x84bab4);}(_0x5c12,0x188));var _0x25c1=function(_0x46698a,_0x8de1e4){_0x46698a=_0x46698a-0x0;var _0x356db0=_0x5c12[_0x46698a];return _0x356db0;};'use strict';var _=require('lodash');var uuid=require(_0x25c1('0x0'));var util=require(_0x25c1('0x1'));var logger=require('../../../../../config/logger')(_0x25c1('0x2'));var Agent=function(_0x1991e5,_0x4042fe,_0x10f10c,_0x2c5df0){this[_0x25c1('0x3')]=uuid['v4']();this[_0x25c1('0x4')]=_0x1991e5;this['agent']=_0x4042fe;this[_0x25c1('0x5')]=_0x10f10c;this[_0x25c1('0x2')]=_0x2c5df0;this[_0x25c1('0x4')]['push'](this['handleRun'][_0x25c1('0x6')](this),this[_0x25c1('0x7')][_0x25c1('0x6')](this));this[_0x25c1('0x4')]['on'](_0x25c1('0x8'),this['handleTimeout'][_0x25c1('0x6')](this));this[_0x25c1('0x4')]['on'](_0x25c1('0x9'),this[_0x25c1('0xa')][_0x25c1('0x6')](this));};Agent['prototype'][_0x25c1('0xb')]=function(){this[_0x25c1('0x4')]['push'](this[_0x25c1('0xc')][_0x25c1('0x6')](this),this[_0x25c1('0x7')][_0x25c1('0x6')](this));};Agent['prototype']['handleDrained']=function(){this['handleTimeout'](!![]);};Agent['prototype'][_0x25c1('0xc')]=function(){logger[_0x25c1('0xd')](_0x25c1('0xe'),this[_0x25c1('0x4')]['id'],this[_0x25c1('0xf')]['id']);if(_['isNil'](this[_0x25c1('0x5')]['agents'][this['agent']['id']])){logger['debug'](_0x25c1('0x10'),this[_0x25c1('0x4')]['id'],this['agent']['id']);setTimeout(this['push'][_0x25c1('0x6')](this),0x3e8);}else{if(this['routing'][_0x25c1('0x11')]||util[_0x25c1('0x12')](this['squeue']['id'],this['realtime']['agents'][this[_0x25c1('0xf')]['id']],this[_0x25c1('0x4')][_0x25c1('0x13')],![])){this[_0x25c1('0x5')]['agents'][this[_0x25c1('0xf')]['id']][_0x25c1('0x14')]=!![];this[_0x25c1('0x5')][_0x25c1('0x15')][this['agent']['id']]['busyQueue']=undefined;util[_0x25c1('0x16')](this[_0x25c1('0x5')],this[_0x25c1('0x2')],this[_0x25c1('0xf')],this[_0x25c1('0x4')][_0x25c1('0x13')]);util[_0x25c1('0x17')](this[_0x25c1('0x3')],this[_0x25c1('0x4')]['id'],this[_0x25c1('0x5')][_0x25c1('0x15')][this[_0x25c1('0xf')]['id']],null,this[_0x25c1('0x2')]);util['writeLog'](this[_0x25c1('0x4')]['id'],this[_0x25c1('0x5')][_0x25c1('0x15')][this[_0x25c1('0xf')]['id']],_0x25c1('0x18')+(this[_0x25c1('0x2')]['forcedOwnership']?_0x25c1('0x19'):''));}else{logger[_0x25c1('0xd')](_0x25c1('0x1a'),this[_0x25c1('0x4')]['id'],this[_0x25c1('0xf')]['id']);setTimeout(this[_0x25c1('0xb')]['bind'](this),0x3e8);}}};Agent[_0x25c1('0x1b')]['handleTimeout']=function(_0x76b360){if(_[_0x25c1('0x1c')](this[_0x25c1('0x5')][_0x25c1('0x15')][this[_0x25c1('0xf')]['id']])){return logger[_0x25c1('0xd')](_0x25c1('0x10'),this[_0x25c1('0x4')]['id'],this[_0x25c1('0xf')]['id']);}else{logger['debug'](_0x25c1('0x1d'),this['squeue']['id'],this['agent']['id']);util[_0x25c1('0x1e')](this[_0x25c1('0x3')],this['squeue']['id'],this[_0x25c1('0x5')]['agents'][this[_0x25c1('0xf')]['id']],null,this['routing']);this[_0x25c1('0x5')][_0x25c1('0x15')][this[_0x25c1('0xf')]['id']][_0x25c1('0x14')]=![];this[_0x25c1('0x5')][_0x25c1('0x15')][this[_0x25c1('0xf')]['id']][_0x25c1('0x1f')]=undefined;util['removeWaitingNotification'](this[_0x25c1('0x5')],this['routing'],this[_0x25c1('0xf')],this['squeue'][_0x25c1('0x13')]);util[_0x25c1('0x20')](this[_0x25c1('0x4')]['id'],this[_0x25c1('0x5')][_0x25c1('0x15')][this[_0x25c1('0xf')]['id']],_0x76b360?_0x25c1('0x21'):_0x25c1('0x22'));}if(!_0x76b360){setTimeout(this[_0x25c1('0xb')][_0x25c1('0x6')](this),0x3e8);}};function agent(_0x26ed98,_0x3f02f2,_0x1041a3,_0x1b6e92){return new Agent(_0x26ed98,_0x3f02f2,_0x1041a3,_0x1b6e92);}module[_0x25c1('0x23')]=agent;