Built motion from commit (unavailable).|2.5.2
[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 _0x0ad1=['validate','lodash','seq-queue','../../../../config/logger','routing','./strategy','number','timeout\x20is\x20a\x20number','info','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','map','message','join','find','agents','createQueue','atimeout','channel','rules','end','close','stop','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack'];(function(_0x26a44e,_0x76ab98){var _0x3ee6dd=function(_0x39cb){while(--_0x39cb){_0x26a44e['push'](_0x26a44e['shift']());}};_0x3ee6dd(++_0x76ab98);}(_0x0ad1,0xaa));var _0x10ad=function(_0x4c3e81,_0x282c49){_0x4c3e81=_0x4c3e81-0x0;var _0x3b1aba=_0x0ad1[_0x4c3e81];return _0x3b1aba;};'use strict';var schema=require(_0x10ad('0x0'));var _=require(_0x10ad('0x1'));var util=require('util');var seqqueue=require(_0x10ad('0x2'));var logger=require(_0x10ad('0x3'))(_0x10ad('0x4'));var strategy=require(_0x10ad('0x5'));var queue=schema({'name':{'type':'string','required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0x10ad('0x6'),'message':_0x10ad('0x7')}});function writeLog(_0x1b2b08,_0x23522a,_0x96109c){return logger[_0x10ad('0x8')](util['format']('[%s][AGENT][NAME:%s][STATUS:%s]',_0x1b2b08,_0x23522a[_0x10ad('0x9')],_0x96109c));}function handleFindAgent(_0x2107c0){return function(_0x31f451){return _0x31f451[_0x10ad('0x9')][_0x10ad('0xa')]()===_0x2107c0[_0x10ad('0xa')]();};}exports[_0x10ad('0xb')]=function(_0x47ab29,_0x17dfa6,_0x59e45a,_0x1364c9){return function(_0x2ec0dd){try{var _0xb466cb={'name':_0x17dfa6[0x0],'timeout':_0x17dfa6[0x1]};var _0x549607=queue['validate'](_0xb466cb,{'typecast':!![]});if(_0x549607[_0x10ad('0xc')]){logger[_0x10ad('0xd')](_0x10ad('0xe'),_0x47ab29,_[_0x10ad('0xf')](_0x549607,_0x10ad('0x10'))[_0x10ad('0x11')](',\x20'));_0x2ec0dd['stop']();}else{var _0x51837c=_[_0x10ad('0x12')](_0x59e45a[_0x10ad('0x13')],handleFindAgent(_0xb466cb[_0x10ad('0x9')]));if(_0x51837c){var _0xf5c6dd=(_0xb466cb['timeout']||0xa)*0x3e8;var _0x29130c,_0x29a448;var _0x51462e=seqqueue[_0x10ad('0x14')](_0xf5c6dd);_0x51462e['id']=_0x47ab29;_0x51462e[_0x10ad('0x15')]=_0xf5c6dd;_0x51462e[_0x10ad('0x16')]=_0x1364c9[_0x10ad('0x16')];writeLog(_0x47ab29,_0x51837c,util['format']('START:%s',_0xf5c6dd));_0x59e45a[_0x10ad('0x17')][_0x47ab29]['on'](_0x10ad('0x18'),function(){logger[_0x10ad('0x8')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x47ab29);clearTimeout(_0x29a448);_0x29a448=undefined;_0x51462e[_0x10ad('0x19')]();if(_0x59e45a[_0x10ad('0x17')][_0x47ab29]){delete _0x59e45a[_0x10ad('0x17')][_0x47ab29];}_0x2ec0dd[_0x10ad('0x1a')]();});_0x59e45a[_0x10ad('0x17')][_0x47ab29]['on']('complete',function(){if(_0x59e45a[_0x10ad('0x17')][_0x47ab29]){delete _0x59e45a[_0x10ad('0x17')][_0x47ab29];}});_0x29a448=setTimeout(function(){logger[_0x10ad('0x8')](_0x10ad('0x1b'),_0x47ab29);clearTimeout(_0x29a448);_0x51462e[_0x10ad('0x19')]();_0x2ec0dd[_0x10ad('0x1c')]();},_0xf5c6dd);strategy[_0x10ad('0x1d')](_0x51462e,_0x51837c,_0x59e45a,_0x1364c9);}else{logger[_0x10ad('0xd')](_0x10ad('0x1e'),_0x47ab29,_0xb466cb['name']);_0x2ec0dd[_0x10ad('0x1a')]();}}}catch(_0x38930e){console[_0x10ad('0x1f')](_0x38930e);logger[_0x10ad('0xd')](_0x10ad('0x20'),_0x47ab29,_0x38930e[_0x10ad('0x21')]);_0x2ec0dd['stop']();}};};