2a6dc0be9a865a3ab43a95a4006f404ccd890b97
[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 _0x9fba=['routing','notificationId','squeue','agent','realtime','push','handleRun','bind','handleTimeout','prototype','info','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','isAgentAvailable','channel','busy','showNotification','writeLog','RINGING','forcedOwnership',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','[%s][AGENT]\x20timeout\x20with\x20%s','busyQueue','STOP','TIMEOUT','uuid'];(function(_0x365c7f,_0xa99915){var _0x4a697e=function(_0x3ad4ce){while(--_0x3ad4ce){_0x365c7f['push'](_0x365c7f['shift']());}};_0x4a697e(++_0xa99915);}(_0x9fba,0x90));var _0xa9fb=function(_0x18cd5b,_0x10240b){_0x18cd5b=_0x18cd5b-0x0;var _0x5eaa52=_0x9fba[_0x18cd5b];return _0x5eaa52;};'use strict';var _=require('lodash');var uuid=require(_0xa9fb('0x0'));var util=require('./util');var logger=require('../../../../../config/logger')(_0xa9fb('0x1'));var Agent=function(_0x1403a8,_0x52bfb8,_0x4aeca4,_0x4ed2ca){this[_0xa9fb('0x2')]=uuid['v4']();this[_0xa9fb('0x3')]=_0x1403a8;this[_0xa9fb('0x4')]=_0x52bfb8;this[_0xa9fb('0x5')]=_0x4aeca4;this[_0xa9fb('0x1')]=_0x4ed2ca;this[_0xa9fb('0x3')][_0xa9fb('0x6')](this[_0xa9fb('0x7')][_0xa9fb('0x8')](this),this[_0xa9fb('0x9')][_0xa9fb('0x8')](this));this[_0xa9fb('0x3')]['on']('timeout',this[_0xa9fb('0x9')][_0xa9fb('0x8')](this));this[_0xa9fb('0x3')]['on']('drained',this['handleDrained'][_0xa9fb('0x8')](this));};Agent[_0xa9fb('0xa')]['push']=function(){this['squeue'][_0xa9fb('0x6')](this[_0xa9fb('0x7')][_0xa9fb('0x8')](this),this[_0xa9fb('0x9')][_0xa9fb('0x8')](this));};Agent['prototype']['handleDrained']=function(){this['handleTimeout'](!![]);};Agent['prototype'][_0xa9fb('0x7')]=function(_0x2fba28){logger[_0xa9fb('0xb')](_0xa9fb('0xc'),this[_0xa9fb('0x3')]['id'],this[_0xa9fb('0x4')]['id']);if(_[_0xa9fb('0xd')](this[_0xa9fb('0x5')][_0xa9fb('0xe')][this['agent']['id']])){logger['info']('[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xa9fb('0x3')]['id'],this['agent']['id']);setTimeout(this[_0xa9fb('0x6')][_0xa9fb('0x8')](this),0x3e8);}else{if(this[_0xa9fb('0x1')]['forcedOwnership']||util[_0xa9fb('0xf')](this[_0xa9fb('0x3')]['id'],this['realtime'][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']],this[_0xa9fb('0x3')][_0xa9fb('0x10')],![])){this[_0xa9fb('0x5')][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']][_0xa9fb('0x11')]=!![];this[_0xa9fb('0x5')][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']]['busyQueue']=undefined;util[_0xa9fb('0x12')](this[_0xa9fb('0x2')],this[_0xa9fb('0x3')]['id'],this['realtime'][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']],null,this['routing']);util[_0xa9fb('0x13')](this['squeue']['id'],this['realtime'][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']],_0xa9fb('0x14')+(this[_0xa9fb('0x1')][_0xa9fb('0x15')]?_0xa9fb('0x16'):''));}else{logger[_0xa9fb('0xb')](_0xa9fb('0x17'),this[_0xa9fb('0x3')]['id'],this[_0xa9fb('0x4')]['id']);setTimeout(this[_0xa9fb('0x6')]['bind'](this),0x3e8);}}};Agent[_0xa9fb('0xa')][_0xa9fb('0x9')]=function(_0x54afba){if(_[_0xa9fb('0xd')](this['realtime'][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']])){return logger['info'](_0xa9fb('0x18'),this[_0xa9fb('0x3')]['id'],this[_0xa9fb('0x4')]['id']);}else{logger[_0xa9fb('0xb')](_0xa9fb('0x19'),this['squeue']['id'],this['agent']['id']);util['hideNotification'](this[_0xa9fb('0x2')],this[_0xa9fb('0x3')]['id'],this['realtime'][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']],null,this['routing']);this[_0xa9fb('0x5')][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']][_0xa9fb('0x11')]=![];this['realtime'][_0xa9fb('0xe')][this[_0xa9fb('0x4')]['id']][_0xa9fb('0x1a')]=undefined;util['writeLog'](this[_0xa9fb('0x3')]['id'],this['realtime']['agents'][this[_0xa9fb('0x4')]['id']],_0x54afba?_0xa9fb('0x1b'):_0xa9fb('0x1c'));}if(!_0x54afba){setTimeout(this[_0xa9fb('0x6')]['bind'](this),0x3e8);}};function agent(_0x372e5c,_0x34cf07,_0x5d6722,_0x453bcb){return new Agent(_0x372e5c,_0x34cf07,_0x5d6722,_0x453bcb);}module['exports']=agent;