Built motion from commit 538092ac.|2.6.10
[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 _0x76f7=['find','timeout','createQueue','channel','START:%s','rules','[%s][AGENT]\x20ROUTING\x20STOPPED','close','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','lodash','util','seq-queue','../../../../config/logger','routing','string','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','validate','length','error','[%s][AGENT]\x20%s','message','join','stop'];(function(_0x128119,_0x2ec797){var _0x5c5e78=function(_0x51faa0){while(--_0x51faa0){_0x128119['push'](_0x128119['shift']());}};_0x5c5e78(++_0x2ec797);}(_0x76f7,0x19b));var _0x776f=function(_0x3f8da9,_0x219e40){_0x3f8da9=_0x3f8da9-0x0;var _0x17ba96=_0x76f7[_0x3f8da9];return _0x17ba96;};'use strict';var schema=require('validate');var _=require(_0x776f('0x0'));var util=require(_0x776f('0x1'));var seqqueue=require(_0x776f('0x2'));var logger=require(_0x776f('0x3'))(_0x776f('0x4'));var strategy=require('./strategy');var queue=schema({'name':{'type':_0x776f('0x5'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0x776f('0x6'),'message':_0x776f('0x7')}});function writeLog(_0x250ac0,_0x43b2b0,_0x279ff4){return logger[_0x776f('0x8')](util[_0x776f('0x9')](_0x776f('0xa'),_0x250ac0,_0x43b2b0[_0x776f('0xb')],_0x279ff4));}function handleFindAgent(_0x1a032c){return function(_0xaeff66){return _0xaeff66[_0x776f('0xb')]['toLowerCase']()===_0x1a032c[_0x776f('0xc')]();};}exports[_0x776f('0xd')]=function(_0x3f8d63,_0x48cd41,_0x2933bc,_0x1ac6d1){return function(_0x5be38e){try{var _0x2fb883={'name':_0x48cd41[0x0],'timeout':_0x48cd41[0x1]};var _0x235cde=queue[_0x776f('0xe')](_0x2fb883,{'typecast':!![]});if(_0x235cde[_0x776f('0xf')]){logger[_0x776f('0x10')](_0x776f('0x11'),_0x3f8d63,_['map'](_0x235cde,_0x776f('0x12'))[_0x776f('0x13')](',\x20'));_0x5be38e[_0x776f('0x14')]();}else{var _0x33253a=_[_0x776f('0x15')](_0x2933bc['agents'],handleFindAgent(_0x2fb883['name']));if(_0x33253a){var _0xf76eee=(_0x2fb883[_0x776f('0x16')]||0xa)*0x3e8;var _0xd2acd3,_0x2abc66;var _0x463272=seqqueue[_0x776f('0x17')](_0xf76eee);_0x463272['id']=_0x3f8d63;_0x463272['atimeout']=_0xf76eee;_0x463272[_0x776f('0x18')]=_0x1ac6d1[_0x776f('0x18')];writeLog(_0x3f8d63,_0x33253a,util['format'](_0x776f('0x19'),_0xf76eee));_0x2933bc[_0x776f('0x1a')][_0x3f8d63]['on']('end',function(){logger[_0x776f('0x8')](_0x776f('0x1b'),_0x3f8d63);clearTimeout(_0x2abc66);_0x2abc66=undefined;_0x463272[_0x776f('0x1c')]();if(_0x2933bc[_0x776f('0x1a')][_0x3f8d63]){delete _0x2933bc[_0x776f('0x1a')][_0x3f8d63];}_0x5be38e[_0x776f('0x14')]();});_0x2933bc['rules'][_0x3f8d63]['on']('complete',function(){if(_0x2933bc[_0x776f('0x1a')][_0x3f8d63]){delete _0x2933bc[_0x776f('0x1a')][_0x3f8d63];}});_0x2abc66=setTimeout(function(){logger[_0x776f('0x8')](_0x776f('0x1d'),_0x3f8d63);clearTimeout(_0x2abc66);_0x463272['close']();_0x5be38e[_0x776f('0x1e')]();},_0xf76eee);strategy[_0x776f('0x1f')](_0x463272,_0x33253a,_0x2933bc,_0x1ac6d1);}else{logger['error'](_0x776f('0x20'),_0x3f8d63,_0x2fb883['name']);_0x5be38e[_0x776f('0x14')]();}}}catch(_0x483728){console[_0x776f('0x21')](_0x483728);logger['error'](_0x776f('0x22'),_0x3f8d63,_0x483728[_0x776f('0x23')]);_0x5be38e[_0x776f('0x14')]();}};};