Built motion from commit f25620e4.|2.6.30
[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 _0x3f26=['stop','find','agents','atimeout','channel','START:%s','rules','end','info','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','next','error','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','lodash','util','seq-queue','../../../../config/logger','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','format','name','toLowerCase','consequence','map','join'];(function(_0x25ff7e,_0x492eb8){var _0x1e8dcc=function(_0x1b1120){while(--_0x1b1120){_0x25ff7e['push'](_0x25ff7e['shift']());}};_0x1e8dcc(++_0x492eb8);}(_0x3f26,0x148));var _0x63f2=function(_0x5db5fc,_0x61dacf){_0x5db5fc=_0x5db5fc-0x0;var _0x214470=_0x3f26[_0x5db5fc];return _0x214470;};'use strict';var schema=require('validate');var _=require(_0x63f2('0x0'));var util=require(_0x63f2('0x1'));var seqqueue=require(_0x63f2('0x2'));var logger=require(_0x63f2('0x3'))('routing');var strategy=require('./strategy');var queue=schema({'name':{'type':'string','required':!![],'message':_0x63f2('0x4')},'timeout':{'type':_0x63f2('0x5'),'message':_0x63f2('0x6')}});function writeLog(_0x5ef2a0,_0x39554a,_0x12723d){return logger['info'](util[_0x63f2('0x7')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x5ef2a0,_0x39554a[_0x63f2('0x8')],_0x12723d));}function handleFindAgent(_0x5d7dc8){return function(_0x1ec53f){return _0x1ec53f[_0x63f2('0x8')][_0x63f2('0x9')]()===_0x5d7dc8[_0x63f2('0x9')]();};}exports[_0x63f2('0xa')]=function(_0x282eb6,_0x1794d4,_0x25ac5e,_0x4009f2){return function(_0x52031c){try{var _0x32ce9b={'name':_0x1794d4[0x0],'timeout':_0x1794d4[0x1]};var _0x472ccf=queue['validate'](_0x32ce9b,{'typecast':!![]});if(_0x472ccf['length']){logger['error']('[%s][AGENT]\x20%s',_0x282eb6,_[_0x63f2('0xb')](_0x472ccf,'message')[_0x63f2('0xc')](',\x20'));_0x52031c[_0x63f2('0xd')]();}else{var _0x29b8cb=_[_0x63f2('0xe')](_0x25ac5e[_0x63f2('0xf')],handleFindAgent(_0x32ce9b['name']));if(_0x29b8cb){var _0x50b514=(_0x32ce9b['timeout']||0xa)*0x3e8;var _0x3627c5,_0x51eac4;var _0x35d795=seqqueue['createQueue'](_0x50b514);_0x35d795['id']=_0x282eb6;_0x35d795[_0x63f2('0x10')]=_0x50b514;_0x35d795['channel']=_0x4009f2[_0x63f2('0x11')];writeLog(_0x282eb6,_0x29b8cb,util['format'](_0x63f2('0x12'),_0x50b514));_0x25ac5e[_0x63f2('0x13')][_0x282eb6]['on'](_0x63f2('0x14'),function(){logger[_0x63f2('0x15')](_0x63f2('0x16'),_0x282eb6);clearTimeout(_0x51eac4);_0x51eac4=undefined;_0x35d795[_0x63f2('0x17')]();if(_0x25ac5e['rules'][_0x282eb6]){delete _0x25ac5e['rules'][_0x282eb6];}_0x52031c[_0x63f2('0xd')]();});_0x25ac5e[_0x63f2('0x13')][_0x282eb6]['on'](_0x63f2('0x18'),function(){if(_0x25ac5e[_0x63f2('0x13')][_0x282eb6]){delete _0x25ac5e[_0x63f2('0x13')][_0x282eb6];}});_0x51eac4=setTimeout(function(){logger[_0x63f2('0x15')]('[%s][AGENT]\x20ROUTING\x20END',_0x282eb6);clearTimeout(_0x51eac4);_0x35d795['close']();_0x52031c[_0x63f2('0x19')]();},_0x50b514);strategy['agent'](_0x35d795,_0x29b8cb,_0x25ac5e,_0x4009f2);}else{logger[_0x63f2('0x1a')](_0x63f2('0x1b'),_0x282eb6,_0x32ce9b['name']);_0x52031c['stop']();}}}catch(_0x3a9288){console[_0x63f2('0x1c')](_0x3a9288);logger[_0x63f2('0x1a')](_0x63f2('0x1d'),_0x282eb6,_0x3a9288[_0x63f2('0x1e')]);_0x52031c[_0x63f2('0xd')]();}};};