9f537b1611663d6b163e1431443bc3461f07c8f6
[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 _0x431e=['lodash','util','seq-queue','../../../../config/logger','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','timeout\x20is\x20a\x20number','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','length','error','message','join','stop','atimeout','channel','START:%s','rules','end','info','[%s][AGENT]\x20ROUTING\x20STOPPED','complete','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','log','validate'];(function(_0x501510,_0x61caa9){var _0x1e6ee5=function(_0x32845b){while(--_0x32845b){_0x501510['push'](_0x501510['shift']());}};_0x1e6ee5(++_0x61caa9);}(_0x431e,0x12b));var _0xe431=function(_0x2f6541,_0x363cba){_0x2f6541=_0x2f6541-0x0;var _0x4d76d8=_0x431e[_0x2f6541];return _0x4d76d8;};'use strict';var schema=require(_0xe431('0x0'));var _=require(_0xe431('0x1'));var util=require(_0xe431('0x2'));var seqqueue=require(_0xe431('0x3'));var logger=require(_0xe431('0x4'))('routing');var strategy=require('./strategy');var queue=schema({'name':{'type':'string','required':!![],'message':_0xe431('0x5')},'timeout':{'type':'number','message':_0xe431('0x6')}});function writeLog(_0x5ccff5,_0xb01210,_0x55c9f3){return logger['info'](util[_0xe431('0x7')](_0xe431('0x8'),_0x5ccff5,_0xb01210[_0xe431('0x9')],_0x55c9f3));}function handleFindAgent(_0x155da8){return function(_0x23a0f0){return _0x23a0f0['name'][_0xe431('0xa')]()===_0x155da8[_0xe431('0xa')]();};}exports[_0xe431('0xb')]=function(_0x3fb7b0,_0x4df4f0,_0x5af92b,_0x1e1a36){return function(_0x11d8f8){try{var _0x57b5d8={'name':_0x4df4f0[0x0],'timeout':_0x4df4f0[0x1]};var _0x217385=queue[_0xe431('0x0')](_0x57b5d8,{'typecast':!![]});if(_0x217385[_0xe431('0xc')]){logger[_0xe431('0xd')]('[%s][AGENT]\x20%s',_0x3fb7b0,_['map'](_0x217385,_0xe431('0xe'))[_0xe431('0xf')](',\x20'));_0x11d8f8[_0xe431('0x10')]();}else{var _0xb709f=_['find'](_0x5af92b['agents'],handleFindAgent(_0x57b5d8[_0xe431('0x9')]));if(_0xb709f){var _0x225af2=(_0x57b5d8['timeout']||0xa)*0x3e8;var _0x16f682,_0x2fc4e5;var _0xe1f194=seqqueue['createQueue'](_0x225af2);_0xe1f194['id']=_0x3fb7b0;_0xe1f194[_0xe431('0x11')]=_0x225af2;_0xe1f194[_0xe431('0x12')]=_0x1e1a36[_0xe431('0x12')];writeLog(_0x3fb7b0,_0xb709f,util[_0xe431('0x7')](_0xe431('0x13'),_0x225af2));_0x5af92b[_0xe431('0x14')][_0x3fb7b0]['on'](_0xe431('0x15'),function(){logger[_0xe431('0x16')](_0xe431('0x17'),_0x3fb7b0);clearTimeout(_0x2fc4e5);_0x2fc4e5=undefined;_0xe1f194['close']();if(_0x5af92b[_0xe431('0x14')][_0x3fb7b0]){delete _0x5af92b[_0xe431('0x14')][_0x3fb7b0];}_0x11d8f8[_0xe431('0x10')]();});_0x5af92b['rules'][_0x3fb7b0]['on'](_0xe431('0x18'),function(){if(_0x5af92b[_0xe431('0x14')][_0x3fb7b0]){delete _0x5af92b[_0xe431('0x14')][_0x3fb7b0];}});_0x2fc4e5=setTimeout(function(){logger[_0xe431('0x16')](_0xe431('0x19'),_0x3fb7b0);clearTimeout(_0x2fc4e5);_0xe1f194[_0xe431('0x1a')]();_0x11d8f8[_0xe431('0x1b')]();},_0x225af2);strategy[_0xe431('0x1c')](_0xe1f194,_0xb709f,_0x5af92b,_0x1e1a36);}else{logger[_0xe431('0xd')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x3fb7b0,_0x57b5d8[_0xe431('0x9')]);_0x11d8f8[_0xe431('0x10')]();}}}catch(_0x198573){console[_0xe431('0x1d')](_0x198573);logger[_0xe431('0xd')]('[%s][QUEUE]\x20%s',_0x3fb7b0,_0x198573['stack']);_0x11d8f8[_0xe431('0x10')]();}};};