ea6c00f11656e1b160744aa9c69853139d251ff0
[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 _0x2c01=['seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','name','toLowerCase','error','message','join','stop','find','agents','timeout','createQueue','atimeout','channel','START:%s','[%s][AGENT]\x20ROUTING\x20STOPPED','close','rules','complete','[%s][AGENT]\x20ROUTING\x20END','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack','lodash'];(function(_0x397e5f,_0x454c8f){var _0x5302b8=function(_0x1a29ef){while(--_0x1a29ef){_0x397e5f['push'](_0x397e5f['shift']());}};_0x5302b8(++_0x454c8f);}(_0x2c01,0x16a));var _0x12c0=function(_0x5d8b03,_0x352fb7){_0x5d8b03=_0x5d8b03-0x0;var _0x35c323=_0x2c01[_0x5d8b03];return _0x35c323;};'use strict';var schema=require('validate');var _=require(_0x12c0('0x0'));var util=require('util');var seqqueue=require(_0x12c0('0x1'));var logger=require(_0x12c0('0x2'))(_0x12c0('0x3'));var strategy=require(_0x12c0('0x4'));var queue=schema({'name':{'type':_0x12c0('0x5'),'required':!![],'message':_0x12c0('0x6')},'timeout':{'type':_0x12c0('0x7'),'message':_0x12c0('0x8')}});function writeLog(_0x4c8428,_0x23802d,_0x525f9e){return logger[_0x12c0('0x9')](util[_0x12c0('0xa')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x4c8428,_0x23802d[_0x12c0('0xb')],_0x525f9e));}function handleFindAgent(_0x3a49e9){return function(_0x336d23){return _0x336d23['name'][_0x12c0('0xc')]()===_0x3a49e9[_0x12c0('0xc')]();};}exports['consequence']=function(_0x3bdb88,_0x16832b,_0x5805d3,_0x20da65){return function(_0x7cc7ca){try{var _0xe76bf1={'name':_0x16832b[0x0],'timeout':_0x16832b[0x1]};var _0x1411ad=queue['validate'](_0xe76bf1,{'typecast':!![]});if(_0x1411ad['length']){logger[_0x12c0('0xd')]('[%s][AGENT]\x20%s',_0x3bdb88,_['map'](_0x1411ad,_0x12c0('0xe'))[_0x12c0('0xf')](',\x20'));_0x7cc7ca[_0x12c0('0x10')]();}else{var _0x302724=_[_0x12c0('0x11')](_0x5805d3[_0x12c0('0x12')],handleFindAgent(_0xe76bf1[_0x12c0('0xb')]));if(_0x302724){var _0x4501d3=(_0xe76bf1[_0x12c0('0x13')]||0xa)*0x3e8;var _0x292c44,_0x4ab1aa;var _0x1b44d0=seqqueue[_0x12c0('0x14')](_0x4501d3);_0x1b44d0['id']=_0x3bdb88;_0x1b44d0[_0x12c0('0x15')]=_0x4501d3;_0x1b44d0[_0x12c0('0x16')]=_0x20da65[_0x12c0('0x16')];writeLog(_0x3bdb88,_0x302724,util[_0x12c0('0xa')](_0x12c0('0x17'),_0x4501d3));_0x5805d3['rules'][_0x3bdb88]['on']('end',function(){logger[_0x12c0('0x9')](_0x12c0('0x18'),_0x3bdb88);clearTimeout(_0x4ab1aa);_0x4ab1aa=undefined;_0x1b44d0[_0x12c0('0x19')]();if(_0x5805d3['rules'][_0x3bdb88]){delete _0x5805d3[_0x12c0('0x1a')][_0x3bdb88];}_0x7cc7ca[_0x12c0('0x10')]();});_0x5805d3[_0x12c0('0x1a')][_0x3bdb88]['on'](_0x12c0('0x1b'),function(){if(_0x5805d3['rules'][_0x3bdb88]){delete _0x5805d3[_0x12c0('0x1a')][_0x3bdb88];}});_0x4ab1aa=setTimeout(function(){logger[_0x12c0('0x9')](_0x12c0('0x1c'),_0x3bdb88);clearTimeout(_0x4ab1aa);_0x1b44d0['close']();_0x7cc7ca['next']();},_0x4501d3);strategy[_0x12c0('0x1d')](_0x1b44d0,_0x302724,_0x5805d3,_0x20da65);}else{logger[_0x12c0('0xd')](_0x12c0('0x1e'),_0x3bdb88,_0xe76bf1[_0x12c0('0xb')]);_0x7cc7ca[_0x12c0('0x10')]();}}}catch(_0x5df8b4){console['log'](_0x5df8b4);logger[_0x12c0('0xd')](_0x12c0('0x1f'),_0x3bdb88,_0x5df8b4[_0x12c0('0x20')]);_0x7cc7ca[_0x12c0('0x10')]();}};};