83d1f77a2fc60579d97e3f71fc970955fd7c3484
[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 _0xa9fe=['util','seq-queue','routing','./strategy','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','[%s][AGENT]\x20%s','map','message','join','stop','agents','timeout','atimeout','channel','format','START:%s','rules','end','close','complete','[%s][AGENT]\x20ROUTING\x20END','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','lodash'];(function(_0x4c6ad2,_0x51092b){var _0x215c13=function(_0xf76c84){while(--_0xf76c84){_0x4c6ad2['push'](_0x4c6ad2['shift']());}};_0x215c13(++_0x51092b);}(_0xa9fe,0xae));var _0xea9f=function(_0x571e38,_0x5134eb){_0x571e38=_0x571e38-0x0;var _0x6fc2b5=_0xa9fe[_0x571e38];return _0x6fc2b5;};'use strict';var schema=require('validate');var _=require(_0xea9f('0x0'));var util=require(_0xea9f('0x1'));var seqqueue=require(_0xea9f('0x2'));var logger=require('../../../../config/logger')(_0xea9f('0x3'));var strategy=require(_0xea9f('0x4'));var queue=schema({'name':{'type':'string','required':!![],'message':_0xea9f('0x5')},'timeout':{'type':_0xea9f('0x6'),'message':_0xea9f('0x7')}});function writeLog(_0x319b99,_0x30dbc1,_0x11fed3){return logger[_0xea9f('0x8')](util['format'](_0xea9f('0x9'),_0x319b99,_0x30dbc1[_0xea9f('0xa')],_0x11fed3));}function handleFindAgent(_0x2f99b4){return function(_0x3d4a8c){return _0x3d4a8c[_0xea9f('0xa')][_0xea9f('0xb')]()===_0x2f99b4['toLowerCase']();};}exports['consequence']=function(_0x57743,_0x362d03,_0x5991a4,_0x18d55f){return function(_0x3f74bf){try{var _0x5e1ffb={'name':_0x362d03[0x0],'timeout':_0x362d03[0x1]};var _0x4afc3d=queue[_0xea9f('0xc')](_0x5e1ffb,{'typecast':!![]});if(_0x4afc3d[_0xea9f('0xd')]){logger[_0xea9f('0xe')](_0xea9f('0xf'),_0x57743,_[_0xea9f('0x10')](_0x4afc3d,_0xea9f('0x11'))[_0xea9f('0x12')](',\x20'));_0x3f74bf[_0xea9f('0x13')]();}else{var _0xf8f02=_['find'](_0x5991a4[_0xea9f('0x14')],handleFindAgent(_0x5e1ffb[_0xea9f('0xa')]));if(_0xf8f02){var _0x5f575b=(_0x5e1ffb[_0xea9f('0x15')]||0xa)*0x3e8;var _0x24f154,_0x38287d;var _0x2c610f=seqqueue['createQueue'](_0x5f575b);_0x2c610f['id']=_0x57743;_0x2c610f[_0xea9f('0x16')]=_0x5f575b;_0x2c610f['channel']=_0x18d55f[_0xea9f('0x17')];writeLog(_0x57743,_0xf8f02,util[_0xea9f('0x18')](_0xea9f('0x19'),_0x5f575b));_0x5991a4[_0xea9f('0x1a')][_0x57743]['on'](_0xea9f('0x1b'),function(){logger[_0xea9f('0x8')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x57743);clearTimeout(_0x38287d);_0x38287d=undefined;_0x2c610f[_0xea9f('0x1c')]();if(_0x5991a4[_0xea9f('0x1a')][_0x57743]){delete _0x5991a4[_0xea9f('0x1a')][_0x57743];}_0x3f74bf[_0xea9f('0x13')]();});_0x5991a4[_0xea9f('0x1a')][_0x57743]['on'](_0xea9f('0x1d'),function(){if(_0x5991a4['rules'][_0x57743]){delete _0x5991a4['rules'][_0x57743];}});_0x38287d=setTimeout(function(){logger['info'](_0xea9f('0x1e'),_0x57743);clearTimeout(_0x38287d);_0x2c610f['close']();_0x3f74bf['next']();},_0x5f575b);strategy[_0xea9f('0x1f')](_0x2c610f,_0xf8f02,_0x5991a4,_0x18d55f);}else{logger[_0xea9f('0xe')](_0xea9f('0x20'),_0x57743,_0x5e1ffb[_0xea9f('0xa')]);_0x3f74bf[_0xea9f('0x13')]();}}}catch(_0x1e96ea){console[_0xea9f('0x21')](_0x1e96ea);logger['error'](_0xea9f('0x22'),_0x57743,_0x1e96ea['stack']);_0x3f74bf['stop']();}};};