c85c527c972199d37ef7313f79f29d73348ca5f4
[motion2.git] / server / services / routing / server / applications / strategy / beepall.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 _0x0b9f=['timeout','drained','prototype','push','handleDrained','isNil','Agents','length','agents','debug','isAgentAvailable','channel','writeLog','busyQueue','name','showNotification','notificationId','[%s][QUEUE]\x20EMPTY','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','hideNotification','STOP','TIMEOUT','removeWaitingNotification','exports','lodash','uuid','./util','../../../../../config/logger','squeue','queue','realtime','routing','handleRun','handleTimeout','bind'];(function(_0x2499b4,_0x50738d){var _0x159617=function(_0x196de3){while(--_0x196de3){_0x2499b4['push'](_0x2499b4['shift']());}};_0x159617(++_0x50738d);}(_0x0b9f,0x1bc));var _0xf0b9=function(_0x8abbd0,_0x3ee1d5){_0x8abbd0=_0x8abbd0-0x0;var _0x1f1727=_0x0b9f[_0x8abbd0];return _0x1f1727;};'use strict';var _=require(_0xf0b9('0x0'));var uuid=require(_0xf0b9('0x1'));var util=require(_0xf0b9('0x2'));var logger=require(_0xf0b9('0x3'))('routing');var Beepall=function(_0x578ded,_0x8b2de7,_0x56534b,_0x121dd4){this['notificationId']=uuid['v4']();this[_0xf0b9('0x4')]=_0x578ded;this[_0xf0b9('0x5')]=_0x8b2de7;this[_0xf0b9('0x6')]=_0x56534b;this[_0xf0b9('0x7')]=_0x121dd4;this[_0xf0b9('0x4')]['push'](this[_0xf0b9('0x8')]['bind'](this),this[_0xf0b9('0x9')][_0xf0b9('0xa')](this));this[_0xf0b9('0x4')]['on'](_0xf0b9('0xb'),this[_0xf0b9('0x9')]['bind'](this));this['squeue']['on'](_0xf0b9('0xc'),this['handleDrained'][_0xf0b9('0xa')](this));};Beepall[_0xf0b9('0xd')]['push']=function(){this['squeue'][_0xf0b9('0xe')](this[_0xf0b9('0x8')]['bind'](this),this[_0xf0b9('0x9')]['bind'](this));};Beepall[_0xf0b9('0xd')][_0xf0b9('0xf')]=function(){this[_0xf0b9('0x9')](!![]);};Beepall[_0xf0b9('0xd')][_0xf0b9('0x8')]=function(){var _0x5baf73=!![];if(!_[_0xf0b9('0x10')](this[_0xf0b9('0x5')])&&!_['isNil'](this[_0xf0b9('0x5')]['Agents'])&&this[_0xf0b9('0x5')][_0xf0b9('0x11')][_0xf0b9('0x12')]>0x0){for(var _0x20d976=0x0,_0x3ccf7f;_0x20d976<this[_0xf0b9('0x5')]['Agents'][_0xf0b9('0x12')];_0x20d976+=0x1){_0x3ccf7f=this[_0xf0b9('0x5')][_0xf0b9('0x11')][_0x20d976]['id'];if(_[_0xf0b9('0x10')](this[_0xf0b9('0x6')][_0xf0b9('0x13')][_0x3ccf7f])){logger[_0xf0b9('0x14')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],_0x3ccf7f);}else{if(util[_0xf0b9('0x15')](this['squeue']['id'],this['realtime']['agents'][_0x3ccf7f],this['squeue'][_0xf0b9('0x16')],!![])){_0x5baf73=![];util[_0xf0b9('0x17')](this['squeue']['id'],this[_0xf0b9('0x6')][_0xf0b9('0x13')][_0x3ccf7f],'RINGING');this[_0xf0b9('0x6')]['agents'][_0x3ccf7f]['busy']=!![];this['realtime'][_0xf0b9('0x13')][_0x3ccf7f][_0xf0b9('0x18')]=this['queue'][_0xf0b9('0x19')];util['saveWaitingNotification'](this[_0xf0b9('0x6')],this[_0xf0b9('0x7')],this[_0xf0b9('0x5')][_0xf0b9('0x11')][_0x20d976],this[_0xf0b9('0x4')][_0xf0b9('0x16')]);util[_0xf0b9('0x1a')](this[_0xf0b9('0x1b')],this[_0xf0b9('0x4')]['id'],this[_0xf0b9('0x6')][_0xf0b9('0x13')][_0x3ccf7f],this[_0xf0b9('0x5')],this['routing']);}}}if(_0x5baf73){logger[_0xf0b9('0x14')]('[%s][QUEUE]\x20ALL\x20AGENTS\x20ARE\x20BUSY',this['squeue']['id']);setTimeout(this[_0xf0b9('0xe')][_0xf0b9('0xa')](this),0x3e8);}}else{logger['debug'](_0xf0b9('0x1c'),this[_0xf0b9('0x4')]['id']);setTimeout(this[_0xf0b9('0xe')][_0xf0b9('0xa')](this),0x3e8);}};Beepall[_0xf0b9('0xd')][_0xf0b9('0x9')]=function(_0x353228){if(!_['isNil'](this[_0xf0b9('0x5')])&&!_[_0xf0b9('0x10')](this[_0xf0b9('0x5')][_0xf0b9('0x11')])){for(var _0xd80223=0x0,_0x154acd;_0xd80223<this['queue'][_0xf0b9('0x11')][_0xf0b9('0x12')];_0xd80223+=0x1){_0x154acd=this['queue'][_0xf0b9('0x11')][_0xd80223]['id'];if(_[_0xf0b9('0x10')](this[_0xf0b9('0x6')][_0xf0b9('0x13')][_0x154acd])){logger[_0xf0b9('0x14')](_0xf0b9('0x1d'),this[_0xf0b9('0x4')]['id'],_0x154acd);}else{util[_0xf0b9('0x1e')](this[_0xf0b9('0x1b')],this[_0xf0b9('0x4')]['id'],this[_0xf0b9('0x6')][_0xf0b9('0x13')][_0x154acd],this[_0xf0b9('0x5')],this['routing']);util[_0xf0b9('0x17')](this[_0xf0b9('0x4')]['id'],this[_0xf0b9('0x6')][_0xf0b9('0x13')][_0x154acd],_0x353228?_0xf0b9('0x1f'):_0xf0b9('0x20'));this['realtime']['agents'][_0x154acd]['busy']=![];this['realtime'][_0xf0b9('0x13')][_0x154acd][_0xf0b9('0x18')]=undefined;util[_0xf0b9('0x21')](this[_0xf0b9('0x6')],this[_0xf0b9('0x7')],this['realtime'][_0xf0b9('0x13')][_0x154acd],this[_0xf0b9('0x4')]['channel']);}}}if(!_0x353228){setTimeout(this[_0xf0b9('0xe')][_0xf0b9('0xa')](this),0x3e8);}};function beepall(_0x6123dd,_0x4d83d7,_0x13a866,_0x1eb95a){return new Beepall(_0x6123dd,_0x4d83d7,_0x13a866,_0x1eb95a);}module[_0xf0b9('0x22')]=beepall;