Built motion from commit (unavailable).|2.5.26
[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 _0xdcf4=['[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','util','../../../../config/logger','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','name','toLowerCase','consequence','validate','length','error','[%s][AGENT]\x20%s','map','message','join','stop','find','agents','createQueue','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete'];(function(_0x17f363,_0x53e47b){var _0x5d7c1b=function(_0x6ac196){while(--_0x6ac196){_0x17f363['push'](_0x17f363['shift']());}};_0x5d7c1b(++_0x53e47b);}(_0xdcf4,0xeb));var _0x4dcf=function(_0x38aa3a,_0x40cbdd){_0x38aa3a=_0x38aa3a-0x0;var _0x2e44d7=_0xdcf4[_0x38aa3a];return _0x2e44d7;};'use strict';var schema=require('validate');var _=require('lodash');var util=require(_0x4dcf('0x0'));var seqqueue=require('seq-queue');var logger=require(_0x4dcf('0x1'))('routing');var strategy=require(_0x4dcf('0x2'));var queue=schema({'name':{'type':_0x4dcf('0x3'),'required':!![],'message':_0x4dcf('0x4')},'timeout':{'type':_0x4dcf('0x5'),'message':_0x4dcf('0x6')}});function writeLog(_0x3e97ea,_0x2f5d62,_0x500f7b){return logger[_0x4dcf('0x7')](util[_0x4dcf('0x8')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x3e97ea,_0x2f5d62[_0x4dcf('0x9')],_0x500f7b));}function handleFindAgent(_0x3cd35d){return function(_0x20b419){return _0x20b419[_0x4dcf('0x9')][_0x4dcf('0xa')]()===_0x3cd35d[_0x4dcf('0xa')]();};}exports[_0x4dcf('0xb')]=function(_0x5e32ed,_0x501f81,_0x335ac8,_0x3de17d){return function(_0x4703f5){try{var _0x1b457d={'name':_0x501f81[0x0],'timeout':_0x501f81[0x1]};var _0x599d8f=queue[_0x4dcf('0xc')](_0x1b457d,{'typecast':!![]});if(_0x599d8f[_0x4dcf('0xd')]){logger[_0x4dcf('0xe')](_0x4dcf('0xf'),_0x5e32ed,_[_0x4dcf('0x10')](_0x599d8f,_0x4dcf('0x11'))[_0x4dcf('0x12')](',\x20'));_0x4703f5[_0x4dcf('0x13')]();}else{var _0x1407ae=_[_0x4dcf('0x14')](_0x335ac8[_0x4dcf('0x15')],handleFindAgent(_0x1b457d['name']));if(_0x1407ae){var _0x5589f1=(_0x1b457d['timeout']||0xa)*0x3e8;var _0x36754d,_0x167205;var _0x4ec552=seqqueue[_0x4dcf('0x16')](_0x5589f1);_0x4ec552['id']=_0x5e32ed;_0x4ec552[_0x4dcf('0x17')]=_0x5589f1;_0x4ec552[_0x4dcf('0x18')]=_0x3de17d[_0x4dcf('0x18')];writeLog(_0x5e32ed,_0x1407ae,util[_0x4dcf('0x8')](_0x4dcf('0x19'),_0x5589f1));_0x335ac8[_0x4dcf('0x1a')][_0x5e32ed]['on'](_0x4dcf('0x1b'),function(){logger[_0x4dcf('0x7')](_0x4dcf('0x1c'),_0x5e32ed);clearTimeout(_0x167205);_0x167205=undefined;_0x4ec552[_0x4dcf('0x1d')]();if(_0x335ac8[_0x4dcf('0x1a')][_0x5e32ed]){delete _0x335ac8['rules'][_0x5e32ed];}_0x4703f5[_0x4dcf('0x13')]();});_0x335ac8[_0x4dcf('0x1a')][_0x5e32ed]['on'](_0x4dcf('0x1e'),function(){if(_0x335ac8[_0x4dcf('0x1a')][_0x5e32ed]){delete _0x335ac8[_0x4dcf('0x1a')][_0x5e32ed];}});_0x167205=setTimeout(function(){logger[_0x4dcf('0x7')](_0x4dcf('0x1f'),_0x5e32ed);clearTimeout(_0x167205);_0x4ec552[_0x4dcf('0x1d')]();_0x4703f5[_0x4dcf('0x20')]();},_0x5589f1);strategy[_0x4dcf('0x21')](_0x4ec552,_0x1407ae,_0x335ac8,_0x3de17d);}else{logger[_0x4dcf('0xe')](_0x4dcf('0x22'),_0x5e32ed,_0x1b457d[_0x4dcf('0x9')]);_0x4703f5[_0x4dcf('0x13')]();}}}catch(_0x3a4ffa){console[_0x4dcf('0x23')](_0x3a4ffa);logger[_0x4dcf('0xe')](_0x4dcf('0x24'),_0x5e32ed,_0x3a4ffa[_0x4dcf('0x25')]);_0x4703f5['stop']();}};};