Built motion from commit (unavailable).|2.5.15
[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 _0x47f1=['timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','toLowerCase','validate','length','error','[%s][AGENT]\x20%s','map','message','join','stop','find','name','timeout','createQueue','atimeout','channel','rules','end','complete','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','log','[%s][QUEUE]\x20%s','stack','lodash','util','../../../../config/logger','routing','./strategy','string'];(function(_0x39cbf3,_0x1b0d92){var _0x18818e=function(_0x492802){while(--_0x492802){_0x39cbf3['push'](_0x39cbf3['shift']());}};_0x18818e(++_0x1b0d92);}(_0x47f1,0x135));var _0x147f=function(_0x4b9283,_0x75dee4){_0x4b9283=_0x4b9283-0x0;var _0x2b6050=_0x47f1[_0x4b9283];return _0x2b6050;};'use strict';var schema=require('validate');var _=require(_0x147f('0x0'));var util=require(_0x147f('0x1'));var seqqueue=require('seq-queue');var logger=require(_0x147f('0x2'))(_0x147f('0x3'));var strategy=require(_0x147f('0x4'));var queue=schema({'name':{'type':_0x147f('0x5'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':'number','message':_0x147f('0x6')}});function writeLog(_0x9fe910,_0x12d1fd,_0x452025){return logger[_0x147f('0x7')](util[_0x147f('0x8')](_0x147f('0x9'),_0x9fe910,_0x12d1fd['name'],_0x452025));}function handleFindAgent(_0x55346c){return function(_0x4a96ec){return _0x4a96ec['name'][_0x147f('0xa')]()===_0x55346c[_0x147f('0xa')]();};}exports['consequence']=function(_0x48de59,_0x1e85c2,_0x32a6f8,_0x232e26){return function(_0x1e3c65){try{var _0x284ad5={'name':_0x1e85c2[0x0],'timeout':_0x1e85c2[0x1]};var _0x245630=queue[_0x147f('0xb')](_0x284ad5,{'typecast':!![]});if(_0x245630[_0x147f('0xc')]){logger[_0x147f('0xd')](_0x147f('0xe'),_0x48de59,_[_0x147f('0xf')](_0x245630,_0x147f('0x10'))[_0x147f('0x11')](',\x20'));_0x1e3c65[_0x147f('0x12')]();}else{var _0x3ae963=_[_0x147f('0x13')](_0x32a6f8['agents'],handleFindAgent(_0x284ad5[_0x147f('0x14')]));if(_0x3ae963){var _0x1a10d5=(_0x284ad5[_0x147f('0x15')]||0xa)*0x3e8;var _0x518d55,_0x3def6a;var _0x5af5f3=seqqueue[_0x147f('0x16')](_0x1a10d5);_0x5af5f3['id']=_0x48de59;_0x5af5f3[_0x147f('0x17')]=_0x1a10d5;_0x5af5f3[_0x147f('0x18')]=_0x232e26['channel'];writeLog(_0x48de59,_0x3ae963,util['format']('START:%s',_0x1a10d5));_0x32a6f8[_0x147f('0x19')][_0x48de59]['on'](_0x147f('0x1a'),function(){logger[_0x147f('0x7')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x48de59);clearTimeout(_0x3def6a);_0x3def6a=undefined;_0x5af5f3['close']();if(_0x32a6f8[_0x147f('0x19')][_0x48de59]){delete _0x32a6f8['rules'][_0x48de59];}_0x1e3c65[_0x147f('0x12')]();});_0x32a6f8[_0x147f('0x19')][_0x48de59]['on'](_0x147f('0x1b'),function(){if(_0x32a6f8[_0x147f('0x19')][_0x48de59]){delete _0x32a6f8['rules'][_0x48de59];}});_0x3def6a=setTimeout(function(){logger[_0x147f('0x7')](_0x147f('0x1c'),_0x48de59);clearTimeout(_0x3def6a);_0x5af5f3[_0x147f('0x1d')]();_0x1e3c65[_0x147f('0x1e')]();},_0x1a10d5);strategy[_0x147f('0x1f')](_0x5af5f3,_0x3ae963,_0x32a6f8,_0x232e26);}else{logger[_0x147f('0xd')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x48de59,_0x284ad5[_0x147f('0x14')]);_0x1e3c65[_0x147f('0x12')]();}}}catch(_0x135660){console[_0x147f('0x20')](_0x135660);logger[_0x147f('0xd')](_0x147f('0x21'),_0x48de59,_0x135660[_0x147f('0x22')]);_0x1e3c65[_0x147f('0x12')]();}};};