Built motion from commit (unavailable).|2.4.21
[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 _0xf619=['message','join','find','timeout','createQueue','channel','format','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','seq-queue','../../../../config/logger','./strategy','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','timeout\x20is\x20a\x20number','info','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','map'];(function(_0x8f82df,_0x4ad0e9){var _0x19212a=function(_0xa30958){while(--_0xa30958){_0x8f82df['push'](_0x8f82df['shift']());}};_0x19212a(++_0x4ad0e9);}(_0xf619,0x7c));var _0x9f61=function(_0x11387a,_0x9d398e){_0x11387a=_0x11387a-0x0;var _0x54fc5c=_0xf619[_0x11387a];return _0x54fc5c;};'use strict';var schema=require(_0x9f61('0x0'));var _=require(_0x9f61('0x1'));var util=require(_0x9f61('0x2'));var seqqueue=require(_0x9f61('0x3'));var logger=require(_0x9f61('0x4'))('routing');var strategy=require(_0x9f61('0x5'));var queue=schema({'name':{'type':'string','required':!![],'message':_0x9f61('0x6')},'timeout':{'type':'number','message':_0x9f61('0x7')}});function writeLog(_0x68324e,_0x4f8563,_0xeb63aa){return logger[_0x9f61('0x8')](util['format']('[%s][AGENT][NAME:%s][STATUS:%s]',_0x68324e,_0x4f8563[_0x9f61('0x9')],_0xeb63aa));}function handleFindAgent(_0x40282d){return function(_0x13e72a){return _0x13e72a[_0x9f61('0x9')]['toLowerCase']()===_0x40282d[_0x9f61('0xa')]();};}exports[_0x9f61('0xb')]=function(_0xe3ba10,_0x4ca51b,_0x231732,_0x21d72f){return function(_0xe142a0){try{var _0x450dcf={'name':_0x4ca51b[0x0],'timeout':_0x4ca51b[0x1]};var _0x315747=queue[_0x9f61('0x0')](_0x450dcf,{'typecast':!![]});if(_0x315747[_0x9f61('0xc')]){logger[_0x9f61('0xd')](_0x9f61('0xe'),_0xe3ba10,_[_0x9f61('0xf')](_0x315747,_0x9f61('0x10'))[_0x9f61('0x11')](',\x20'));_0xe142a0['stop']();}else{var _0x15c12d=_[_0x9f61('0x12')](_0x231732['agents'],handleFindAgent(_0x450dcf[_0x9f61('0x9')]));if(_0x15c12d){var _0x1c8373=(_0x450dcf[_0x9f61('0x13')]||0xa)*0x3e8;var _0x15e6e6,_0x74d620;var _0x43838f=seqqueue[_0x9f61('0x14')](_0x1c8373);_0x43838f['id']=_0xe3ba10;_0x43838f['atimeout']=_0x1c8373;_0x43838f[_0x9f61('0x15')]=_0x21d72f[_0x9f61('0x15')];writeLog(_0xe3ba10,_0x15c12d,util[_0x9f61('0x16')]('START:%s',_0x1c8373));_0x231732[_0x9f61('0x17')][_0xe3ba10]['on'](_0x9f61('0x18'),function(){logger[_0x9f61('0x8')](_0x9f61('0x19'),_0xe3ba10);clearTimeout(_0x74d620);_0x74d620=undefined;_0x43838f['close']();if(_0x231732[_0x9f61('0x17')][_0xe3ba10]){delete _0x231732[_0x9f61('0x17')][_0xe3ba10];}_0xe142a0[_0x9f61('0x1a')]();});_0x231732[_0x9f61('0x17')][_0xe3ba10]['on'](_0x9f61('0x1b'),function(){if(_0x231732[_0x9f61('0x17')][_0xe3ba10]){delete _0x231732[_0x9f61('0x17')][_0xe3ba10];}});_0x74d620=setTimeout(function(){logger[_0x9f61('0x8')](_0x9f61('0x1c'),_0xe3ba10);clearTimeout(_0x74d620);_0x43838f['close']();_0xe142a0[_0x9f61('0x1d')]();},_0x1c8373);strategy[_0x9f61('0x1e')](_0x43838f,_0x15c12d,_0x231732,_0x21d72f);}else{logger[_0x9f61('0xd')](_0x9f61('0x1f'),_0xe3ba10,_0x450dcf[_0x9f61('0x9')]);_0xe142a0[_0x9f61('0x1a')]();}}}catch(_0x16971f){console[_0x9f61('0x20')](_0x16971f);logger['error'](_0x9f61('0x21'),_0xe3ba10,_0x16971f[_0x9f61('0x22')]);_0xe142a0[_0x9f61('0x1a')]();}};};