Built motion from commit (unavailable).|2.5.7
[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 _0x46d3=['stack','validate','seq-queue','../../../../config/logger','routing','./strategy','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','[%s][AGENT]\x20%s','map','message','join','stop','find','agents','timeout','createQueue','channel','START:%s','rules','[%s][AGENT]\x20ROUTING\x20STOPPED','close','[%s][AGENT]\x20ROUTING\x20END','next','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s'];(function(_0x5ec06f,_0x27b11f){var _0x24065a=function(_0x3b935d){while(--_0x3b935d){_0x5ec06f['push'](_0x5ec06f['shift']());}};_0x24065a(++_0x27b11f);}(_0x46d3,0x13c));var _0x346d=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x46d3[_0x3dd15e];return _0x231fd0;};'use strict';var schema=require(_0x346d('0x0'));var _=require('lodash');var util=require('util');var seqqueue=require(_0x346d('0x1'));var logger=require(_0x346d('0x2'))(_0x346d('0x3'));var strategy=require(_0x346d('0x4'));var queue=schema({'name':{'type':'string','required':!![],'message':_0x346d('0x5')},'timeout':{'type':_0x346d('0x6'),'message':_0x346d('0x7')}});function writeLog(_0x4dc5c2,_0x36116f,_0x3ad22b){return logger[_0x346d('0x8')](util[_0x346d('0x9')](_0x346d('0xa'),_0x4dc5c2,_0x36116f[_0x346d('0xb')],_0x3ad22b));}function handleFindAgent(_0x29ebbf){return function(_0x2f2754){return _0x2f2754[_0x346d('0xb')]['toLowerCase']()===_0x29ebbf[_0x346d('0xc')]();};}exports[_0x346d('0xd')]=function(_0x4c2c49,_0x1c61cb,_0xf9060b,_0x54e5ee){return function(_0x1fd562){try{var _0x3b154f={'name':_0x1c61cb[0x0],'timeout':_0x1c61cb[0x1]};var _0x4c40c6=queue[_0x346d('0x0')](_0x3b154f,{'typecast':!![]});if(_0x4c40c6[_0x346d('0xe')]){logger['error'](_0x346d('0xf'),_0x4c2c49,_[_0x346d('0x10')](_0x4c40c6,_0x346d('0x11'))[_0x346d('0x12')](',\x20'));_0x1fd562[_0x346d('0x13')]();}else{var _0x4c984a=_[_0x346d('0x14')](_0xf9060b[_0x346d('0x15')],handleFindAgent(_0x3b154f[_0x346d('0xb')]));if(_0x4c984a){var _0xcbd0f1=(_0x3b154f[_0x346d('0x16')]||0xa)*0x3e8;var _0x3430d0,_0xfff7f0;var _0x17d6b6=seqqueue[_0x346d('0x17')](_0xcbd0f1);_0x17d6b6['id']=_0x4c2c49;_0x17d6b6['atimeout']=_0xcbd0f1;_0x17d6b6[_0x346d('0x18')]=_0x54e5ee[_0x346d('0x18')];writeLog(_0x4c2c49,_0x4c984a,util[_0x346d('0x9')](_0x346d('0x19'),_0xcbd0f1));_0xf9060b[_0x346d('0x1a')][_0x4c2c49]['on']('end',function(){logger['info'](_0x346d('0x1b'),_0x4c2c49);clearTimeout(_0xfff7f0);_0xfff7f0=undefined;_0x17d6b6[_0x346d('0x1c')]();if(_0xf9060b[_0x346d('0x1a')][_0x4c2c49]){delete _0xf9060b[_0x346d('0x1a')][_0x4c2c49];}_0x1fd562['stop']();});_0xf9060b['rules'][_0x4c2c49]['on']('complete',function(){if(_0xf9060b[_0x346d('0x1a')][_0x4c2c49]){delete _0xf9060b['rules'][_0x4c2c49];}});_0xfff7f0=setTimeout(function(){logger['info'](_0x346d('0x1d'),_0x4c2c49);clearTimeout(_0xfff7f0);_0x17d6b6[_0x346d('0x1c')]();_0x1fd562[_0x346d('0x1e')]();},_0xcbd0f1);strategy['agent'](_0x17d6b6,_0x4c984a,_0xf9060b,_0x54e5ee);}else{logger['error'](_0x346d('0x1f'),_0x4c2c49,_0x3b154f[_0x346d('0xb')]);_0x1fd562[_0x346d('0x13')]();}}}catch(_0x18ff47){console[_0x346d('0x20')](_0x18ff47);logger['error'](_0x346d('0x21'),_0x4c2c49,_0x18ff47[_0x346d('0x22')]);_0x1fd562['stop']();}};};