Built motion from commit 616d3211.|2.6.4
[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 _0x29a9=['message','join','stop','find','timeout','createQueue','atimeout','channel','end','rules','complete','[%s][AGENT]\x20ROUTING\x20END','next','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','../../../../config/logger','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','error'];(function(_0x467ccd,_0x327beb){var _0x1e802c=function(_0x4b6976){while(--_0x4b6976){_0x467ccd['push'](_0x467ccd['shift']());}};_0x1e802c(++_0x327beb);}(_0x29a9,0x74));var _0x929a=function(_0x57eb2d,_0x5e4918){_0x57eb2d=_0x57eb2d-0x0;var _0xd8e18=_0x29a9[_0x57eb2d];return _0xd8e18;};'use strict';var schema=require(_0x929a('0x0'));var _=require(_0x929a('0x1'));var util=require(_0x929a('0x2'));var seqqueue=require(_0x929a('0x3'));var logger=require(_0x929a('0x4'))(_0x929a('0x5'));var strategy=require(_0x929a('0x6'));var queue=schema({'name':{'type':'string','required':!![],'message':_0x929a('0x7')},'timeout':{'type':_0x929a('0x8'),'message':_0x929a('0x9')}});function writeLog(_0x370b47,_0x29e6e2,_0x15f37d){return logger[_0x929a('0xa')](util[_0x929a('0xb')](_0x929a('0xc'),_0x370b47,_0x29e6e2[_0x929a('0xd')],_0x15f37d));}function handleFindAgent(_0x417ad5){return function(_0x1557ff){return _0x1557ff[_0x929a('0xd')][_0x929a('0xe')]()===_0x417ad5[_0x929a('0xe')]();};}exports['consequence']=function(_0xa3e72,_0x3af793,_0xde1ca3,_0xb1687a){return function(_0x5bf237){try{var _0xe9199d={'name':_0x3af793[0x0],'timeout':_0x3af793[0x1]};var _0x2f3eb7=queue[_0x929a('0x0')](_0xe9199d,{'typecast':!![]});if(_0x2f3eb7['length']){logger[_0x929a('0xf')]('[%s][AGENT]\x20%s',_0xa3e72,_['map'](_0x2f3eb7,_0x929a('0x10'))[_0x929a('0x11')](',\x20'));_0x5bf237[_0x929a('0x12')]();}else{var _0x141b3a=_[_0x929a('0x13')](_0xde1ca3['agents'],handleFindAgent(_0xe9199d[_0x929a('0xd')]));if(_0x141b3a){var _0x59f02d=(_0xe9199d[_0x929a('0x14')]||0xa)*0x3e8;var _0x28cf88,_0x7548b4;var _0x4e5e27=seqqueue[_0x929a('0x15')](_0x59f02d);_0x4e5e27['id']=_0xa3e72;_0x4e5e27[_0x929a('0x16')]=_0x59f02d;_0x4e5e27[_0x929a('0x17')]=_0xb1687a[_0x929a('0x17')];writeLog(_0xa3e72,_0x141b3a,util[_0x929a('0xb')]('START:%s',_0x59f02d));_0xde1ca3['rules'][_0xa3e72]['on'](_0x929a('0x18'),function(){logger[_0x929a('0xa')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0xa3e72);clearTimeout(_0x7548b4);_0x7548b4=undefined;_0x4e5e27['close']();if(_0xde1ca3[_0x929a('0x19')][_0xa3e72]){delete _0xde1ca3['rules'][_0xa3e72];}_0x5bf237['stop']();});_0xde1ca3[_0x929a('0x19')][_0xa3e72]['on'](_0x929a('0x1a'),function(){if(_0xde1ca3['rules'][_0xa3e72]){delete _0xde1ca3[_0x929a('0x19')][_0xa3e72];}});_0x7548b4=setTimeout(function(){logger['info'](_0x929a('0x1b'),_0xa3e72);clearTimeout(_0x7548b4);_0x4e5e27['close']();_0x5bf237[_0x929a('0x1c')]();},_0x59f02d);strategy['agent'](_0x4e5e27,_0x141b3a,_0xde1ca3,_0xb1687a);}else{logger[_0x929a('0xf')](_0x929a('0x1d'),_0xa3e72,_0xe9199d['name']);_0x5bf237[_0x929a('0x12')]();}}}catch(_0x26759c){console[_0x929a('0x1e')](_0x26759c);logger['error'](_0x929a('0x1f'),_0xa3e72,_0x26759c[_0x929a('0x20')]);_0x5bf237['stop']();}};};