Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / services / routing / server / applications / 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 _0x1b5d=['[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','stack','lodash','util','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','validate','length','error','map','message','find','agents','createQueue','atimeout','channel','START:%s','end','close','stop','complete','rules'];(function(_0x37b7b6,_0x165a5c){var _0x10c4c3=function(_0x16d71e){while(--_0x16d71e){_0x37b7b6['push'](_0x37b7b6['shift']());}};_0x10c4c3(++_0x165a5c);}(_0x1b5d,0x1cd));var _0xd1b5=function(_0x19b56f,_0x4cbbd9){_0x19b56f=_0x19b56f-0x0;var _0x1e69f9=_0x1b5d[_0x19b56f];return _0x1e69f9;};'use strict';var schema=require('validate');var _=require(_0xd1b5('0x0'));var util=require(_0xd1b5('0x1'));var seqqueue=require('seq-queue');var logger=require(_0xd1b5('0x2'))(_0xd1b5('0x3'));var strategy=require(_0xd1b5('0x4'));var queue=schema({'name':{'type':_0xd1b5('0x5'),'required':!![],'message':_0xd1b5('0x6')},'timeout':{'type':_0xd1b5('0x7'),'message':_0xd1b5('0x8')}});function writeLog(_0xc2d724,_0x486ce2,_0x4ccc1d){return logger[_0xd1b5('0x9')](util['format'](_0xd1b5('0xa'),_0xc2d724,_0x486ce2[_0xd1b5('0xb')],_0x4ccc1d));}function handleFindAgent(_0x4c8249){return function(_0x43bfc5){return _0x43bfc5['name'][_0xd1b5('0xc')]()===_0x4c8249[_0xd1b5('0xc')]();};}exports['consequence']=function(_0x222eb0,_0x219d14,_0x39dab8,_0x53d9e4){return function(_0x2956a8){try{var _0x1474bf={'name':_0x219d14[0x0],'timeout':_0x219d14[0x1]};var _0xf5be25=queue[_0xd1b5('0xd')](_0x1474bf,{'typecast':!![]});if(_0xf5be25[_0xd1b5('0xe')]){logger[_0xd1b5('0xf')]('[%s][AGENT]\x20%s',_0x222eb0,_[_0xd1b5('0x10')](_0xf5be25,_0xd1b5('0x11'))['join'](',\x20'));_0x2956a8['stop']();}else{var _0x26ddbc=_[_0xd1b5('0x12')](_0x39dab8[_0xd1b5('0x13')],handleFindAgent(_0x1474bf[_0xd1b5('0xb')]));if(_0x26ddbc){var _0x2e4aca=(_0x1474bf['timeout']||0xa)*0x3e8;var _0x2d2968,_0x1bb0ce;var _0x31e14b=seqqueue[_0xd1b5('0x14')](_0x2e4aca);_0x31e14b['id']=_0x222eb0;_0x31e14b[_0xd1b5('0x15')]=_0x2e4aca;_0x31e14b[_0xd1b5('0x16')]=_0x53d9e4[_0xd1b5('0x16')];writeLog(_0x222eb0,_0x26ddbc,util['format'](_0xd1b5('0x17'),_0x2e4aca));_0x39dab8['rules'][_0x222eb0]['on'](_0xd1b5('0x18'),function(){logger['info']('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x222eb0);clearTimeout(_0x1bb0ce);_0x1bb0ce=undefined;_0x31e14b[_0xd1b5('0x19')]();if(_0x39dab8['rules'][_0x222eb0]){delete _0x39dab8['rules'][_0x222eb0];}_0x2956a8[_0xd1b5('0x1a')]();});_0x39dab8['rules'][_0x222eb0]['on'](_0xd1b5('0x1b'),function(){if(_0x39dab8[_0xd1b5('0x1c')][_0x222eb0]){delete _0x39dab8[_0xd1b5('0x1c')][_0x222eb0];}});_0x1bb0ce=setTimeout(function(){logger[_0xd1b5('0x9')](_0xd1b5('0x1d'),_0x222eb0);clearTimeout(_0x1bb0ce);_0x31e14b[_0xd1b5('0x19')]();_0x2956a8[_0xd1b5('0x1e')]();},_0x2e4aca);strategy[_0xd1b5('0x1f')](_0x31e14b,_0x26ddbc,_0x39dab8,_0x53d9e4);}else{logger[_0xd1b5('0xf')](_0xd1b5('0x20'),_0x222eb0,_0x1474bf[_0xd1b5('0xb')]);_0x2956a8['stop']();}}}catch(_0x32b238){console[_0xd1b5('0x21')](_0x32b238);logger[_0xd1b5('0xf')]('[%s][QUEUE]\x20%s',_0x222eb0,_0x32b238[_0xd1b5('0x22')]);_0x2956a8[_0xd1b5('0x1a')]();}};};