d1989413360d9888298d43ea1bfbc80fd00e76fe
[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 _0x343d=['join','stop','find','agents','timeout','createQueue','atimeout','channel','START:%s','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','rules','complete','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','validate','lodash','seq-queue','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','error','[%s][AGENT]\x20%s','message'];(function(_0x244f5d,_0x3c98c6){var _0x1a3886=function(_0x2bf049){while(--_0x2bf049){_0x244f5d['push'](_0x244f5d['shift']());}};_0x1a3886(++_0x3c98c6);}(_0x343d,0x1aa));var _0xd343=function(_0x224dda,_0x16d0f9){_0x224dda=_0x224dda-0x0;var _0x2987ac=_0x343d[_0x224dda];return _0x2987ac;};'use strict';var schema=require(_0xd343('0x0'));var _=require(_0xd343('0x1'));var util=require('util');var seqqueue=require(_0xd343('0x2'));var logger=require('../../../../config/logger')(_0xd343('0x3'));var strategy=require(_0xd343('0x4'));var queue=schema({'name':{'type':'string','required':!![],'message':_0xd343('0x5')},'timeout':{'type':_0xd343('0x6'),'message':_0xd343('0x7')}});function writeLog(_0x47c5a2,_0x5180b3,_0x596481){return logger[_0xd343('0x8')](util[_0xd343('0x9')](_0xd343('0xa'),_0x47c5a2,_0x5180b3[_0xd343('0xb')],_0x596481));}function handleFindAgent(_0x5666a7){return function(_0x9c873e){return _0x9c873e[_0xd343('0xb')][_0xd343('0xc')]()===_0x5666a7[_0xd343('0xc')]();};}exports[_0xd343('0xd')]=function(_0x437e55,_0x34a27d,_0x50f2b2,_0x5eec5e){return function(_0xe8562c){try{var _0x553e15={'name':_0x34a27d[0x0],'timeout':_0x34a27d[0x1]};var _0x47788f=queue['validate'](_0x553e15,{'typecast':!![]});if(_0x47788f[_0xd343('0xe')]){logger[_0xd343('0xf')](_0xd343('0x10'),_0x437e55,_['map'](_0x47788f,_0xd343('0x11'))[_0xd343('0x12')](',\x20'));_0xe8562c[_0xd343('0x13')]();}else{var _0x5292cf=_[_0xd343('0x14')](_0x50f2b2[_0xd343('0x15')],handleFindAgent(_0x553e15['name']));if(_0x5292cf){var _0x414ee2=(_0x553e15[_0xd343('0x16')]||0xa)*0x3e8;var _0x24ee3a,_0x460b7f;var _0x174c15=seqqueue[_0xd343('0x17')](_0x414ee2);_0x174c15['id']=_0x437e55;_0x174c15[_0xd343('0x18')]=_0x414ee2;_0x174c15[_0xd343('0x19')]=_0x5eec5e[_0xd343('0x19')];writeLog(_0x437e55,_0x5292cf,util[_0xd343('0x9')](_0xd343('0x1a'),_0x414ee2));_0x50f2b2['rules'][_0x437e55]['on'](_0xd343('0x1b'),function(){logger[_0xd343('0x8')](_0xd343('0x1c'),_0x437e55);clearTimeout(_0x460b7f);_0x460b7f=undefined;_0x174c15[_0xd343('0x1d')]();if(_0x50f2b2[_0xd343('0x1e')][_0x437e55]){delete _0x50f2b2[_0xd343('0x1e')][_0x437e55];}_0xe8562c['stop']();});_0x50f2b2[_0xd343('0x1e')][_0x437e55]['on'](_0xd343('0x1f'),function(){if(_0x50f2b2[_0xd343('0x1e')][_0x437e55]){delete _0x50f2b2[_0xd343('0x1e')][_0x437e55];}});_0x460b7f=setTimeout(function(){logger[_0xd343('0x8')]('[%s][AGENT]\x20ROUTING\x20END',_0x437e55);clearTimeout(_0x460b7f);_0x174c15[_0xd343('0x1d')]();_0xe8562c[_0xd343('0x20')]();},_0x414ee2);strategy[_0xd343('0x21')](_0x174c15,_0x5292cf,_0x50f2b2,_0x5eec5e);}else{logger[_0xd343('0xf')](_0xd343('0x22'),_0x437e55,_0x553e15[_0xd343('0xb')]);_0xe8562c[_0xd343('0x13')]();}}}catch(_0x1d44b7){console[_0xd343('0x23')](_0x1d44b7);logger[_0xd343('0xf')](_0xd343('0x24'),_0x437e55,_0x1d44b7['stack']);_0xe8562c[_0xd343('0x13')]();}};};