e7644a502bfeb1e7e6e180e756fd144776401e1a
[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 _0x226c=['[%s][AGENT]\x20%s','map','message','join','stop','find','agents','timeout','createQueue','atimeout','channel','START:%s','rules','complete','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','seq-queue','./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'];(function(_0x22635a,_0x408f8d){var _0x588b2d=function(_0x12a8fa){while(--_0x12a8fa){_0x22635a['push'](_0x22635a['shift']());}};_0x588b2d(++_0x408f8d);}(_0x226c,0x1d2));var _0xc226=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x226c[_0x3b380d];return _0x54502b;};'use strict';var schema=require(_0xc226('0x0'));var _=require('lodash');var util=require('util');var seqqueue=require(_0xc226('0x1'));var logger=require('../../../../config/logger')('routing');var strategy=require(_0xc226('0x2'));var queue=schema({'name':{'type':_0xc226('0x3'),'required':!![],'message':_0xc226('0x4')},'timeout':{'type':_0xc226('0x5'),'message':_0xc226('0x6')}});function writeLog(_0x476b9a,_0xec8bab,_0xd79af5){return logger[_0xc226('0x7')](util[_0xc226('0x8')](_0xc226('0x9'),_0x476b9a,_0xec8bab['name'],_0xd79af5));}function handleFindAgent(_0x5d548b){return function(_0x5b9c04){return _0x5b9c04[_0xc226('0xa')][_0xc226('0xb')]()===_0x5d548b[_0xc226('0xb')]();};}exports[_0xc226('0xc')]=function(_0x2b8b75,_0x1fde59,_0x44e371,_0x4901ba){return function(_0x3294c0){try{var _0x5301e5={'name':_0x1fde59[0x0],'timeout':_0x1fde59[0x1]};var _0x3ed20d=queue[_0xc226('0x0')](_0x5301e5,{'typecast':!![]});if(_0x3ed20d[_0xc226('0xd')]){logger[_0xc226('0xe')](_0xc226('0xf'),_0x2b8b75,_[_0xc226('0x10')](_0x3ed20d,_0xc226('0x11'))[_0xc226('0x12')](',\x20'));_0x3294c0[_0xc226('0x13')]();}else{var _0x5dcb49=_[_0xc226('0x14')](_0x44e371[_0xc226('0x15')],handleFindAgent(_0x5301e5[_0xc226('0xa')]));if(_0x5dcb49){var _0x31e537=(_0x5301e5[_0xc226('0x16')]||0xa)*0x3e8;var _0x4b3360,_0x1432e7;var _0x293374=seqqueue[_0xc226('0x17')](_0x31e537);_0x293374['id']=_0x2b8b75;_0x293374[_0xc226('0x18')]=_0x31e537;_0x293374[_0xc226('0x19')]=_0x4901ba[_0xc226('0x19')];writeLog(_0x2b8b75,_0x5dcb49,util[_0xc226('0x8')](_0xc226('0x1a'),_0x31e537));_0x44e371[_0xc226('0x1b')][_0x2b8b75]['on']('end',function(){logger[_0xc226('0x7')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x2b8b75);clearTimeout(_0x1432e7);_0x1432e7=undefined;_0x293374['close']();if(_0x44e371[_0xc226('0x1b')][_0x2b8b75]){delete _0x44e371[_0xc226('0x1b')][_0x2b8b75];}_0x3294c0[_0xc226('0x13')]();});_0x44e371[_0xc226('0x1b')][_0x2b8b75]['on'](_0xc226('0x1c'),function(){if(_0x44e371[_0xc226('0x1b')][_0x2b8b75]){delete _0x44e371[_0xc226('0x1b')][_0x2b8b75];}});_0x1432e7=setTimeout(function(){logger[_0xc226('0x7')](_0xc226('0x1d'),_0x2b8b75);clearTimeout(_0x1432e7);_0x293374[_0xc226('0x1e')]();_0x3294c0[_0xc226('0x1f')]();},_0x31e537);strategy[_0xc226('0x20')](_0x293374,_0x5dcb49,_0x44e371,_0x4901ba);}else{logger[_0xc226('0xe')](_0xc226('0x21'),_0x2b8b75,_0x5301e5[_0xc226('0xa')]);_0x3294c0[_0xc226('0x13')]();}}}catch(_0xd8bedc){console[_0xc226('0x22')](_0xd8bedc);logger['error'](_0xc226('0x23'),_0x2b8b75,_0xd8bedc[_0xc226('0x24')]);_0x3294c0[_0xc226('0x13')]();}};};