Built motion from commit (unavailable).|2.4.5
[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 _0xa738=['length','error','[%s][AGENT]\x20%s','map','message','join','stop','find','timeout','createQueue','atimeout','channel','format','START:%s','rules','end','close','[%s][AGENT]\x20ROUTING\x20STOPPED','next','[%s][AGENT]\x20agent\x20not\x20found\x20%s','stack','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','validate'];(function(_0xc64933,_0x1fab4c){var _0x1279db=function(_0x26e79e){while(--_0x26e79e){_0xc64933['push'](_0xc64933['shift']());}};_0x1279db(++_0x1fab4c);}(_0xa738,0x196));var _0x8a73=function(_0x2bf347,_0x5dc5bb){_0x2bf347=_0x2bf347-0x0;var _0x373799=_0xa738[_0x2bf347];return _0x373799;};'use strict';var schema=require('validate');var _=require(_0x8a73('0x0'));var util=require(_0x8a73('0x1'));var seqqueue=require(_0x8a73('0x2'));var logger=require(_0x8a73('0x3'))(_0x8a73('0x4'));var strategy=require(_0x8a73('0x5'));var queue=schema({'name':{'type':'string','required':!![],'message':_0x8a73('0x6')},'timeout':{'type':_0x8a73('0x7'),'message':_0x8a73('0x8')}});function writeLog(_0x26d3af,_0x5095ba,_0x1cab5c){return logger[_0x8a73('0x9')](util['format'](_0x8a73('0xa'),_0x26d3af,_0x5095ba[_0x8a73('0xb')],_0x1cab5c));}function handleFindAgent(_0x3ebfa7){return function(_0x3d8db6){return _0x3d8db6['name'][_0x8a73('0xc')]()===_0x3ebfa7[_0x8a73('0xc')]();};}exports['consequence']=function(_0x2059ac,_0x1dcf29,_0xbbd193,_0x5c1943){return function(_0xa3f80d){try{var _0x41c3be={'name':_0x1dcf29[0x0],'timeout':_0x1dcf29[0x1]};var _0x836ec9=queue[_0x8a73('0xd')](_0x41c3be,{'typecast':!![]});if(_0x836ec9[_0x8a73('0xe')]){logger[_0x8a73('0xf')](_0x8a73('0x10'),_0x2059ac,_[_0x8a73('0x11')](_0x836ec9,_0x8a73('0x12'))[_0x8a73('0x13')](',\x20'));_0xa3f80d[_0x8a73('0x14')]();}else{var _0x57f844=_[_0x8a73('0x15')](_0xbbd193['agents'],handleFindAgent(_0x41c3be[_0x8a73('0xb')]));if(_0x57f844){var _0x406f65=(_0x41c3be[_0x8a73('0x16')]||0xa)*0x3e8;var _0x2b82d0,_0x47a305;var _0x3450b9=seqqueue[_0x8a73('0x17')](_0x406f65);_0x3450b9['id']=_0x2059ac;_0x3450b9[_0x8a73('0x18')]=_0x406f65;_0x3450b9[_0x8a73('0x19')]=_0x5c1943[_0x8a73('0x19')];writeLog(_0x2059ac,_0x57f844,util[_0x8a73('0x1a')](_0x8a73('0x1b'),_0x406f65));_0xbbd193[_0x8a73('0x1c')][_0x2059ac]['on'](_0x8a73('0x1d'),function(){_0x3450b9[_0x8a73('0x1e')]();clearTimeout(_0x47a305);_0x47a305=undefined;if(_0xbbd193['rules'][_0x2059ac]){delete _0xbbd193['rules'][_0x2059ac];}logger[_0x8a73('0x9')](_0x8a73('0x1f'),_0x2059ac);_0xa3f80d['stop']();});_0x47a305=setTimeout(function(){clearTimeout(_0x47a305);_0x3450b9[_0x8a73('0x1e')]();logger[_0x8a73('0x9')]('[%s][AGENT]\x20ROUTING\x20END',_0x2059ac);_0xa3f80d[_0x8a73('0x20')]();},_0x406f65);strategy['agent'](_0x3450b9,_0x57f844,_0xbbd193,_0x5c1943);}else{logger[_0x8a73('0xf')](_0x8a73('0x21'),_0x2059ac,_0x41c3be[_0x8a73('0xb')]);_0xa3f80d[_0x8a73('0x14')]();}}}catch(_0x572d73){console['log'](_0x572d73);logger[_0x8a73('0xf')]('[%s][QUEUE]\x20%s',_0x2059ac,_0x572d73[_0x8a73('0x22')]);_0xa3f80d[_0x8a73('0x14')]();}};};