Built motion from commit 85328c08.|2.5.50
[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 _0x14d2=['format','name','toLowerCase','length','error','map','join','stop','agents','timeout','createQueue','atimeout','channel','START:%s','rules','info','[%s][AGENT]\x20ROUTING\x20STOPPED','complete','close','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','util','seq-queue','../../../../config/logger','routing','./strategy','string'];(function(_0x21c74d,_0x36a28d){var _0x293cd1=function(_0x532501){while(--_0x532501){_0x21c74d['push'](_0x21c74d['shift']());}};_0x293cd1(++_0x36a28d);}(_0x14d2,0x107));var _0x214d=function(_0x1532a7,_0x46f0b3){_0x1532a7=_0x1532a7-0x0;var _0x53e269=_0x14d2[_0x1532a7];return _0x53e269;};'use strict';var schema=require(_0x214d('0x0'));var _=require('lodash');var util=require(_0x214d('0x1'));var seqqueue=require(_0x214d('0x2'));var logger=require(_0x214d('0x3'))(_0x214d('0x4'));var strategy=require(_0x214d('0x5'));var queue=schema({'name':{'type':_0x214d('0x6'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':'number','message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x481b07,_0x3cc930,_0x413c0e){return logger['info'](util[_0x214d('0x7')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x481b07,_0x3cc930['name'],_0x413c0e));}function handleFindAgent(_0x1a36b3){return function(_0x138203){return _0x138203[_0x214d('0x8')][_0x214d('0x9')]()===_0x1a36b3[_0x214d('0x9')]();};}exports['consequence']=function(_0x4fb795,_0x12ab58,_0x2dba32,_0x4c008b){return function(_0x196633){try{var _0x468c98={'name':_0x12ab58[0x0],'timeout':_0x12ab58[0x1]};var _0x483607=queue[_0x214d('0x0')](_0x468c98,{'typecast':!![]});if(_0x483607[_0x214d('0xa')]){logger[_0x214d('0xb')]('[%s][AGENT]\x20%s',_0x4fb795,_[_0x214d('0xc')](_0x483607,'message')[_0x214d('0xd')](',\x20'));_0x196633[_0x214d('0xe')]();}else{var _0x29fedf=_['find'](_0x2dba32[_0x214d('0xf')],handleFindAgent(_0x468c98[_0x214d('0x8')]));if(_0x29fedf){var _0x555519=(_0x468c98[_0x214d('0x10')]||0xa)*0x3e8;var _0x26164a,_0x41ee9e;var _0x446e99=seqqueue[_0x214d('0x11')](_0x555519);_0x446e99['id']=_0x4fb795;_0x446e99[_0x214d('0x12')]=_0x555519;_0x446e99['channel']=_0x4c008b[_0x214d('0x13')];writeLog(_0x4fb795,_0x29fedf,util[_0x214d('0x7')](_0x214d('0x14'),_0x555519));_0x2dba32[_0x214d('0x15')][_0x4fb795]['on']('end',function(){logger[_0x214d('0x16')](_0x214d('0x17'),_0x4fb795);clearTimeout(_0x41ee9e);_0x41ee9e=undefined;_0x446e99['close']();if(_0x2dba32[_0x214d('0x15')][_0x4fb795]){delete _0x2dba32['rules'][_0x4fb795];}_0x196633['stop']();});_0x2dba32['rules'][_0x4fb795]['on'](_0x214d('0x18'),function(){if(_0x2dba32[_0x214d('0x15')][_0x4fb795]){delete _0x2dba32[_0x214d('0x15')][_0x4fb795];}});_0x41ee9e=setTimeout(function(){logger[_0x214d('0x16')]('[%s][AGENT]\x20ROUTING\x20END',_0x4fb795);clearTimeout(_0x41ee9e);_0x446e99[_0x214d('0x19')]();_0x196633['next']();},_0x555519);strategy['agent'](_0x446e99,_0x29fedf,_0x2dba32,_0x4c008b);}else{logger[_0x214d('0xb')](_0x214d('0x1a'),_0x4fb795,_0x468c98['name']);_0x196633[_0x214d('0xe')]();}}}catch(_0x5a300a){console[_0x214d('0x1b')](_0x5a300a);logger[_0x214d('0xb')](_0x214d('0x1c'),_0x4fb795,_0x5a300a[_0x214d('0x1d')]);_0x196633[_0x214d('0xe')]();}};};