Built motion from commit (unavailable).|2.4.4
[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 _0x563d=['agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack','validate','util','seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','toLowerCase','consequence','length','error','map','message','join','stop','find','agents','name','createQueue','channel','START:%s','rules','end','close','[%s][AGENT]\x20ROUTING\x20STOPPED'];(function(_0x1842e4,_0x4b67d5){var _0x456a40=function(_0x5058d5){while(--_0x5058d5){_0x1842e4['push'](_0x1842e4['shift']());}};_0x456a40(++_0x4b67d5);}(_0x563d,0xb3));var _0xd563=function(_0x19dd7a,_0x51de21){_0x19dd7a=_0x19dd7a-0x0;var _0x3feb6a=_0x563d[_0x19dd7a];return _0x3feb6a;};'use strict';var schema=require(_0xd563('0x0'));var _=require('lodash');var util=require(_0xd563('0x1'));var seqqueue=require(_0xd563('0x2'));var logger=require(_0xd563('0x3'))(_0xd563('0x4'));var strategy=require(_0xd563('0x5'));var queue=schema({'name':{'type':_0xd563('0x6'),'required':!![],'message':_0xd563('0x7')},'timeout':{'type':_0xd563('0x8'),'message':_0xd563('0x9')}});function writeLog(_0x1dd776,_0x4aeea0,_0x119bbe){return logger[_0xd563('0xa')](util[_0xd563('0xb')](_0xd563('0xc'),_0x1dd776,_0x4aeea0['name'],_0x119bbe));}function handleFindAgent(_0x222c7b){return function(_0x447889){return _0x447889['name']['toLowerCase']()===_0x222c7b[_0xd563('0xd')]();};}exports[_0xd563('0xe')]=function(_0xe945f4,_0x57e97c,_0x5ccbbe,_0xa0bace){return function(_0x291f70){try{var _0x4a3be2={'name':_0x57e97c[0x0],'timeout':_0x57e97c[0x1]};var _0x531e98=queue[_0xd563('0x0')](_0x4a3be2,{'typecast':!![]});if(_0x531e98[_0xd563('0xf')]){logger[_0xd563('0x10')]('[%s][AGENT]\x20%s',_0xe945f4,_[_0xd563('0x11')](_0x531e98,_0xd563('0x12'))[_0xd563('0x13')](',\x20'));_0x291f70[_0xd563('0x14')]();}else{var _0x17f3d4=_[_0xd563('0x15')](_0x5ccbbe[_0xd563('0x16')],handleFindAgent(_0x4a3be2[_0xd563('0x17')]));if(_0x17f3d4){var _0x480087=(_0x4a3be2['timeout']||0xa)*0x3e8;var _0x5753eb,_0x5c32c9;var _0x44f9dd=seqqueue[_0xd563('0x18')](_0x480087);_0x44f9dd['id']=_0xe945f4;_0x44f9dd['atimeout']=_0x480087;_0x44f9dd[_0xd563('0x19')]=_0xa0bace[_0xd563('0x19')];writeLog(_0xe945f4,_0x17f3d4,util[_0xd563('0xb')](_0xd563('0x1a'),_0x480087));_0x5ccbbe[_0xd563('0x1b')][_0xe945f4]['on'](_0xd563('0x1c'),function(){_0x44f9dd[_0xd563('0x1d')]();clearTimeout(_0x5c32c9);_0x5c32c9=undefined;if(_0x5ccbbe[_0xd563('0x1b')][_0xe945f4]){delete _0x5ccbbe[_0xd563('0x1b')][_0xe945f4];}logger[_0xd563('0xa')](_0xd563('0x1e'),_0xe945f4);_0x291f70[_0xd563('0x14')]();});_0x5c32c9=setTimeout(function(){clearTimeout(_0x5c32c9);_0x44f9dd[_0xd563('0x1d')]();logger[_0xd563('0xa')]('[%s][AGENT]\x20ROUTING\x20END',_0xe945f4);_0x291f70['next']();},_0x480087);strategy[_0xd563('0x1f')](_0x44f9dd,_0x17f3d4,_0x5ccbbe,_0xa0bace);}else{logger[_0xd563('0x10')](_0xd563('0x20'),_0xe945f4,_0x4a3be2[_0xd563('0x17')]);_0x291f70[_0xd563('0x14')]();}}}catch(_0x2bcea1){console['log'](_0x2bcea1);logger[_0xd563('0x10')](_0xd563('0x21'),_0xe945f4,_0x2bcea1[_0xd563('0x22')]);_0x291f70['stop']();}};};