55fc87391d84d1b74dac918d446442e08340d3d0
[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 _0x06b5=['timeout','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','complete','[%s][AGENT]\x20ROUTING\x20END','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','./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','error','[%s][AGENT]\x20%s','message','join','stop','find'];(function(_0x5399ce,_0x295a64){var _0x1c4271=function(_0xecad70){while(--_0xecad70){_0x5399ce['push'](_0x5399ce['shift']());}};_0x1c4271(++_0x295a64);}(_0x06b5,0x158));var _0x506b=function(_0x2e2484,_0x47e573){_0x2e2484=_0x2e2484-0x0;var _0x3d49e0=_0x06b5[_0x2e2484];return _0x3d49e0;};'use strict';var schema=require(_0x506b('0x0'));var _=require(_0x506b('0x1'));var util=require('util');var seqqueue=require('seq-queue');var logger=require('../../../../config/logger')('routing');var strategy=require(_0x506b('0x2'));var queue=schema({'name':{'type':_0x506b('0x3'),'required':!![],'message':_0x506b('0x4')},'timeout':{'type':_0x506b('0x5'),'message':_0x506b('0x6')}});function writeLog(_0x1143ce,_0x632730,_0x4c9ea3){return logger[_0x506b('0x7')](util[_0x506b('0x8')](_0x506b('0x9'),_0x1143ce,_0x632730[_0x506b('0xa')],_0x4c9ea3));}function handleFindAgent(_0x3e5cb7){return function(_0x452e8a){return _0x452e8a[_0x506b('0xa')][_0x506b('0xb')]()===_0x3e5cb7[_0x506b('0xb')]();};}exports[_0x506b('0xc')]=function(_0x31100e,_0x249847,_0x5a5388,_0x51db3b){return function(_0x3004ea){try{var _0xed0103={'name':_0x249847[0x0],'timeout':_0x249847[0x1]};var _0x345c79=queue['validate'](_0xed0103,{'typecast':!![]});if(_0x345c79['length']){logger[_0x506b('0xd')](_0x506b('0xe'),_0x31100e,_['map'](_0x345c79,_0x506b('0xf'))[_0x506b('0x10')](',\x20'));_0x3004ea[_0x506b('0x11')]();}else{var _0x4bb472=_[_0x506b('0x12')](_0x5a5388['agents'],handleFindAgent(_0xed0103['name']));if(_0x4bb472){var _0x3d2b6a=(_0xed0103[_0x506b('0x13')]||0xa)*0x3e8;var _0x27d049,_0x544d2f;var _0x483c03=seqqueue['createQueue'](_0x3d2b6a);_0x483c03['id']=_0x31100e;_0x483c03[_0x506b('0x14')]=_0x3d2b6a;_0x483c03['channel']=_0x51db3b[_0x506b('0x15')];writeLog(_0x31100e,_0x4bb472,util[_0x506b('0x8')](_0x506b('0x16'),_0x3d2b6a));_0x5a5388[_0x506b('0x17')][_0x31100e]['on'](_0x506b('0x18'),function(){logger[_0x506b('0x7')](_0x506b('0x19'),_0x31100e);clearTimeout(_0x544d2f);_0x544d2f=undefined;_0x483c03['close']();if(_0x5a5388[_0x506b('0x17')][_0x31100e]){delete _0x5a5388['rules'][_0x31100e];}_0x3004ea[_0x506b('0x11')]();});_0x5a5388[_0x506b('0x17')][_0x31100e]['on'](_0x506b('0x1a'),function(){if(_0x5a5388[_0x506b('0x17')][_0x31100e]){delete _0x5a5388[_0x506b('0x17')][_0x31100e];}});_0x544d2f=setTimeout(function(){logger[_0x506b('0x7')](_0x506b('0x1b'),_0x31100e);clearTimeout(_0x544d2f);_0x483c03['close']();_0x3004ea['next']();},_0x3d2b6a);strategy[_0x506b('0x1c')](_0x483c03,_0x4bb472,_0x5a5388,_0x51db3b);}else{logger['error'](_0x506b('0x1d'),_0x31100e,_0xed0103[_0x506b('0xa')]);_0x3004ea['stop']();}}}catch(_0x450262){console[_0x506b('0x1e')](_0x450262);logger[_0x506b('0xd')](_0x506b('0x1f'),_0x31100e,_0x450262[_0x506b('0x20')]);_0x3004ea[_0x506b('0x11')]();}};};