5ffc985a3d5e867f0afed893873a4c3b96702266
[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 _0x8a29=['timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','consequence','validate','length','[%s][AGENT]\x20%s','map','message','join','find','agents','createQueue','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','error','[%s][QUEUE]\x20%s','stack','lodash','util','routing','./strategy','number'];(function(_0x35b18a,_0x6b2fbe){var _0x4db1bd=function(_0x389e62){while(--_0x389e62){_0x35b18a['push'](_0x35b18a['shift']());}};_0x4db1bd(++_0x6b2fbe);}(_0x8a29,0xfe));var _0x98a2=function(_0x3ff4c8,_0x2201f6){_0x3ff4c8=_0x3ff4c8-0x0;var _0x1fd97c=_0x8a29[_0x3ff4c8];return _0x1fd97c;};'use strict';var schema=require('validate');var _=require(_0x98a2('0x0'));var util=require(_0x98a2('0x1'));var seqqueue=require('seq-queue');var logger=require('../../../../config/logger')(_0x98a2('0x2'));var strategy=require(_0x98a2('0x3'));var queue=schema({'name':{'type':'string','required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0x98a2('0x4'),'message':_0x98a2('0x5')}});function writeLog(_0x489781,_0x58a15d,_0x29579d){return logger[_0x98a2('0x6')](util[_0x98a2('0x7')](_0x98a2('0x8'),_0x489781,_0x58a15d[_0x98a2('0x9')],_0x29579d));}function handleFindAgent(_0x4c377e){return function(_0x98f1c7){return _0x98f1c7[_0x98a2('0x9')]['toLowerCase']()===_0x4c377e['toLowerCase']();};}exports[_0x98a2('0xa')]=function(_0x5da1ed,_0x3f4063,_0x27d207,_0x5a280a){return function(_0x552f50){try{var _0x5720b5={'name':_0x3f4063[0x0],'timeout':_0x3f4063[0x1]};var _0x3e15c0=queue[_0x98a2('0xb')](_0x5720b5,{'typecast':!![]});if(_0x3e15c0[_0x98a2('0xc')]){logger['error'](_0x98a2('0xd'),_0x5da1ed,_[_0x98a2('0xe')](_0x3e15c0,_0x98a2('0xf'))[_0x98a2('0x10')](',\x20'));_0x552f50['stop']();}else{var _0x8b9575=_[_0x98a2('0x11')](_0x27d207[_0x98a2('0x12')],handleFindAgent(_0x5720b5[_0x98a2('0x9')]));if(_0x8b9575){var _0x2576c8=(_0x5720b5['timeout']||0xa)*0x3e8;var _0x4161c7,_0x5afd8f;var _0x4c636e=seqqueue[_0x98a2('0x13')](_0x2576c8);_0x4c636e['id']=_0x5da1ed;_0x4c636e[_0x98a2('0x14')]=_0x2576c8;_0x4c636e[_0x98a2('0x15')]=_0x5a280a['channel'];writeLog(_0x5da1ed,_0x8b9575,util['format'](_0x98a2('0x16'),_0x2576c8));_0x27d207[_0x98a2('0x17')][_0x5da1ed]['on'](_0x98a2('0x18'),function(){logger[_0x98a2('0x6')](_0x98a2('0x19'),_0x5da1ed);clearTimeout(_0x5afd8f);_0x5afd8f=undefined;_0x4c636e[_0x98a2('0x1a')]();if(_0x27d207[_0x98a2('0x17')][_0x5da1ed]){delete _0x27d207[_0x98a2('0x17')][_0x5da1ed];}_0x552f50[_0x98a2('0x1b')]();});_0x27d207[_0x98a2('0x17')][_0x5da1ed]['on'](_0x98a2('0x1c'),function(){if(_0x27d207[_0x98a2('0x17')][_0x5da1ed]){delete _0x27d207[_0x98a2('0x17')][_0x5da1ed];}});_0x5afd8f=setTimeout(function(){logger[_0x98a2('0x6')](_0x98a2('0x1d'),_0x5da1ed);clearTimeout(_0x5afd8f);_0x4c636e['close']();_0x552f50[_0x98a2('0x1e')]();},_0x2576c8);strategy[_0x98a2('0x1f')](_0x4c636e,_0x8b9575,_0x27d207,_0x5a280a);}else{logger['error'](_0x98a2('0x20'),_0x5da1ed,_0x5720b5[_0x98a2('0x9')]);_0x552f50['stop']();}}}catch(_0x3ba28a){console[_0x98a2('0x21')](_0x3ba28a);logger[_0x98a2('0x22')](_0x98a2('0x23'),_0x5da1ed,_0x3ba28a[_0x98a2('0x24')]);_0x552f50[_0x98a2('0x1b')]();}};};