Built motion from commit d1eab355.|2.6.28
[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 _0xc897=['[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','stop','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','timeout\x20is\x20a\x20number','info','format','name','toLowerCase','consequence','error','[%s][AGENT]\x20%s','map','join','find','agents','timeout','atimeout','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete'];(function(_0x53b901,_0x138ca1){var _0xc39adc=function(_0x4b616f){while(--_0x4b616f){_0x53b901['push'](_0x53b901['shift']());}};_0xc39adc(++_0x138ca1);}(_0xc897,0xc1));var _0x7c89=function(_0x133277,_0xb1d6b2){_0x133277=_0x133277-0x0;var _0x5b4a22=_0xc897[_0x133277];return _0x5b4a22;};'use strict';var schema=require(_0x7c89('0x0'));var _=require(_0x7c89('0x1'));var util=require(_0x7c89('0x2'));var seqqueue=require(_0x7c89('0x3'));var logger=require(_0x7c89('0x4'))(_0x7c89('0x5'));var strategy=require(_0x7c89('0x6'));var queue=schema({'name':{'type':_0x7c89('0x7'),'required':!![],'message':_0x7c89('0x8')},'timeout':{'type':'number','message':_0x7c89('0x9')}});function writeLog(_0x33c211,_0x5bff64,_0xa3acd7){return logger[_0x7c89('0xa')](util[_0x7c89('0xb')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x33c211,_0x5bff64[_0x7c89('0xc')],_0xa3acd7));}function handleFindAgent(_0x543104){return function(_0x139cbb){return _0x139cbb[_0x7c89('0xc')][_0x7c89('0xd')]()===_0x543104[_0x7c89('0xd')]();};}exports[_0x7c89('0xe')]=function(_0x20f485,_0x27b176,_0x2acc39,_0x4abbce){return function(_0x505f7b){try{var _0x2ab47e={'name':_0x27b176[0x0],'timeout':_0x27b176[0x1]};var _0xd3f5d5=queue[_0x7c89('0x0')](_0x2ab47e,{'typecast':!![]});if(_0xd3f5d5['length']){logger[_0x7c89('0xf')](_0x7c89('0x10'),_0x20f485,_[_0x7c89('0x11')](_0xd3f5d5,'message')[_0x7c89('0x12')](',\x20'));_0x505f7b['stop']();}else{var _0x2ccfe2=_[_0x7c89('0x13')](_0x2acc39[_0x7c89('0x14')],handleFindAgent(_0x2ab47e[_0x7c89('0xc')]));if(_0x2ccfe2){var _0x3e13eb=(_0x2ab47e[_0x7c89('0x15')]||0xa)*0x3e8;var _0x475c1b,_0x1bc1a9;var _0x4e54fa=seqqueue['createQueue'](_0x3e13eb);_0x4e54fa['id']=_0x20f485;_0x4e54fa[_0x7c89('0x16')]=_0x3e13eb;_0x4e54fa['channel']=_0x4abbce['channel'];writeLog(_0x20f485,_0x2ccfe2,util[_0x7c89('0xb')](_0x7c89('0x17'),_0x3e13eb));_0x2acc39[_0x7c89('0x18')][_0x20f485]['on'](_0x7c89('0x19'),function(){logger['info'](_0x7c89('0x1a'),_0x20f485);clearTimeout(_0x1bc1a9);_0x1bc1a9=undefined;_0x4e54fa[_0x7c89('0x1b')]();if(_0x2acc39[_0x7c89('0x18')][_0x20f485]){delete _0x2acc39[_0x7c89('0x18')][_0x20f485];}_0x505f7b['stop']();});_0x2acc39[_0x7c89('0x18')][_0x20f485]['on'](_0x7c89('0x1c'),function(){if(_0x2acc39[_0x7c89('0x18')][_0x20f485]){delete _0x2acc39[_0x7c89('0x18')][_0x20f485];}});_0x1bc1a9=setTimeout(function(){logger[_0x7c89('0xa')](_0x7c89('0x1d'),_0x20f485);clearTimeout(_0x1bc1a9);_0x4e54fa[_0x7c89('0x1b')]();_0x505f7b[_0x7c89('0x1e')]();},_0x3e13eb);strategy[_0x7c89('0x1f')](_0x4e54fa,_0x2ccfe2,_0x2acc39,_0x4abbce);}else{logger[_0x7c89('0xf')](_0x7c89('0x20'),_0x20f485,_0x2ab47e['name']);_0x505f7b[_0x7c89('0x21')]();}}}catch(_0x353c35){console[_0x7c89('0x22')](_0x353c35);logger['error'](_0x7c89('0x23'),_0x20f485,_0x353c35[_0x7c89('0x24')]);_0x505f7b[_0x7c89('0x21')]();}};};