f0d6a78bba264494e5a42b96a6453e69c99f99b9
[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 _0x90fe=['log','[%s][QUEUE]\x20%s','stack','lodash','util','seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','message','stop','find','agents','timeout','createQueue','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','[%s][AGENT]\x20ROUTING\x20END','next','agent'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x90fe,0x106));var _0xe90f=function(_0x48ca88,_0x285255){_0x48ca88=_0x48ca88-0x0;var _0x39f9ca=_0x90fe[_0x48ca88];return _0x39f9ca;};'use strict';var schema=require('validate');var _=require(_0xe90f('0x0'));var util=require(_0xe90f('0x1'));var seqqueue=require(_0xe90f('0x2'));var logger=require(_0xe90f('0x3'))(_0xe90f('0x4'));var strategy=require(_0xe90f('0x5'));var queue=schema({'name':{'type':_0xe90f('0x6'),'required':!![],'message':_0xe90f('0x7')},'timeout':{'type':_0xe90f('0x8'),'message':_0xe90f('0x9')}});function writeLog(_0x40f303,_0x1999c1,_0x52f3ed){return logger[_0xe90f('0xa')](util[_0xe90f('0xb')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x40f303,_0x1999c1[_0xe90f('0xc')],_0x52f3ed));}function handleFindAgent(_0x7fbaf3){return function(_0x26c402){return _0x26c402[_0xe90f('0xc')]['toLowerCase']()===_0x7fbaf3[_0xe90f('0xd')]();};}exports[_0xe90f('0xe')]=function(_0x1d6cc3,_0x6d8f89,_0x3ed296,_0x525840){return function(_0x5924d7){try{var _0xd0ad8c={'name':_0x6d8f89[0x0],'timeout':_0x6d8f89[0x1]};var _0x3fcc2c=queue['validate'](_0xd0ad8c,{'typecast':!![]});if(_0x3fcc2c[_0xe90f('0xf')]){logger[_0xe90f('0x10')](_0xe90f('0x11'),_0x1d6cc3,_['map'](_0x3fcc2c,_0xe90f('0x12'))['join'](',\x20'));_0x5924d7[_0xe90f('0x13')]();}else{var _0x239edf=_[_0xe90f('0x14')](_0x3ed296[_0xe90f('0x15')],handleFindAgent(_0xd0ad8c[_0xe90f('0xc')]));if(_0x239edf){var _0x4481d0=(_0xd0ad8c[_0xe90f('0x16')]||0xa)*0x3e8;var _0x273544,_0x24e244;var _0x227a66=seqqueue[_0xe90f('0x17')](_0x4481d0);_0x227a66['id']=_0x1d6cc3;_0x227a66[_0xe90f('0x18')]=_0x4481d0;_0x227a66[_0xe90f('0x19')]=_0x525840[_0xe90f('0x19')];writeLog(_0x1d6cc3,_0x239edf,util[_0xe90f('0xb')](_0xe90f('0x1a'),_0x4481d0));_0x3ed296[_0xe90f('0x1b')][_0x1d6cc3]['on'](_0xe90f('0x1c'),function(){logger[_0xe90f('0xa')](_0xe90f('0x1d'),_0x1d6cc3);clearTimeout(_0x24e244);_0x24e244=undefined;_0x227a66[_0xe90f('0x1e')]();if(_0x3ed296[_0xe90f('0x1b')][_0x1d6cc3]){delete _0x3ed296[_0xe90f('0x1b')][_0x1d6cc3];}_0x5924d7[_0xe90f('0x13')]();});_0x3ed296[_0xe90f('0x1b')][_0x1d6cc3]['on']('complete',function(){if(_0x3ed296[_0xe90f('0x1b')][_0x1d6cc3]){delete _0x3ed296['rules'][_0x1d6cc3];}});_0x24e244=setTimeout(function(){logger['info'](_0xe90f('0x1f'),_0x1d6cc3);clearTimeout(_0x24e244);_0x227a66['close']();_0x5924d7[_0xe90f('0x20')]();},_0x4481d0);strategy[_0xe90f('0x21')](_0x227a66,_0x239edf,_0x3ed296,_0x525840);}else{logger[_0xe90f('0x10')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x1d6cc3,_0xd0ad8c[_0xe90f('0xc')]);_0x5924d7[_0xe90f('0x13')]();}}}catch(_0x5575c5){console[_0xe90f('0x22')](_0x5575c5);logger['error'](_0xe90f('0x23'),_0x1d6cc3,_0x5575c5[_0xe90f('0x24')]);_0x5924d7['stop']();}};};