6035b2da7523e34794af418005dd7209960865c5
[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 _0xb51f=['stack','validate','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','string','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','length','[%s][AGENT]\x20%s','message','join','stop','find','agents','timeout','createQueue','atimeout','channel','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','error'];(function(_0x1fb97b,_0x15284e){var _0x3e3b3d=function(_0x393bdf){while(--_0x393bdf){_0x1fb97b['push'](_0x1fb97b['shift']());}};_0x3e3b3d(++_0x15284e);}(_0xb51f,0x6d));var _0xfb51=function(_0x1a3c28,_0x4d892e){_0x1a3c28=_0x1a3c28-0x0;var _0x259952=_0xb51f[_0x1a3c28];return _0x259952;};'use strict';var schema=require(_0xfb51('0x0'));var _=require(_0xfb51('0x1'));var util=require(_0xfb51('0x2'));var seqqueue=require(_0xfb51('0x3'));var logger=require(_0xfb51('0x4'))(_0xfb51('0x5'));var strategy=require(_0xfb51('0x6'));var queue=schema({'name':{'type':_0xfb51('0x7'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0xfb51('0x8'),'message':_0xfb51('0x9')}});function writeLog(_0x1e0033,_0x567ef8,_0x5e303b){return logger[_0xfb51('0xa')](util[_0xfb51('0xb')](_0xfb51('0xc'),_0x1e0033,_0x567ef8[_0xfb51('0xd')],_0x5e303b));}function handleFindAgent(_0x1f22d7){return function(_0x148df9){return _0x148df9[_0xfb51('0xd')]['toLowerCase']()===_0x1f22d7[_0xfb51('0xe')]();};}exports['consequence']=function(_0xfe42f5,_0x26495f,_0x31e4dd,_0x55fc5b){return function(_0x11b5e5){try{var _0x38d3c6={'name':_0x26495f[0x0],'timeout':_0x26495f[0x1]};var _0x376c58=queue[_0xfb51('0x0')](_0x38d3c6,{'typecast':!![]});if(_0x376c58[_0xfb51('0xf')]){logger['error'](_0xfb51('0x10'),_0xfe42f5,_['map'](_0x376c58,_0xfb51('0x11'))[_0xfb51('0x12')](',\x20'));_0x11b5e5[_0xfb51('0x13')]();}else{var _0x12d050=_[_0xfb51('0x14')](_0x31e4dd[_0xfb51('0x15')],handleFindAgent(_0x38d3c6[_0xfb51('0xd')]));if(_0x12d050){var _0x1dc4a3=(_0x38d3c6[_0xfb51('0x16')]||0xa)*0x3e8;var _0x5ddf75,_0x4a67c9;var _0x2e1ff3=seqqueue[_0xfb51('0x17')](_0x1dc4a3);_0x2e1ff3['id']=_0xfe42f5;_0x2e1ff3[_0xfb51('0x18')]=_0x1dc4a3;_0x2e1ff3[_0xfb51('0x19')]=_0x55fc5b[_0xfb51('0x19')];writeLog(_0xfe42f5,_0x12d050,util[_0xfb51('0xb')]('START:%s',_0x1dc4a3));_0x31e4dd[_0xfb51('0x1a')][_0xfe42f5]['on'](_0xfb51('0x1b'),function(){logger['info'](_0xfb51('0x1c'),_0xfe42f5);clearTimeout(_0x4a67c9);_0x4a67c9=undefined;_0x2e1ff3[_0xfb51('0x1d')]();if(_0x31e4dd[_0xfb51('0x1a')][_0xfe42f5]){delete _0x31e4dd[_0xfb51('0x1a')][_0xfe42f5];}_0x11b5e5[_0xfb51('0x13')]();});_0x31e4dd['rules'][_0xfe42f5]['on'](_0xfb51('0x1e'),function(){if(_0x31e4dd[_0xfb51('0x1a')][_0xfe42f5]){delete _0x31e4dd['rules'][_0xfe42f5];}});_0x4a67c9=setTimeout(function(){logger[_0xfb51('0xa')](_0xfb51('0x1f'),_0xfe42f5);clearTimeout(_0x4a67c9);_0x2e1ff3['close']();_0x11b5e5['next']();},_0x1dc4a3);strategy['agent'](_0x2e1ff3,_0x12d050,_0x31e4dd,_0x55fc5b);}else{logger['error'](_0xfb51('0x20'),_0xfe42f5,_0x38d3c6[_0xfb51('0xd')]);_0x11b5e5[_0xfb51('0x13')]();}}}catch(_0x439203){console[_0xfb51('0x21')](_0x439203);logger[_0xfb51('0x22')]('[%s][QUEUE]\x20%s',_0xfe42f5,_0x439203[_0xfb51('0x23')]);_0x11b5e5[_0xfb51('0x13')]();}};};