Built motion from commit (unavailable).|2.5.4
[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 _0x3f21=['[%s][AGENT]\x20ROUTING\x20STOPPED','complete','close','next','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack','lodash','util','../../../../config/logger','routing','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','validate','length','error','[%s][AGENT]\x20%s','map','message','join','stop','timeout','createQueue','atimeout','channel','format','START:%s','rules','end'];(function(_0x201d02,_0x16330b){var _0x549a99=function(_0x10066a){while(--_0x10066a){_0x201d02['push'](_0x201d02['shift']());}};_0x549a99(++_0x16330b);}(_0x3f21,0xcd));var _0x13f2=function(_0x4343e2,_0x346afb){_0x4343e2=_0x4343e2-0x0;var _0x402b4f=_0x3f21[_0x4343e2];return _0x402b4f;};'use strict';var schema=require('validate');var _=require(_0x13f2('0x0'));var util=require(_0x13f2('0x1'));var seqqueue=require('seq-queue');var logger=require(_0x13f2('0x2'))(_0x13f2('0x3'));var strategy=require('./strategy');var queue=schema({'name':{'type':'string','required':!![],'message':_0x13f2('0x4')},'timeout':{'type':_0x13f2('0x5'),'message':_0x13f2('0x6')}});function writeLog(_0x52c7a7,_0x259bd3,_0x5e8ca6){return logger[_0x13f2('0x7')](util['format'](_0x13f2('0x8'),_0x52c7a7,_0x259bd3['name'],_0x5e8ca6));}function handleFindAgent(_0x1a6d1c){return function(_0x3347fa){return _0x3347fa[_0x13f2('0x9')]['toLowerCase']()===_0x1a6d1c['toLowerCase']();};}exports['consequence']=function(_0x126ede,_0x46ec9b,_0x3a8295,_0x10d537){return function(_0x53611c){try{var _0x511196={'name':_0x46ec9b[0x0],'timeout':_0x46ec9b[0x1]};var _0x1c26ac=queue[_0x13f2('0xa')](_0x511196,{'typecast':!![]});if(_0x1c26ac[_0x13f2('0xb')]){logger[_0x13f2('0xc')](_0x13f2('0xd'),_0x126ede,_[_0x13f2('0xe')](_0x1c26ac,_0x13f2('0xf'))[_0x13f2('0x10')](',\x20'));_0x53611c[_0x13f2('0x11')]();}else{var _0x2a7300=_['find'](_0x3a8295['agents'],handleFindAgent(_0x511196[_0x13f2('0x9')]));if(_0x2a7300){var _0x15830b=(_0x511196[_0x13f2('0x12')]||0xa)*0x3e8;var _0x294b05,_0x42fdd2;var _0x2d58ad=seqqueue[_0x13f2('0x13')](_0x15830b);_0x2d58ad['id']=_0x126ede;_0x2d58ad[_0x13f2('0x14')]=_0x15830b;_0x2d58ad[_0x13f2('0x15')]=_0x10d537[_0x13f2('0x15')];writeLog(_0x126ede,_0x2a7300,util[_0x13f2('0x16')](_0x13f2('0x17'),_0x15830b));_0x3a8295[_0x13f2('0x18')][_0x126ede]['on'](_0x13f2('0x19'),function(){logger[_0x13f2('0x7')](_0x13f2('0x1a'),_0x126ede);clearTimeout(_0x42fdd2);_0x42fdd2=undefined;_0x2d58ad['close']();if(_0x3a8295[_0x13f2('0x18')][_0x126ede]){delete _0x3a8295[_0x13f2('0x18')][_0x126ede];}_0x53611c[_0x13f2('0x11')]();});_0x3a8295[_0x13f2('0x18')][_0x126ede]['on'](_0x13f2('0x1b'),function(){if(_0x3a8295[_0x13f2('0x18')][_0x126ede]){delete _0x3a8295['rules'][_0x126ede];}});_0x42fdd2=setTimeout(function(){logger[_0x13f2('0x7')]('[%s][AGENT]\x20ROUTING\x20END',_0x126ede);clearTimeout(_0x42fdd2);_0x2d58ad[_0x13f2('0x1c')]();_0x53611c[_0x13f2('0x1d')]();},_0x15830b);strategy['agent'](_0x2d58ad,_0x2a7300,_0x3a8295,_0x10d537);}else{logger[_0x13f2('0xc')](_0x13f2('0x1e'),_0x126ede,_0x511196[_0x13f2('0x9')]);_0x53611c[_0x13f2('0x11')]();}}}catch(_0x2845f3){console['log'](_0x2845f3);logger[_0x13f2('0xc')](_0x13f2('0x1f'),_0x126ede,_0x2845f3[_0x13f2('0x20')]);_0x53611c[_0x13f2('0x11')]();}};};