Built motion from commit 43538d75.|2.5.35
[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 _0x1f53=['message','join','stop','find','agents','timeout','atimeout','channel','START:%s','rules','end','info','[%s][AGENT]\x20ROUTING\x20STOPPED','close','next','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','string','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','validate','length','error'];(function(_0x47c418,_0x1e3182){var _0x83159=function(_0x3df040){while(--_0x3df040){_0x47c418['push'](_0x47c418['shift']());}};_0x83159(++_0x1e3182);}(_0x1f53,0xf9));var _0x31f5=function(_0x539c6c,_0x350271){_0x539c6c=_0x539c6c-0x0;var _0x323e73=_0x1f53[_0x539c6c];return _0x323e73;};'use strict';var schema=require('validate');var _=require(_0x31f5('0x0'));var util=require(_0x31f5('0x1'));var seqqueue=require(_0x31f5('0x2'));var logger=require(_0x31f5('0x3'))(_0x31f5('0x4'));var strategy=require(_0x31f5('0x5'));var queue=schema({'name':{'type':_0x31f5('0x6'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':'number','message':'timeout\x20is\x20a\x20number'}});function writeLog(_0xd0730a,_0x52b748,_0x35f344){return logger['info'](util[_0x31f5('0x7')](_0x31f5('0x8'),_0xd0730a,_0x52b748[_0x31f5('0x9')],_0x35f344));}function handleFindAgent(_0x4b2089){return function(_0x531934){return _0x531934[_0x31f5('0x9')]['toLowerCase']()===_0x4b2089[_0x31f5('0xa')]();};}exports[_0x31f5('0xb')]=function(_0x51ec2c,_0x39478e,_0x5124ee,_0x4243a5){return function(_0x2b758d){try{var _0x3ab970={'name':_0x39478e[0x0],'timeout':_0x39478e[0x1]};var _0x4d2d6e=queue[_0x31f5('0xc')](_0x3ab970,{'typecast':!![]});if(_0x4d2d6e[_0x31f5('0xd')]){logger[_0x31f5('0xe')]('[%s][AGENT]\x20%s',_0x51ec2c,_['map'](_0x4d2d6e,_0x31f5('0xf'))[_0x31f5('0x10')](',\x20'));_0x2b758d[_0x31f5('0x11')]();}else{var _0x37ae60=_[_0x31f5('0x12')](_0x5124ee[_0x31f5('0x13')],handleFindAgent(_0x3ab970[_0x31f5('0x9')]));if(_0x37ae60){var _0x342bf6=(_0x3ab970[_0x31f5('0x14')]||0xa)*0x3e8;var _0x5f3c4f,_0x3d1e4b;var _0x1fde59=seqqueue['createQueue'](_0x342bf6);_0x1fde59['id']=_0x51ec2c;_0x1fde59[_0x31f5('0x15')]=_0x342bf6;_0x1fde59[_0x31f5('0x16')]=_0x4243a5[_0x31f5('0x16')];writeLog(_0x51ec2c,_0x37ae60,util[_0x31f5('0x7')](_0x31f5('0x17'),_0x342bf6));_0x5124ee[_0x31f5('0x18')][_0x51ec2c]['on'](_0x31f5('0x19'),function(){logger[_0x31f5('0x1a')](_0x31f5('0x1b'),_0x51ec2c);clearTimeout(_0x3d1e4b);_0x3d1e4b=undefined;_0x1fde59[_0x31f5('0x1c')]();if(_0x5124ee[_0x31f5('0x18')][_0x51ec2c]){delete _0x5124ee[_0x31f5('0x18')][_0x51ec2c];}_0x2b758d[_0x31f5('0x11')]();});_0x5124ee[_0x31f5('0x18')][_0x51ec2c]['on']('complete',function(){if(_0x5124ee[_0x31f5('0x18')][_0x51ec2c]){delete _0x5124ee[_0x31f5('0x18')][_0x51ec2c];}});_0x3d1e4b=setTimeout(function(){logger[_0x31f5('0x1a')]('[%s][AGENT]\x20ROUTING\x20END',_0x51ec2c);clearTimeout(_0x3d1e4b);_0x1fde59[_0x31f5('0x1c')]();_0x2b758d[_0x31f5('0x1d')]();},_0x342bf6);strategy['agent'](_0x1fde59,_0x37ae60,_0x5124ee,_0x4243a5);}else{logger[_0x31f5('0xe')](_0x31f5('0x1e'),_0x51ec2c,_0x3ab970['name']);_0x2b758d[_0x31f5('0x11')]();}}}catch(_0x5470e8){console['log'](_0x5470e8);logger[_0x31f5('0xe')](_0x31f5('0x1f'),_0x51ec2c,_0x5470e8[_0x31f5('0x20')]);_0x2b758d['stop']();}};};