Built motion from commit 19a84241.|2.5.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 _0x1950=['validate','lodash','util','seq-queue','../../../../config/logger','routing','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','info','name','toLowerCase','consequence','length','error','map','message','join','stop','find','agents','timeout','createQueue','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','[%s][AGENT]\x20ROUTING\x20END','close','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','stack'];(function(_0x2d6e49,_0x41c922){var _0x4efc58=function(_0x3ca1d2){while(--_0x3ca1d2){_0x2d6e49['push'](_0x2d6e49['shift']());}};_0x4efc58(++_0x41c922);}(_0x1950,0x140));var _0x0195=function(_0x18ef3d,_0x43933e){_0x18ef3d=_0x18ef3d-0x0;var _0x31545a=_0x1950[_0x18ef3d];return _0x31545a;};'use strict';var schema=require(_0x0195('0x0'));var _=require(_0x0195('0x1'));var util=require(_0x0195('0x2'));var seqqueue=require(_0x0195('0x3'));var logger=require(_0x0195('0x4'))(_0x0195('0x5'));var strategy=require('./strategy');var queue=schema({'name':{'type':'string','required':!![],'message':_0x0195('0x6')},'timeout':{'type':_0x0195('0x7'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x564412,_0x7452f9,_0x1f152d){return logger[_0x0195('0x8')](util['format']('[%s][AGENT][NAME:%s][STATUS:%s]',_0x564412,_0x7452f9[_0x0195('0x9')],_0x1f152d));}function handleFindAgent(_0x1b8919){return function(_0x36b32c){return _0x36b32c[_0x0195('0x9')][_0x0195('0xa')]()===_0x1b8919['toLowerCase']();};}exports[_0x0195('0xb')]=function(_0x309971,_0x2f36e6,_0x5f541c,_0x2ddb1b){return function(_0x40fd9a){try{var _0x2858a0={'name':_0x2f36e6[0x0],'timeout':_0x2f36e6[0x1]};var _0xa2deb0=queue[_0x0195('0x0')](_0x2858a0,{'typecast':!![]});if(_0xa2deb0[_0x0195('0xc')]){logger[_0x0195('0xd')]('[%s][AGENT]\x20%s',_0x309971,_[_0x0195('0xe')](_0xa2deb0,_0x0195('0xf'))[_0x0195('0x10')](',\x20'));_0x40fd9a[_0x0195('0x11')]();}else{var _0x1b2dcc=_[_0x0195('0x12')](_0x5f541c[_0x0195('0x13')],handleFindAgent(_0x2858a0[_0x0195('0x9')]));if(_0x1b2dcc){var _0x33252c=(_0x2858a0[_0x0195('0x14')]||0xa)*0x3e8;var _0x3d391a,_0x1b6782;var _0x312ffd=seqqueue[_0x0195('0x15')](_0x33252c);_0x312ffd['id']=_0x309971;_0x312ffd['atimeout']=_0x33252c;_0x312ffd[_0x0195('0x16')]=_0x2ddb1b[_0x0195('0x16')];writeLog(_0x309971,_0x1b2dcc,util['format'](_0x0195('0x17'),_0x33252c));_0x5f541c[_0x0195('0x18')][_0x309971]['on'](_0x0195('0x19'),function(){logger['info'](_0x0195('0x1a'),_0x309971);clearTimeout(_0x1b6782);_0x1b6782=undefined;_0x312ffd['close']();if(_0x5f541c['rules'][_0x309971]){delete _0x5f541c[_0x0195('0x18')][_0x309971];}_0x40fd9a[_0x0195('0x11')]();});_0x5f541c[_0x0195('0x18')][_0x309971]['on']('complete',function(){if(_0x5f541c['rules'][_0x309971]){delete _0x5f541c[_0x0195('0x18')][_0x309971];}});_0x1b6782=setTimeout(function(){logger['info'](_0x0195('0x1b'),_0x309971);clearTimeout(_0x1b6782);_0x312ffd[_0x0195('0x1c')]();_0x40fd9a['next']();},_0x33252c);strategy['agent'](_0x312ffd,_0x1b2dcc,_0x5f541c,_0x2ddb1b);}else{logger[_0x0195('0xd')](_0x0195('0x1d'),_0x309971,_0x2858a0['name']);_0x40fd9a[_0x0195('0x11')]();}}}catch(_0xda85d8){console[_0x0195('0x1e')](_0xda85d8);logger['error']('[%s][QUEUE]\x20%s',_0x309971,_0xda85d8[_0x0195('0x1f')]);_0x40fd9a[_0x0195('0x11')]();}};};