ccb50fa078421a373436fa64c2baa7ae3ee3fa52
[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 _0x2873=['timeout','createQueue','channel','format','START:%s','rules','[%s][AGENT]\x20ROUTING\x20STOPPED','stop','complete','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','routing','./strategy','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','error','[%s][AGENT]\x20%s','map','message','join','find','agents'];(function(_0x553acf,_0x293eef){var _0x23efe7=function(_0x2d6317){while(--_0x2d6317){_0x553acf['push'](_0x553acf['shift']());}};_0x23efe7(++_0x293eef);}(_0x2873,0x1f2));var _0x3287=function(_0x2afcbd,_0x295396){_0x2afcbd=_0x2afcbd-0x0;var _0x1592b3=_0x2873[_0x2afcbd];return _0x1592b3;};'use strict';var schema=require(_0x3287('0x0'));var _=require(_0x3287('0x1'));var util=require(_0x3287('0x2'));var seqqueue=require(_0x3287('0x3'));var logger=require('../../../../config/logger')(_0x3287('0x4'));var strategy=require(_0x3287('0x5'));var queue=schema({'name':{'type':'string','required':!![],'message':_0x3287('0x6')},'timeout':{'type':_0x3287('0x7'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x38b618,_0x795e58,_0x5b30c4){return logger[_0x3287('0x8')](util['format'](_0x3287('0x9'),_0x38b618,_0x795e58[_0x3287('0xa')],_0x5b30c4));}function handleFindAgent(_0x2bbe7f){return function(_0xf42d0f){return _0xf42d0f[_0x3287('0xa')][_0x3287('0xb')]()===_0x2bbe7f[_0x3287('0xb')]();};}exports[_0x3287('0xc')]=function(_0x29ecc6,_0x1c342a,_0x22f28c,_0x43f42d){return function(_0x330f79){try{var _0x36081b={'name':_0x1c342a[0x0],'timeout':_0x1c342a[0x1]};var _0x34a920=queue['validate'](_0x36081b,{'typecast':!![]});if(_0x34a920['length']){logger[_0x3287('0xd')](_0x3287('0xe'),_0x29ecc6,_[_0x3287('0xf')](_0x34a920,_0x3287('0x10'))[_0x3287('0x11')](',\x20'));_0x330f79['stop']();}else{var _0x3a6a15=_[_0x3287('0x12')](_0x22f28c[_0x3287('0x13')],handleFindAgent(_0x36081b[_0x3287('0xa')]));if(_0x3a6a15){var _0x5b895a=(_0x36081b[_0x3287('0x14')]||0xa)*0x3e8;var _0x4c8143,_0x342461;var _0x46128a=seqqueue[_0x3287('0x15')](_0x5b895a);_0x46128a['id']=_0x29ecc6;_0x46128a['atimeout']=_0x5b895a;_0x46128a[_0x3287('0x16')]=_0x43f42d[_0x3287('0x16')];writeLog(_0x29ecc6,_0x3a6a15,util[_0x3287('0x17')](_0x3287('0x18'),_0x5b895a));_0x22f28c[_0x3287('0x19')][_0x29ecc6]['on']('end',function(){logger['info'](_0x3287('0x1a'),_0x29ecc6);clearTimeout(_0x342461);_0x342461=undefined;_0x46128a['close']();if(_0x22f28c[_0x3287('0x19')][_0x29ecc6]){delete _0x22f28c['rules'][_0x29ecc6];}_0x330f79[_0x3287('0x1b')]();});_0x22f28c['rules'][_0x29ecc6]['on'](_0x3287('0x1c'),function(){if(_0x22f28c[_0x3287('0x19')][_0x29ecc6]){delete _0x22f28c[_0x3287('0x19')][_0x29ecc6];}});_0x342461=setTimeout(function(){logger[_0x3287('0x8')](_0x3287('0x1d'),_0x29ecc6);clearTimeout(_0x342461);_0x46128a[_0x3287('0x1e')]();_0x330f79[_0x3287('0x1f')]();},_0x5b895a);strategy[_0x3287('0x20')](_0x46128a,_0x3a6a15,_0x22f28c,_0x43f42d);}else{logger[_0x3287('0xd')](_0x3287('0x21'),_0x29ecc6,_0x36081b[_0x3287('0xa')]);_0x330f79['stop']();}}}catch(_0x4f0bba){console[_0x3287('0x22')](_0x4f0bba);logger[_0x3287('0xd')](_0x3287('0x23'),_0x29ecc6,_0x4f0bba[_0x3287('0x24')]);_0x330f79[_0x3287('0x1b')]();}};};