899f81e5a0da11023001d9e65c7f4413f9e3c7e2
[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 _0x9fe1=['timeout','createQueue','atimeout','channel','START:%s','rules','info','close','complete','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','string','timeout\x20is\x20a\x20number','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','map','message','stop','agents'];(function(_0x195577,_0x5de53a){var _0x13c367=function(_0x583022){while(--_0x583022){_0x195577['push'](_0x195577['shift']());}};_0x13c367(++_0x5de53a);}(_0x9fe1,0x1d5));var _0x19fe=function(_0x5ac40d,_0x13ba14){_0x5ac40d=_0x5ac40d-0x0;var _0x42b7a1=_0x9fe1[_0x5ac40d];return _0x42b7a1;};'use strict';var schema=require(_0x19fe('0x0'));var _=require(_0x19fe('0x1'));var util=require(_0x19fe('0x2'));var seqqueue=require(_0x19fe('0x3'));var logger=require(_0x19fe('0x4'))(_0x19fe('0x5'));var strategy=require(_0x19fe('0x6'));var queue=schema({'name':{'type':_0x19fe('0x7'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':'number','message':_0x19fe('0x8')}});function writeLog(_0x542d99,_0x263a90,_0x3fece4){return logger['info'](util[_0x19fe('0x9')](_0x19fe('0xa'),_0x542d99,_0x263a90[_0x19fe('0xb')],_0x3fece4));}function handleFindAgent(_0x2745cb){return function(_0x58c5c0){return _0x58c5c0[_0x19fe('0xb')][_0x19fe('0xc')]()===_0x2745cb[_0x19fe('0xc')]();};}exports[_0x19fe('0xd')]=function(_0x111ba8,_0x38e0b4,_0xd56664,_0x32b2d2){return function(_0x4e4260){try{var _0x2bf3d0={'name':_0x38e0b4[0x0],'timeout':_0x38e0b4[0x1]};var _0xb76683=queue[_0x19fe('0x0')](_0x2bf3d0,{'typecast':!![]});if(_0xb76683[_0x19fe('0xe')]){logger[_0x19fe('0xf')](_0x19fe('0x10'),_0x111ba8,_[_0x19fe('0x11')](_0xb76683,_0x19fe('0x12'))['join'](',\x20'));_0x4e4260[_0x19fe('0x13')]();}else{var _0x58cb46=_['find'](_0xd56664[_0x19fe('0x14')],handleFindAgent(_0x2bf3d0['name']));if(_0x58cb46){var _0x53acb9=(_0x2bf3d0[_0x19fe('0x15')]||0xa)*0x3e8;var _0x55c339,_0x11fb01;var _0x59bf70=seqqueue[_0x19fe('0x16')](_0x53acb9);_0x59bf70['id']=_0x111ba8;_0x59bf70[_0x19fe('0x17')]=_0x53acb9;_0x59bf70[_0x19fe('0x18')]=_0x32b2d2[_0x19fe('0x18')];writeLog(_0x111ba8,_0x58cb46,util[_0x19fe('0x9')](_0x19fe('0x19'),_0x53acb9));_0xd56664[_0x19fe('0x1a')][_0x111ba8]['on']('end',function(){logger[_0x19fe('0x1b')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x111ba8);clearTimeout(_0x11fb01);_0x11fb01=undefined;_0x59bf70[_0x19fe('0x1c')]();if(_0xd56664['rules'][_0x111ba8]){delete _0xd56664[_0x19fe('0x1a')][_0x111ba8];}_0x4e4260[_0x19fe('0x13')]();});_0xd56664[_0x19fe('0x1a')][_0x111ba8]['on'](_0x19fe('0x1d'),function(){if(_0xd56664[_0x19fe('0x1a')][_0x111ba8]){delete _0xd56664[_0x19fe('0x1a')][_0x111ba8];}});_0x11fb01=setTimeout(function(){logger[_0x19fe('0x1b')]('[%s][AGENT]\x20ROUTING\x20END',_0x111ba8);clearTimeout(_0x11fb01);_0x59bf70[_0x19fe('0x1c')]();_0x4e4260['next']();},_0x53acb9);strategy[_0x19fe('0x1e')](_0x59bf70,_0x58cb46,_0xd56664,_0x32b2d2);}else{logger['error'](_0x19fe('0x1f'),_0x111ba8,_0x2bf3d0[_0x19fe('0xb')]);_0x4e4260[_0x19fe('0x13')]();}}}catch(_0xe58e62){console[_0x19fe('0x20')](_0xe58e62);logger[_0x19fe('0xf')](_0x19fe('0x21'),_0x111ba8,_0xe58e62[_0x19fe('0x22')]);_0x4e4260[_0x19fe('0x13')]();}};};