Built motion from commit (unavailable).|2.4.20
[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 _0x49bb=['close','stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','consequence','length','error','[%s][AGENT]\x20%s','map','timeout','createQueue','atimeout','channel','START:%s','rules','info','[%s][AGENT]\x20ROUTING\x20STOPPED'];(function(_0x27dd89,_0x1549f2){var _0x26b660=function(_0x1085b6){while(--_0x1085b6){_0x27dd89['push'](_0x27dd89['shift']());}};_0x26b660(++_0x1549f2);}(_0x49bb,0x175));var _0xb49b=function(_0x53e696,_0x4b0f00){_0x53e696=_0x53e696-0x0;var _0x3f7ddb=_0x49bb[_0x53e696];return _0x3f7ddb;};'use strict';var schema=require(_0xb49b('0x0'));var _=require(_0xb49b('0x1'));var util=require(_0xb49b('0x2'));var seqqueue=require('seq-queue');var logger=require('../../../../config/logger')('routing');var strategy=require(_0xb49b('0x3'));var queue=schema({'name':{'type':_0xb49b('0x4'),'required':!![],'message':_0xb49b('0x5')},'timeout':{'type':_0xb49b('0x6'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0xa34db5,_0x2ff51e,_0x174092){return logger['info'](util[_0xb49b('0x7')](_0xb49b('0x8'),_0xa34db5,_0x2ff51e[_0xb49b('0x9')],_0x174092));}function handleFindAgent(_0x3841c2){return function(_0x436197){return _0x436197['name']['toLowerCase']()===_0x3841c2['toLowerCase']();};}exports[_0xb49b('0xa')]=function(_0x425527,_0x2cc6bb,_0x1dbc48,_0x3ca9ca){return function(_0x2a6247){try{var _0x11ef0d={'name':_0x2cc6bb[0x0],'timeout':_0x2cc6bb[0x1]};var _0x1518d3=queue['validate'](_0x11ef0d,{'typecast':!![]});if(_0x1518d3[_0xb49b('0xb')]){logger[_0xb49b('0xc')](_0xb49b('0xd'),_0x425527,_[_0xb49b('0xe')](_0x1518d3,'message')['join'](',\x20'));_0x2a6247['stop']();}else{var _0x25bc61=_['find'](_0x1dbc48['agents'],handleFindAgent(_0x11ef0d[_0xb49b('0x9')]));if(_0x25bc61){var _0x5ce848=(_0x11ef0d[_0xb49b('0xf')]||0xa)*0x3e8;var _0x41bf14,_0x185ff6;var _0x4b9df9=seqqueue[_0xb49b('0x10')](_0x5ce848);_0x4b9df9['id']=_0x425527;_0x4b9df9[_0xb49b('0x11')]=_0x5ce848;_0x4b9df9[_0xb49b('0x12')]=_0x3ca9ca['channel'];writeLog(_0x425527,_0x25bc61,util[_0xb49b('0x7')](_0xb49b('0x13'),_0x5ce848));_0x1dbc48[_0xb49b('0x14')][_0x425527]['on']('end',function(){logger[_0xb49b('0x15')](_0xb49b('0x16'),_0x425527);clearTimeout(_0x185ff6);_0x185ff6=undefined;_0x4b9df9[_0xb49b('0x17')]();if(_0x1dbc48[_0xb49b('0x14')][_0x425527]){delete _0x1dbc48[_0xb49b('0x14')][_0x425527];}_0x2a6247[_0xb49b('0x18')]();});_0x1dbc48[_0xb49b('0x14')][_0x425527]['on'](_0xb49b('0x19'),function(){if(_0x1dbc48[_0xb49b('0x14')][_0x425527]){delete _0x1dbc48[_0xb49b('0x14')][_0x425527];}});_0x185ff6=setTimeout(function(){logger[_0xb49b('0x15')](_0xb49b('0x1a'),_0x425527);clearTimeout(_0x185ff6);_0x4b9df9[_0xb49b('0x17')]();_0x2a6247[_0xb49b('0x1b')]();},_0x5ce848);strategy[_0xb49b('0x1c')](_0x4b9df9,_0x25bc61,_0x1dbc48,_0x3ca9ca);}else{logger[_0xb49b('0xc')](_0xb49b('0x1d'),_0x425527,_0x11ef0d[_0xb49b('0x9')]);_0x2a6247[_0xb49b('0x18')]();}}}catch(_0x282507){console[_0xb49b('0x1e')](_0x282507);logger['error'](_0xb49b('0x1f'),_0x425527,_0x282507[_0xb49b('0x20')]);_0x2a6247[_0xb49b('0x18')]();}};};