6d1b3acc39a886eab38e08b739236a9927b3d6ce
[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 _0xd627=['util','seq-queue','../../../../config/logger','routing','./strategy','string','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','validate','length','error','message','join','stop','find','agents','timeout','createQueue','atimeout','channel','format','START:%s','rules','end','complete','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack'];(function(_0x1a251d,_0x2da78d){var _0x4b16d0=function(_0x5e450a){while(--_0x5e450a){_0x1a251d['push'](_0x1a251d['shift']());}};_0x4b16d0(++_0x2da78d);}(_0xd627,0x1bc));var _0x7d62=function(_0x48c2ae,_0x4cea90){_0x48c2ae=_0x48c2ae-0x0;var _0x8f7531=_0xd627[_0x48c2ae];return _0x8f7531;};'use strict';var schema=require('validate');var _=require('lodash');var util=require(_0x7d62('0x0'));var seqqueue=require(_0x7d62('0x1'));var logger=require(_0x7d62('0x2'))(_0x7d62('0x3'));var strategy=require(_0x7d62('0x4'));var queue=schema({'name':{'type':_0x7d62('0x5'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0x7d62('0x6'),'message':_0x7d62('0x7')}});function writeLog(_0x39684c,_0x1d553f,_0x8f720b){return logger[_0x7d62('0x8')](util['format'](_0x7d62('0x9'),_0x39684c,_0x1d553f[_0x7d62('0xa')],_0x8f720b));}function handleFindAgent(_0x3b87a0){return function(_0x9b5f1a){return _0x9b5f1a[_0x7d62('0xa')][_0x7d62('0xb')]()===_0x3b87a0[_0x7d62('0xb')]();};}exports[_0x7d62('0xc')]=function(_0x275037,_0x6379ad,_0x13394a,_0x3bc587){return function(_0x30bbb6){try{var _0x115dee={'name':_0x6379ad[0x0],'timeout':_0x6379ad[0x1]};var _0x102601=queue[_0x7d62('0xd')](_0x115dee,{'typecast':!![]});if(_0x102601[_0x7d62('0xe')]){logger[_0x7d62('0xf')]('[%s][AGENT]\x20%s',_0x275037,_['map'](_0x102601,_0x7d62('0x10'))[_0x7d62('0x11')](',\x20'));_0x30bbb6[_0x7d62('0x12')]();}else{var _0x594db=_[_0x7d62('0x13')](_0x13394a[_0x7d62('0x14')],handleFindAgent(_0x115dee[_0x7d62('0xa')]));if(_0x594db){var _0x125cc7=(_0x115dee[_0x7d62('0x15')]||0xa)*0x3e8;var _0x548302,_0x377833;var _0x36d3bf=seqqueue[_0x7d62('0x16')](_0x125cc7);_0x36d3bf['id']=_0x275037;_0x36d3bf[_0x7d62('0x17')]=_0x125cc7;_0x36d3bf['channel']=_0x3bc587[_0x7d62('0x18')];writeLog(_0x275037,_0x594db,util[_0x7d62('0x19')](_0x7d62('0x1a'),_0x125cc7));_0x13394a[_0x7d62('0x1b')][_0x275037]['on'](_0x7d62('0x1c'),function(){logger['info']('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x275037);clearTimeout(_0x377833);_0x377833=undefined;_0x36d3bf['close']();if(_0x13394a[_0x7d62('0x1b')][_0x275037]){delete _0x13394a[_0x7d62('0x1b')][_0x275037];}_0x30bbb6[_0x7d62('0x12')]();});_0x13394a[_0x7d62('0x1b')][_0x275037]['on'](_0x7d62('0x1d'),function(){if(_0x13394a['rules'][_0x275037]){delete _0x13394a[_0x7d62('0x1b')][_0x275037];}});_0x377833=setTimeout(function(){logger[_0x7d62('0x8')](_0x7d62('0x1e'),_0x275037);clearTimeout(_0x377833);_0x36d3bf[_0x7d62('0x1f')]();_0x30bbb6[_0x7d62('0x20')]();},_0x125cc7);strategy[_0x7d62('0x21')](_0x36d3bf,_0x594db,_0x13394a,_0x3bc587);}else{logger[_0x7d62('0xf')](_0x7d62('0x22'),_0x275037,_0x115dee['name']);_0x30bbb6[_0x7d62('0x12')]();}}}catch(_0x455cc0){console['log'](_0x455cc0);logger[_0x7d62('0xf')](_0x7d62('0x23'),_0x275037,_0x455cc0[_0x7d62('0x24')]);_0x30bbb6[_0x7d62('0x12')]();}};};