Built motion from commit da617fac.|2.6.6
[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 _0x01ff=['timeout','createQueue','atimeout','channel','format','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','../../../../config/logger','routing','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','join','stop','find','agents'];(function(_0x367b37,_0xecb6d9){var _0x56776b=function(_0x87b0d6){while(--_0x87b0d6){_0x367b37['push'](_0x367b37['shift']());}};_0x56776b(++_0xecb6d9);}(_0x01ff,0x167));var _0xf01f=function(_0x42ccd8,_0x204285){_0x42ccd8=_0x42ccd8-0x0;var _0x54334a=_0x01ff[_0x42ccd8];return _0x54334a;};'use strict';var schema=require(_0xf01f('0x0'));var _=require(_0xf01f('0x1'));var util=require(_0xf01f('0x2'));var seqqueue=require('seq-queue');var logger=require(_0xf01f('0x3'))(_0xf01f('0x4'));var strategy=require('./strategy');var queue=schema({'name':{'type':_0xf01f('0x5'),'required':!![],'message':_0xf01f('0x6')},'timeout':{'type':_0xf01f('0x7'),'message':_0xf01f('0x8')}});function writeLog(_0xfa4041,_0x57a4ed,_0x4125e3){return logger[_0xf01f('0x9')](util['format'](_0xf01f('0xa'),_0xfa4041,_0x57a4ed[_0xf01f('0xb')],_0x4125e3));}function handleFindAgent(_0x1a8498){return function(_0x514ac7){return _0x514ac7[_0xf01f('0xb')][_0xf01f('0xc')]()===_0x1a8498[_0xf01f('0xc')]();};}exports[_0xf01f('0xd')]=function(_0x52c3f4,_0x511693,_0x28d559,_0xdf6981){return function(_0x19b1ec){try{var _0x30f74f={'name':_0x511693[0x0],'timeout':_0x511693[0x1]};var _0x114834=queue[_0xf01f('0x0')](_0x30f74f,{'typecast':!![]});if(_0x114834[_0xf01f('0xe')]){logger[_0xf01f('0xf')](_0xf01f('0x10'),_0x52c3f4,_['map'](_0x114834,'message')[_0xf01f('0x11')](',\x20'));_0x19b1ec[_0xf01f('0x12')]();}else{var _0x747494=_[_0xf01f('0x13')](_0x28d559[_0xf01f('0x14')],handleFindAgent(_0x30f74f[_0xf01f('0xb')]));if(_0x747494){var _0x473241=(_0x30f74f[_0xf01f('0x15')]||0xa)*0x3e8;var _0x2f8293,_0x35eb3b;var _0x30772d=seqqueue[_0xf01f('0x16')](_0x473241);_0x30772d['id']=_0x52c3f4;_0x30772d[_0xf01f('0x17')]=_0x473241;_0x30772d[_0xf01f('0x18')]=_0xdf6981[_0xf01f('0x18')];writeLog(_0x52c3f4,_0x747494,util[_0xf01f('0x19')]('START:%s',_0x473241));_0x28d559[_0xf01f('0x1a')][_0x52c3f4]['on'](_0xf01f('0x1b'),function(){logger[_0xf01f('0x9')](_0xf01f('0x1c'),_0x52c3f4);clearTimeout(_0x35eb3b);_0x35eb3b=undefined;_0x30772d[_0xf01f('0x1d')]();if(_0x28d559[_0xf01f('0x1a')][_0x52c3f4]){delete _0x28d559[_0xf01f('0x1a')][_0x52c3f4];}_0x19b1ec['stop']();});_0x28d559[_0xf01f('0x1a')][_0x52c3f4]['on'](_0xf01f('0x1e'),function(){if(_0x28d559[_0xf01f('0x1a')][_0x52c3f4]){delete _0x28d559[_0xf01f('0x1a')][_0x52c3f4];}});_0x35eb3b=setTimeout(function(){logger['info'](_0xf01f('0x1f'),_0x52c3f4);clearTimeout(_0x35eb3b);_0x30772d[_0xf01f('0x1d')]();_0x19b1ec[_0xf01f('0x20')]();},_0x473241);strategy[_0xf01f('0x21')](_0x30772d,_0x747494,_0x28d559,_0xdf6981);}else{logger[_0xf01f('0xf')](_0xf01f('0x22'),_0x52c3f4,_0x30f74f[_0xf01f('0xb')]);_0x19b1ec[_0xf01f('0x12')]();}}}catch(_0x5664e0){console[_0xf01f('0x23')](_0x5664e0);logger[_0xf01f('0xf')](_0xf01f('0x24'),_0x52c3f4,_0x5664e0[_0xf01f('0x25')]);_0x19b1ec[_0xf01f('0x12')]();}};};