Built motion from commit 4c281f94.|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 _0x0ba7=['handleRun','bind','handleTimeout','timeout','drained','handleDrained','prototype','debug','[%s][AGENT]\x20try\x20with\x20%s','isNil','agents','[%s][AGENT]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','channel','busy','busyQueue','RINGING','forcedOwnership',':FORCED','[%s][AGENT]\x20timeout\x20with\x20%s','hideNotification','removeWaitingNotification','writeLog','STOP','TIMEOUT','lodash','./util','../../../../../config/logger','routing','notificationId','squeue','agent','realtime','push'];(function(_0x4d2cd6,_0x3dca37){var _0x23acb6=function(_0x4837d5){while(--_0x4837d5){_0x4d2cd6['push'](_0x4d2cd6['shift']());}};_0x23acb6(++_0x3dca37);}(_0x0ba7,0x16d));var _0x70ba=function(_0x11dfac,_0x130a5c){_0x11dfac=_0x11dfac-0x0;var _0x4bb484=_0x0ba7[_0x11dfac];return _0x4bb484;};'use strict';var _=require(_0x70ba('0x0'));var uuid=require('uuid');var util=require(_0x70ba('0x1'));var logger=require(_0x70ba('0x2'))(_0x70ba('0x3'));var Agent=function(_0x42d93c,_0x5e5368,_0x319ca9,_0x3e20ab){this[_0x70ba('0x4')]=uuid['v4']();this[_0x70ba('0x5')]=_0x42d93c;this[_0x70ba('0x6')]=_0x5e5368;this[_0x70ba('0x7')]=_0x319ca9;this[_0x70ba('0x3')]=_0x3e20ab;this[_0x70ba('0x5')][_0x70ba('0x8')](this[_0x70ba('0x9')][_0x70ba('0xa')](this),this[_0x70ba('0xb')][_0x70ba('0xa')](this));this[_0x70ba('0x5')]['on'](_0x70ba('0xc'),this['handleTimeout'][_0x70ba('0xa')](this));this['squeue']['on'](_0x70ba('0xd'),this[_0x70ba('0xe')][_0x70ba('0xa')](this));};Agent[_0x70ba('0xf')]['push']=function(){this['squeue'][_0x70ba('0x8')](this['handleRun'][_0x70ba('0xa')](this),this['handleTimeout'][_0x70ba('0xa')](this));};Agent[_0x70ba('0xf')]['handleDrained']=function(){this[_0x70ba('0xb')](!![]);};Agent['prototype'][_0x70ba('0x9')]=function(){logger[_0x70ba('0x10')](_0x70ba('0x11'),this[_0x70ba('0x5')]['id'],this[_0x70ba('0x6')]['id']);if(_[_0x70ba('0x12')](this[_0x70ba('0x7')][_0x70ba('0x13')][this[_0x70ba('0x6')]['id']])){logger[_0x70ba('0x10')](_0x70ba('0x14'),this[_0x70ba('0x5')]['id'],this[_0x70ba('0x6')]['id']);setTimeout(this[_0x70ba('0x8')]['bind'](this),0x3e8);}else{if(this['routing']['forcedOwnership']||util[_0x70ba('0x15')](this[_0x70ba('0x5')]['id'],this[_0x70ba('0x7')][_0x70ba('0x13')][this[_0x70ba('0x6')]['id']],this[_0x70ba('0x5')][_0x70ba('0x16')],![])){this[_0x70ba('0x7')][_0x70ba('0x13')][this[_0x70ba('0x6')]['id']][_0x70ba('0x17')]=!![];this[_0x70ba('0x7')][_0x70ba('0x13')][this[_0x70ba('0x6')]['id']][_0x70ba('0x18')]=undefined;util['saveWaitingNotification'](this[_0x70ba('0x7')],this[_0x70ba('0x3')],this['agent'],this[_0x70ba('0x5')]['channel']);util['showNotification'](this[_0x70ba('0x4')],this['squeue']['id'],this[_0x70ba('0x7')][_0x70ba('0x13')][this['agent']['id']],null,this[_0x70ba('0x3')]);util['writeLog'](this['squeue']['id'],this[_0x70ba('0x7')]['agents'][this[_0x70ba('0x6')]['id']],_0x70ba('0x19')+(this[_0x70ba('0x3')][_0x70ba('0x1a')]?_0x70ba('0x1b'):''));}else{logger[_0x70ba('0x10')]('[%s][AGENT]\x20agent\x20%s\x20is\x20not\x20available',this[_0x70ba('0x5')]['id'],this[_0x70ba('0x6')]['id']);setTimeout(this[_0x70ba('0x8')]['bind'](this),0x3e8);}}};Agent[_0x70ba('0xf')]['handleTimeout']=function(_0x5955dc){if(_['isNil'](this[_0x70ba('0x7')][_0x70ba('0x13')][this['agent']['id']])){return logger['debug'](_0x70ba('0x14'),this['squeue']['id'],this[_0x70ba('0x6')]['id']);}else{logger[_0x70ba('0x10')](_0x70ba('0x1c'),this[_0x70ba('0x5')]['id'],this[_0x70ba('0x6')]['id']);util[_0x70ba('0x1d')](this[_0x70ba('0x4')],this[_0x70ba('0x5')]['id'],this[_0x70ba('0x7')][_0x70ba('0x13')][this[_0x70ba('0x6')]['id']],null,this['routing']);this['realtime'][_0x70ba('0x13')][this[_0x70ba('0x6')]['id']][_0x70ba('0x17')]=![];this['realtime']['agents'][this['agent']['id']][_0x70ba('0x18')]=undefined;util[_0x70ba('0x1e')](this[_0x70ba('0x7')],this['routing'],this[_0x70ba('0x6')],this['squeue']['channel']);util[_0x70ba('0x1f')](this['squeue']['id'],this[_0x70ba('0x7')][_0x70ba('0x13')][this['agent']['id']],_0x5955dc?_0x70ba('0x20'):_0x70ba('0x21'));}if(!_0x5955dc){setTimeout(this[_0x70ba('0x8')]['bind'](this),0x3e8);}};function agent(_0x1402b2,_0x20c3fd,_0xbb0c72,_0x75fbbe){return new Agent(_0x1402b2,_0x20c3fd,_0xbb0c72,_0x75fbbe);}module['exports']=agent;