525a5919788dce153a4c04e3f8780c4e3ccdff90
[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 _0x81c2=['length','[%s][AGENT]\x20%s','map','join','stop','find','agents','timeout','channel','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','error','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','seq-queue','../../../../config/logger','routing','./strategy','string','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence'];(function(_0x62ae03,_0xe5a1d2){var _0x335278=function(_0x373cc3){while(--_0x373cc3){_0x62ae03['push'](_0x62ae03['shift']());}};_0x335278(++_0xe5a1d2);}(_0x81c2,0xee));var _0x281c=function(_0x3ca29d,_0x5a8d31){_0x3ca29d=_0x3ca29d-0x0;var _0x5c5d2e=_0x81c2[_0x3ca29d];return _0x5c5d2e;};'use strict';var schema=require(_0x281c('0x0'));var _=require('lodash');var util=require('util');var seqqueue=require(_0x281c('0x1'));var logger=require(_0x281c('0x2'))(_0x281c('0x3'));var strategy=require(_0x281c('0x4'));var queue=schema({'name':{'type':_0x281c('0x5'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0x281c('0x6'),'message':_0x281c('0x7')}});function writeLog(_0x1b5147,_0x39ae60,_0x1bc2cd){return logger[_0x281c('0x8')](util[_0x281c('0x9')](_0x281c('0xa'),_0x1b5147,_0x39ae60[_0x281c('0xb')],_0x1bc2cd));}function handleFindAgent(_0x10d919){return function(_0x292824){return _0x292824[_0x281c('0xb')][_0x281c('0xc')]()===_0x10d919['toLowerCase']();};}exports[_0x281c('0xd')]=function(_0x313b57,_0x182aac,_0x1a2a3e,_0x35d28e){return function(_0x484241){try{var _0x2faa18={'name':_0x182aac[0x0],'timeout':_0x182aac[0x1]};var _0xe6a1a4=queue[_0x281c('0x0')](_0x2faa18,{'typecast':!![]});if(_0xe6a1a4[_0x281c('0xe')]){logger['error'](_0x281c('0xf'),_0x313b57,_[_0x281c('0x10')](_0xe6a1a4,'message')[_0x281c('0x11')](',\x20'));_0x484241[_0x281c('0x12')]();}else{var _0x26f1ff=_[_0x281c('0x13')](_0x1a2a3e[_0x281c('0x14')],handleFindAgent(_0x2faa18[_0x281c('0xb')]));if(_0x26f1ff){var _0x24f4db=(_0x2faa18[_0x281c('0x15')]||0xa)*0x3e8;var _0x176ee4,_0x5ecc71;var _0x218da6=seqqueue['createQueue'](_0x24f4db);_0x218da6['id']=_0x313b57;_0x218da6['atimeout']=_0x24f4db;_0x218da6['channel']=_0x35d28e[_0x281c('0x16')];writeLog(_0x313b57,_0x26f1ff,util[_0x281c('0x9')]('START:%s',_0x24f4db));_0x1a2a3e[_0x281c('0x17')][_0x313b57]['on'](_0x281c('0x18'),function(){logger[_0x281c('0x8')](_0x281c('0x19'),_0x313b57);clearTimeout(_0x5ecc71);_0x5ecc71=undefined;_0x218da6[_0x281c('0x1a')]();if(_0x1a2a3e['rules'][_0x313b57]){delete _0x1a2a3e[_0x281c('0x17')][_0x313b57];}_0x484241[_0x281c('0x12')]();});_0x1a2a3e['rules'][_0x313b57]['on'](_0x281c('0x1b'),function(){if(_0x1a2a3e[_0x281c('0x17')][_0x313b57]){delete _0x1a2a3e['rules'][_0x313b57];}});_0x5ecc71=setTimeout(function(){logger[_0x281c('0x8')](_0x281c('0x1c'),_0x313b57);clearTimeout(_0x5ecc71);_0x218da6[_0x281c('0x1a')]();_0x484241[_0x281c('0x1d')]();},_0x24f4db);strategy[_0x281c('0x1e')](_0x218da6,_0x26f1ff,_0x1a2a3e,_0x35d28e);}else{logger[_0x281c('0x1f')](_0x281c('0x20'),_0x313b57,_0x2faa18['name']);_0x484241['stop']();}}}catch(_0x24e67c){console[_0x281c('0x21')](_0x24e67c);logger['error'](_0x281c('0x22'),_0x313b57,_0x24e67c[_0x281c('0x23')]);_0x484241[_0x281c('0x12')]();}};};