Built motion from commit 192134f6.|2.6.25
[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 _0xdc75=['string','number','timeout\x20is\x20a\x20number','format','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','map','message','join','find','agents','timeout','channel','START:%s','rules','info','[%s][AGENT]\x20ROUTING\x20STOPPED','close','stop','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','../../../../config/logger','routing','./strategy'];(function(_0x237ead,_0x1869d8){var _0x3f78bf=function(_0x5a7294){while(--_0x5a7294){_0x237ead['push'](_0x237ead['shift']());}};_0x3f78bf(++_0x1869d8);}(_0xdc75,0xf5));var _0x5dc7=function(_0x2ed08e,_0x31e039){_0x2ed08e=_0x2ed08e-0x0;var _0x5d98cb=_0xdc75[_0x2ed08e];return _0x5d98cb;};'use strict';var schema=require(_0x5dc7('0x0'));var _=require(_0x5dc7('0x1'));var util=require(_0x5dc7('0x2'));var seqqueue=require(_0x5dc7('0x3'));var logger=require(_0x5dc7('0x4'))(_0x5dc7('0x5'));var strategy=require(_0x5dc7('0x6'));var queue=schema({'name':{'type':_0x5dc7('0x7'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0x5dc7('0x8'),'message':_0x5dc7('0x9')}});function writeLog(_0x5c67ae,_0x2638cf,_0xbfe309){return logger['info'](util[_0x5dc7('0xa')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x5c67ae,_0x2638cf[_0x5dc7('0xb')],_0xbfe309));}function handleFindAgent(_0x1ddc62){return function(_0x6361bd){return _0x6361bd['name'][_0x5dc7('0xc')]()===_0x1ddc62[_0x5dc7('0xc')]();};}exports[_0x5dc7('0xd')]=function(_0xcc5459,_0x5709f5,_0x233e5d,_0x2478f6){return function(_0x416ae5){try{var _0x48168f={'name':_0x5709f5[0x0],'timeout':_0x5709f5[0x1]};var _0x42a357=queue[_0x5dc7('0x0')](_0x48168f,{'typecast':!![]});if(_0x42a357[_0x5dc7('0xe')]){logger[_0x5dc7('0xf')](_0x5dc7('0x10'),_0xcc5459,_[_0x5dc7('0x11')](_0x42a357,_0x5dc7('0x12'))[_0x5dc7('0x13')](',\x20'));_0x416ae5['stop']();}else{var _0x473708=_[_0x5dc7('0x14')](_0x233e5d[_0x5dc7('0x15')],handleFindAgent(_0x48168f['name']));if(_0x473708){var _0x46de01=(_0x48168f[_0x5dc7('0x16')]||0xa)*0x3e8;var _0x49ab02,_0x2158cc;var _0x8e3814=seqqueue['createQueue'](_0x46de01);_0x8e3814['id']=_0xcc5459;_0x8e3814['atimeout']=_0x46de01;_0x8e3814[_0x5dc7('0x17')]=_0x2478f6[_0x5dc7('0x17')];writeLog(_0xcc5459,_0x473708,util[_0x5dc7('0xa')](_0x5dc7('0x18'),_0x46de01));_0x233e5d[_0x5dc7('0x19')][_0xcc5459]['on']('end',function(){logger[_0x5dc7('0x1a')](_0x5dc7('0x1b'),_0xcc5459);clearTimeout(_0x2158cc);_0x2158cc=undefined;_0x8e3814[_0x5dc7('0x1c')]();if(_0x233e5d['rules'][_0xcc5459]){delete _0x233e5d[_0x5dc7('0x19')][_0xcc5459];}_0x416ae5[_0x5dc7('0x1d')]();});_0x233e5d[_0x5dc7('0x19')][_0xcc5459]['on']('complete',function(){if(_0x233e5d[_0x5dc7('0x19')][_0xcc5459]){delete _0x233e5d[_0x5dc7('0x19')][_0xcc5459];}});_0x2158cc=setTimeout(function(){logger[_0x5dc7('0x1a')]('[%s][AGENT]\x20ROUTING\x20END',_0xcc5459);clearTimeout(_0x2158cc);_0x8e3814[_0x5dc7('0x1c')]();_0x416ae5[_0x5dc7('0x1e')]();},_0x46de01);strategy[_0x5dc7('0x1f')](_0x8e3814,_0x473708,_0x233e5d,_0x2478f6);}else{logger[_0x5dc7('0xf')](_0x5dc7('0x20'),_0xcc5459,_0x48168f[_0x5dc7('0xb')]);_0x416ae5[_0x5dc7('0x1d')]();}}}catch(_0x41fb79){console[_0x5dc7('0x21')](_0x41fb79);logger[_0x5dc7('0xf')](_0x5dc7('0x22'),_0xcc5459,_0x41fb79[_0x5dc7('0x23')]);_0x416ae5[_0x5dc7('0x1d')]();}};};