23c43aa9ee2e054337416bf0d28e5be46819cb6b
[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 _0x4d23=['isAgentAvailable','busy','busyQueue','showNotification','RINGING','[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','writeLog','STOP','TIMEOUT','exports','./util','../../../../../config/logger','routing','notificationId','squeue','agent','realtime','push','bind','timeout','handleTimeout','prototype','handleRun','handleDrained','info','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','forcedOwnership'];(function(_0x3caa84,_0x7e8d4e){var _0x5235bd=function(_0x194834){while(--_0x194834){_0x3caa84['push'](_0x3caa84['shift']());}};_0x5235bd(++_0x7e8d4e);}(_0x4d23,0x12c));var _0x34d2=function(_0x58f959,_0x161339){_0x58f959=_0x58f959-0x0;var _0x29810f=_0x4d23[_0x58f959];return _0x29810f;};'use strict';var _=require('lodash');var uuid=require('uuid');var util=require(_0x34d2('0x0'));var logger=require(_0x34d2('0x1'))(_0x34d2('0x2'));var Agent=function(_0x2acdcc,_0x11b1c6,_0x2489aa,_0x7cf8af){this[_0x34d2('0x3')]=uuid['v4']();this[_0x34d2('0x4')]=_0x2acdcc;this[_0x34d2('0x5')]=_0x11b1c6;this[_0x34d2('0x6')]=_0x2489aa;this['routing']=_0x7cf8af;this[_0x34d2('0x4')][_0x34d2('0x7')](this['handleRun']['bind'](this),this['handleTimeout'][_0x34d2('0x8')](this));this[_0x34d2('0x4')]['on'](_0x34d2('0x9'),this[_0x34d2('0xa')][_0x34d2('0x8')](this));this[_0x34d2('0x4')]['on']('drained',this['handleDrained'][_0x34d2('0x8')](this));};Agent[_0x34d2('0xb')][_0x34d2('0x7')]=function(){this[_0x34d2('0x4')]['push'](this[_0x34d2('0xc')]['bind'](this),this[_0x34d2('0xa')]['bind'](this));};Agent['prototype'][_0x34d2('0xd')]=function(){this[_0x34d2('0xa')](!![]);};Agent[_0x34d2('0xb')][_0x34d2('0xc')]=function(_0x154423){logger[_0x34d2('0xe')](_0x34d2('0xf'),this['squeue']['id'],this[_0x34d2('0x5')]['id']);if(_[_0x34d2('0x10')](this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']])){logger['info'](_0x34d2('0x12'),this[_0x34d2('0x4')]['id'],this[_0x34d2('0x5')]['id']);setTimeout(this[_0x34d2('0x7')][_0x34d2('0x8')](this),0x3e8);}else{if(this[_0x34d2('0x2')][_0x34d2('0x13')]||util[_0x34d2('0x14')](this['squeue']['id'],this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']],this['squeue']['channel'],![])){this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']][_0x34d2('0x15')]=!![];this['realtime'][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']][_0x34d2('0x16')]=undefined;util[_0x34d2('0x17')](this[_0x34d2('0x3')],this[_0x34d2('0x4')]['id'],this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']],null,this[_0x34d2('0x2')]);util['writeLog'](this[_0x34d2('0x4')]['id'],this['realtime']['agents'][this[_0x34d2('0x5')]['id']],_0x34d2('0x18')+(this['routing']['forcedOwnership']?':FORCED':''));}else{logger[_0x34d2('0xe')](_0x34d2('0x19'),this[_0x34d2('0x4')]['id'],this['agent']['id']);setTimeout(this['push'][_0x34d2('0x8')](this),0x3e8);}}};Agent[_0x34d2('0xb')]['handleTimeout']=function(_0x136c6e){if(_['isNil'](this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']])){return logger[_0x34d2('0xe')](_0x34d2('0x12'),this[_0x34d2('0x4')]['id'],this[_0x34d2('0x5')]['id']);}else{logger['info'](_0x34d2('0x1a'),this[_0x34d2('0x4')]['id'],this[_0x34d2('0x5')]['id']);util[_0x34d2('0x1b')](this['notificationId'],this[_0x34d2('0x4')]['id'],this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']],null,this[_0x34d2('0x2')]);this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']][_0x34d2('0x15')]=![];this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']][_0x34d2('0x16')]=undefined;util[_0x34d2('0x1c')](this[_0x34d2('0x4')]['id'],this[_0x34d2('0x6')][_0x34d2('0x11')][this[_0x34d2('0x5')]['id']],_0x136c6e?_0x34d2('0x1d'):_0x34d2('0x1e'));}if(!_0x136c6e){setTimeout(this[_0x34d2('0x7')][_0x34d2('0x8')](this),0x3e8);}};function agent(_0x27b832,_0x2017d6,_0x5b6b2d,_0xe50c1a){return new Agent(_0x27b832,_0x2017d6,_0x5b6b2d,_0xe50c1a);}module[_0x34d2('0x1f')]=agent;