3ad2cc4d69263f58e03b33eda3edde0bedb0ac7e
[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 _0xb66c=['TIMEOUT','lodash','./util','routing','notificationId','squeue','agent','push','handleRun','bind','handleTimeout','timeout','handleDrained','prototype','debug','isNil','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','realtime','agents','busyQueue','saveWaitingNotification','channel','forcedOwnership',':FORCED','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','busy','writeLog','STOP'];(function(_0x122ef9,_0x451d2a){var _0x42fba0=function(_0x17c9d3){while(--_0x17c9d3){_0x122ef9['push'](_0x122ef9['shift']());}};_0x42fba0(++_0x451d2a);}(_0xb66c,0x175));var _0xcb66=function(_0x391e3b,_0x3e63ed){_0x391e3b=_0x391e3b-0x0;var _0x355fa1=_0xb66c[_0x391e3b];return _0x355fa1;};'use strict';var _=require(_0xcb66('0x0'));var uuid=require('uuid');var util=require(_0xcb66('0x1'));var logger=require('../../../../../config/logger')(_0xcb66('0x2'));var Agent=function(_0x24ea13,_0xf7ccc5,_0x5f487c,_0x35d439){this[_0xcb66('0x3')]=uuid['v4']();this[_0xcb66('0x4')]=_0x24ea13;this[_0xcb66('0x5')]=_0xf7ccc5;this['realtime']=_0x5f487c;this['routing']=_0x35d439;this[_0xcb66('0x4')][_0xcb66('0x6')](this[_0xcb66('0x7')][_0xcb66('0x8')](this),this[_0xcb66('0x9')]['bind'](this));this[_0xcb66('0x4')]['on'](_0xcb66('0xa'),this[_0xcb66('0x9')][_0xcb66('0x8')](this));this[_0xcb66('0x4')]['on']('drained',this[_0xcb66('0xb')][_0xcb66('0x8')](this));};Agent[_0xcb66('0xc')][_0xcb66('0x6')]=function(){this['squeue'][_0xcb66('0x6')](this[_0xcb66('0x7')][_0xcb66('0x8')](this),this[_0xcb66('0x9')]['bind'](this));};Agent[_0xcb66('0xc')][_0xcb66('0xb')]=function(){this[_0xcb66('0x9')](!![]);};Agent[_0xcb66('0xc')]['handleRun']=function(){logger[_0xcb66('0xd')]('[%s][AGENT]\x20try\x20with\x20%s',this[_0xcb66('0x4')]['id'],this['agent']['id']);if(_[_0xcb66('0xe')](this['realtime']['agents'][this[_0xcb66('0x5')]['id']])){logger[_0xcb66('0xd')](_0xcb66('0xf'),this[_0xcb66('0x4')]['id'],this['agent']['id']);setTimeout(this[_0xcb66('0x6')][_0xcb66('0x8')](this),0x3e8);}else{if(this[_0xcb66('0x2')]['forcedOwnership']||util[_0xcb66('0x10')](this['squeue']['id'],this[_0xcb66('0x11')][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']],this[_0xcb66('0x4')]['channel'],![])){this['realtime']['agents'][this[_0xcb66('0x5')]['id']]['busy']=!![];this['realtime'][_0xcb66('0x12')][this['agent']['id']][_0xcb66('0x13')]=undefined;util[_0xcb66('0x14')](this[_0xcb66('0x11')],this[_0xcb66('0x2')],this[_0xcb66('0x5')],this[_0xcb66('0x4')][_0xcb66('0x15')]);util['showNotification'](this[_0xcb66('0x3')],this['squeue']['id'],this['realtime'][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']],null,this[_0xcb66('0x2')]);util['writeLog'](this[_0xcb66('0x4')]['id'],this[_0xcb66('0x11')][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']],'RINGING'+(this[_0xcb66('0x2')][_0xcb66('0x16')]?_0xcb66('0x17'):''));}else{logger[_0xcb66('0xd')](_0xcb66('0x18'),this[_0xcb66('0x4')]['id'],this[_0xcb66('0x5')]['id']);setTimeout(this[_0xcb66('0x6')][_0xcb66('0x8')](this),0x3e8);}}};Agent[_0xcb66('0xc')]['handleTimeout']=function(_0x2152dc){if(_['isNil'](this['realtime']['agents'][this[_0xcb66('0x5')]['id']])){return logger['debug'](_0xcb66('0xf'),this[_0xcb66('0x4')]['id'],this[_0xcb66('0x5')]['id']);}else{logger['debug'](_0xcb66('0x19'),this[_0xcb66('0x4')]['id'],this[_0xcb66('0x5')]['id']);util[_0xcb66('0x1a')](this[_0xcb66('0x3')],this[_0xcb66('0x4')]['id'],this[_0xcb66('0x11')][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']],null,this[_0xcb66('0x2')]);this['realtime'][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']][_0xcb66('0x1b')]=![];this[_0xcb66('0x11')][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']][_0xcb66('0x13')]=undefined;util['removeWaitingNotification'](this[_0xcb66('0x11')],this[_0xcb66('0x2')],this[_0xcb66('0x5')],this[_0xcb66('0x4')]['channel']);util[_0xcb66('0x1c')](this[_0xcb66('0x4')]['id'],this[_0xcb66('0x11')][_0xcb66('0x12')][this[_0xcb66('0x5')]['id']],_0x2152dc?_0xcb66('0x1d'):_0xcb66('0x1e'));}if(!_0x2152dc){setTimeout(this[_0xcb66('0x6')][_0xcb66('0x8')](this),0x3e8);}};function agent(_0x299156,_0x3dc592,_0x17b087,_0x4ef8ba){return new Agent(_0x299156,_0x3dc592,_0x17b087,_0x4ef8ba);}module['exports']=agent;