a460683ae0cd9af3db22490a8ce694551e1e5846
[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 _0x1c6d=['log','[%s][QUEUE]\x20%s','stack','lodash','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]','name','toLowerCase','consequence','length','error','map','message','join','stop','find','agents','timeout','createQueue','channel','START:%s','rules','close','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s'];(function(_0x5762a3,_0x347892){var _0x1215b6=function(_0x57fbd9){while(--_0x57fbd9){_0x5762a3['push'](_0x5762a3['shift']());}};_0x1215b6(++_0x347892);}(_0x1c6d,0xff));var _0xd1c6=function(_0x4e9a22,_0x65e645){_0x4e9a22=_0x4e9a22-0x0;var _0x364420=_0x1c6d[_0x4e9a22];return _0x364420;};'use strict';var schema=require('validate');var _=require(_0xd1c6('0x0'));var util=require(_0xd1c6('0x1'));var seqqueue=require(_0xd1c6('0x2'));var logger=require(_0xd1c6('0x3'))(_0xd1c6('0x4'));var strategy=require(_0xd1c6('0x5'));var queue=schema({'name':{'type':_0xd1c6('0x6'),'required':!![],'message':_0xd1c6('0x7')},'timeout':{'type':_0xd1c6('0x8'),'message':_0xd1c6('0x9')}});function writeLog(_0x561126,_0x4dfcc6,_0x46cf4d){return logger[_0xd1c6('0xa')](util[_0xd1c6('0xb')](_0xd1c6('0xc'),_0x561126,_0x4dfcc6[_0xd1c6('0xd')],_0x46cf4d));}function handleFindAgent(_0x5ee9e6){return function(_0x504e39){return _0x504e39[_0xd1c6('0xd')][_0xd1c6('0xe')]()===_0x5ee9e6[_0xd1c6('0xe')]();};}exports[_0xd1c6('0xf')]=function(_0x4a3cc3,_0x8a5425,_0x53ccda,_0x45b278){return function(_0x3a911d){try{var _0x1b55d7={'name':_0x8a5425[0x0],'timeout':_0x8a5425[0x1]};var _0x3b6fea=queue['validate'](_0x1b55d7,{'typecast':!![]});if(_0x3b6fea[_0xd1c6('0x10')]){logger[_0xd1c6('0x11')]('[%s][AGENT]\x20%s',_0x4a3cc3,_[_0xd1c6('0x12')](_0x3b6fea,_0xd1c6('0x13'))[_0xd1c6('0x14')](',\x20'));_0x3a911d[_0xd1c6('0x15')]();}else{var _0x33bae7=_[_0xd1c6('0x16')](_0x53ccda[_0xd1c6('0x17')],handleFindAgent(_0x1b55d7[_0xd1c6('0xd')]));if(_0x33bae7){var _0x2cdd1d=(_0x1b55d7[_0xd1c6('0x18')]||0xa)*0x3e8;var _0xa306bf,_0x300a48;var _0x2ecdc4=seqqueue[_0xd1c6('0x19')](_0x2cdd1d);_0x2ecdc4['id']=_0x4a3cc3;_0x2ecdc4['atimeout']=_0x2cdd1d;_0x2ecdc4[_0xd1c6('0x1a')]=_0x45b278[_0xd1c6('0x1a')];writeLog(_0x4a3cc3,_0x33bae7,util[_0xd1c6('0xb')](_0xd1c6('0x1b'),_0x2cdd1d));_0x53ccda[_0xd1c6('0x1c')][_0x4a3cc3]['on']('end',function(){logger[_0xd1c6('0xa')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x4a3cc3);clearTimeout(_0x300a48);_0x300a48=undefined;_0x2ecdc4[_0xd1c6('0x1d')]();if(_0x53ccda[_0xd1c6('0x1c')][_0x4a3cc3]){delete _0x53ccda[_0xd1c6('0x1c')][_0x4a3cc3];}_0x3a911d[_0xd1c6('0x15')]();});_0x53ccda['rules'][_0x4a3cc3]['on']('complete',function(){if(_0x53ccda[_0xd1c6('0x1c')][_0x4a3cc3]){delete _0x53ccda[_0xd1c6('0x1c')][_0x4a3cc3];}});_0x300a48=setTimeout(function(){logger[_0xd1c6('0xa')]('[%s][AGENT]\x20ROUTING\x20END',_0x4a3cc3);clearTimeout(_0x300a48);_0x2ecdc4[_0xd1c6('0x1d')]();_0x3a911d[_0xd1c6('0x1e')]();},_0x2cdd1d);strategy[_0xd1c6('0x1f')](_0x2ecdc4,_0x33bae7,_0x53ccda,_0x45b278);}else{logger[_0xd1c6('0x11')](_0xd1c6('0x20'),_0x4a3cc3,_0x1b55d7[_0xd1c6('0xd')]);_0x3a911d[_0xd1c6('0x15')]();}}}catch(_0xe4e49c){console[_0xd1c6('0x21')](_0xe4e49c);logger[_0xd1c6('0x11')](_0xd1c6('0x22'),_0x4a3cc3,_0xe4e49c[_0xd1c6('0x23')]);_0x3a911d['stop']();}};};