b6cef2aef9c9d920a3bcc16c06d34ec580cfac32
[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 _0x350f=['seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','map','message','join','stop','find','agents','timeout','channel','START:%s','rules','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','error','[%s][QUEUE]\x20%s','stack','validate','lodash','util'];(function(_0x37bd26,_0x5ad346){var _0xe83dc4=function(_0x1ac229){while(--_0x1ac229){_0x37bd26['push'](_0x37bd26['shift']());}};_0xe83dc4(++_0x5ad346);}(_0x350f,0x69));var _0xf350=function(_0xce93c,_0x555be5){_0xce93c=_0xce93c-0x0;var _0x230720=_0x350f[_0xce93c];return _0x230720;};'use strict';var schema=require(_0xf350('0x0'));var _=require(_0xf350('0x1'));var util=require(_0xf350('0x2'));var seqqueue=require(_0xf350('0x3'));var logger=require(_0xf350('0x4'))(_0xf350('0x5'));var strategy=require(_0xf350('0x6'));var queue=schema({'name':{'type':_0xf350('0x7'),'required':!![],'message':_0xf350('0x8')},'timeout':{'type':_0xf350('0x9'),'message':_0xf350('0xa')}});function writeLog(_0x2d7f29,_0x1ddc81,_0x14e628){return logger[_0xf350('0xb')](util[_0xf350('0xc')](_0xf350('0xd'),_0x2d7f29,_0x1ddc81[_0xf350('0xe')],_0x14e628));}function handleFindAgent(_0x2d93e8){return function(_0x2fd0d8){return _0x2fd0d8['name'][_0xf350('0xf')]()===_0x2d93e8[_0xf350('0xf')]();};}exports[_0xf350('0x10')]=function(_0x9ccc51,_0x29fb41,_0x27878e,_0x222117){return function(_0x586c6b){try{var _0x3335e3={'name':_0x29fb41[0x0],'timeout':_0x29fb41[0x1]};var _0x3dc46a=queue[_0xf350('0x0')](_0x3335e3,{'typecast':!![]});if(_0x3dc46a['length']){logger['error']('[%s][AGENT]\x20%s',_0x9ccc51,_[_0xf350('0x11')](_0x3dc46a,_0xf350('0x12'))[_0xf350('0x13')](',\x20'));_0x586c6b[_0xf350('0x14')]();}else{var _0x1f9726=_[_0xf350('0x15')](_0x27878e[_0xf350('0x16')],handleFindAgent(_0x3335e3['name']));if(_0x1f9726){var _0x1eaed2=(_0x3335e3[_0xf350('0x17')]||0xa)*0x3e8;var _0x4c1517,_0x13d3e3;var _0x6b2c7=seqqueue['createQueue'](_0x1eaed2);_0x6b2c7['id']=_0x9ccc51;_0x6b2c7['atimeout']=_0x1eaed2;_0x6b2c7[_0xf350('0x18')]=_0x222117[_0xf350('0x18')];writeLog(_0x9ccc51,_0x1f9726,util[_0xf350('0xc')](_0xf350('0x19'),_0x1eaed2));_0x27878e[_0xf350('0x1a')][_0x9ccc51]['on']('end',function(){logger['info'](_0xf350('0x1b'),_0x9ccc51);clearTimeout(_0x13d3e3);_0x13d3e3=undefined;_0x6b2c7[_0xf350('0x1c')]();if(_0x27878e[_0xf350('0x1a')][_0x9ccc51]){delete _0x27878e[_0xf350('0x1a')][_0x9ccc51];}_0x586c6b[_0xf350('0x14')]();});_0x27878e[_0xf350('0x1a')][_0x9ccc51]['on'](_0xf350('0x1d'),function(){if(_0x27878e[_0xf350('0x1a')][_0x9ccc51]){delete _0x27878e[_0xf350('0x1a')][_0x9ccc51];}});_0x13d3e3=setTimeout(function(){logger[_0xf350('0xb')](_0xf350('0x1e'),_0x9ccc51);clearTimeout(_0x13d3e3);_0x6b2c7['close']();_0x586c6b[_0xf350('0x1f')]();},_0x1eaed2);strategy[_0xf350('0x20')](_0x6b2c7,_0x1f9726,_0x27878e,_0x222117);}else{logger[_0xf350('0x21')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x9ccc51,_0x3335e3[_0xf350('0xe')]);_0x586c6b[_0xf350('0x14')]();}}}catch(_0xfb56cf){console['log'](_0xfb56cf);logger[_0xf350('0x21')](_0xf350('0x22'),_0x9ccc51,_0xfb56cf[_0xf350('0x23')]);_0x586c6b['stop']();}};};