Built motion from commit fe909640.|2.6.8
[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 _0xaa85=['end','[%s][AGENT]\x20ROUTING\x20STOPPED','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','util','seq-queue','../../../../config/logger','routing','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','length','error','[%s][AGENT]\x20%s','map','message','join','stop','find','agents','createQueue','channel','format','rules'];(function(_0x267583,_0x2e1356){var _0x23d218=function(_0x7f2ae2){while(--_0x7f2ae2){_0x267583['push'](_0x267583['shift']());}};_0x23d218(++_0x2e1356);}(_0xaa85,0x70));var _0x5aa8=function(_0x3ab1e9,_0x48aa96){_0x3ab1e9=_0x3ab1e9-0x0;var _0x59d2c6=_0xaa85[_0x3ab1e9];return _0x59d2c6;};'use strict';var schema=require(_0x5aa8('0x0'));var _=require('lodash');var util=require(_0x5aa8('0x1'));var seqqueue=require(_0x5aa8('0x2'));var logger=require(_0x5aa8('0x3'))(_0x5aa8('0x4'));var strategy=require('./strategy');var queue=schema({'name':{'type':'string','required':!![],'message':_0x5aa8('0x5')},'timeout':{'type':_0x5aa8('0x6'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x36a7f5,_0x106e93,_0x3c2263){return logger[_0x5aa8('0x7')](util['format'](_0x5aa8('0x8'),_0x36a7f5,_0x106e93[_0x5aa8('0x9')],_0x3c2263));}function handleFindAgent(_0x528cf2){return function(_0x2a1698){return _0x2a1698['name'][_0x5aa8('0xa')]()===_0x528cf2[_0x5aa8('0xa')]();};}exports['consequence']=function(_0x2fc94b,_0x24bc2f,_0x436515,_0xe96da5){return function(_0x3faee7){try{var _0x2506dc={'name':_0x24bc2f[0x0],'timeout':_0x24bc2f[0x1]};var _0x26e620=queue[_0x5aa8('0x0')](_0x2506dc,{'typecast':!![]});if(_0x26e620[_0x5aa8('0xb')]){logger[_0x5aa8('0xc')](_0x5aa8('0xd'),_0x2fc94b,_[_0x5aa8('0xe')](_0x26e620,_0x5aa8('0xf'))[_0x5aa8('0x10')](',\x20'));_0x3faee7[_0x5aa8('0x11')]();}else{var _0x3e1bda=_[_0x5aa8('0x12')](_0x436515[_0x5aa8('0x13')],handleFindAgent(_0x2506dc['name']));if(_0x3e1bda){var _0x235e1e=(_0x2506dc['timeout']||0xa)*0x3e8;var _0x29994a,_0x4987df;var _0x3242e9=seqqueue[_0x5aa8('0x14')](_0x235e1e);_0x3242e9['id']=_0x2fc94b;_0x3242e9['atimeout']=_0x235e1e;_0x3242e9[_0x5aa8('0x15')]=_0xe96da5[_0x5aa8('0x15')];writeLog(_0x2fc94b,_0x3e1bda,util[_0x5aa8('0x16')]('START:%s',_0x235e1e));_0x436515[_0x5aa8('0x17')][_0x2fc94b]['on'](_0x5aa8('0x18'),function(){logger['info'](_0x5aa8('0x19'),_0x2fc94b);clearTimeout(_0x4987df);_0x4987df=undefined;_0x3242e9['close']();if(_0x436515[_0x5aa8('0x17')][_0x2fc94b]){delete _0x436515[_0x5aa8('0x17')][_0x2fc94b];}_0x3faee7[_0x5aa8('0x11')]();});_0x436515['rules'][_0x2fc94b]['on']('complete',function(){if(_0x436515['rules'][_0x2fc94b]){delete _0x436515[_0x5aa8('0x17')][_0x2fc94b];}});_0x4987df=setTimeout(function(){logger[_0x5aa8('0x7')](_0x5aa8('0x1a'),_0x2fc94b);clearTimeout(_0x4987df);_0x3242e9[_0x5aa8('0x1b')]();_0x3faee7[_0x5aa8('0x1c')]();},_0x235e1e);strategy[_0x5aa8('0x1d')](_0x3242e9,_0x3e1bda,_0x436515,_0xe96da5);}else{logger[_0x5aa8('0xc')](_0x5aa8('0x1e'),_0x2fc94b,_0x2506dc[_0x5aa8('0x9')]);_0x3faee7['stop']();}}}catch(_0x1acad9){console[_0x5aa8('0x1f')](_0x1acad9);logger[_0x5aa8('0xc')](_0x5aa8('0x20'),_0x2fc94b,_0x1acad9[_0x5aa8('0x21')]);_0x3faee7['stop']();}};};