6f59881c914c3c8633385dc866819d5ffc9e2132
[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 _0x3f0f=['lodash','seq-queue','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','[%s][AGENT]\x20%s','map','join','stop','find','agents','timeout','atimeout','channel','rules','end','close','complete','next','error','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','stack','validate'];(function(_0x398f35,_0x359971){var _0x308e74=function(_0x241997){while(--_0x241997){_0x398f35['push'](_0x398f35['shift']());}};_0x308e74(++_0x359971);}(_0x3f0f,0x1cd));var _0xf3f0=function(_0x1d8fed,_0xead126){_0x1d8fed=_0x1d8fed-0x0;var _0x3deaac=_0x3f0f[_0x1d8fed];return _0x3deaac;};'use strict';var schema=require(_0xf3f0('0x0'));var _=require(_0xf3f0('0x1'));var util=require('util');var seqqueue=require(_0xf3f0('0x2'));var logger=require(_0xf3f0('0x3'))(_0xf3f0('0x4'));var strategy=require(_0xf3f0('0x5'));var queue=schema({'name':{'type':_0xf3f0('0x6'),'required':!![],'message':_0xf3f0('0x7')},'timeout':{'type':'number','message':_0xf3f0('0x8')}});function writeLog(_0x1572b9,_0x58ddb8,_0x54d938){return logger[_0xf3f0('0x9')](util[_0xf3f0('0xa')](_0xf3f0('0xb'),_0x1572b9,_0x58ddb8[_0xf3f0('0xc')],_0x54d938));}function handleFindAgent(_0x514637){return function(_0x2fab52){return _0x2fab52[_0xf3f0('0xc')][_0xf3f0('0xd')]()===_0x514637['toLowerCase']();};}exports[_0xf3f0('0xe')]=function(_0x3982b8,_0xf790a5,_0x1a1a94,_0x4047b7){return function(_0x23af7f){try{var _0x4be38d={'name':_0xf790a5[0x0],'timeout':_0xf790a5[0x1]};var _0x11e6fb=queue['validate'](_0x4be38d,{'typecast':!![]});if(_0x11e6fb['length']){logger['error'](_0xf3f0('0xf'),_0x3982b8,_[_0xf3f0('0x10')](_0x11e6fb,'message')[_0xf3f0('0x11')](',\x20'));_0x23af7f[_0xf3f0('0x12')]();}else{var _0x541643=_[_0xf3f0('0x13')](_0x1a1a94[_0xf3f0('0x14')],handleFindAgent(_0x4be38d[_0xf3f0('0xc')]));if(_0x541643){var _0x511dae=(_0x4be38d[_0xf3f0('0x15')]||0xa)*0x3e8;var _0x2c76ae,_0x5a44f6;var _0x3bc426=seqqueue['createQueue'](_0x511dae);_0x3bc426['id']=_0x3982b8;_0x3bc426[_0xf3f0('0x16')]=_0x511dae;_0x3bc426[_0xf3f0('0x17')]=_0x4047b7['channel'];writeLog(_0x3982b8,_0x541643,util[_0xf3f0('0xa')]('START:%s',_0x511dae));_0x1a1a94[_0xf3f0('0x18')][_0x3982b8]['on'](_0xf3f0('0x19'),function(){logger[_0xf3f0('0x9')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x3982b8);clearTimeout(_0x5a44f6);_0x5a44f6=undefined;_0x3bc426[_0xf3f0('0x1a')]();if(_0x1a1a94[_0xf3f0('0x18')][_0x3982b8]){delete _0x1a1a94[_0xf3f0('0x18')][_0x3982b8];}_0x23af7f[_0xf3f0('0x12')]();});_0x1a1a94['rules'][_0x3982b8]['on'](_0xf3f0('0x1b'),function(){if(_0x1a1a94[_0xf3f0('0x18')][_0x3982b8]){delete _0x1a1a94[_0xf3f0('0x18')][_0x3982b8];}});_0x5a44f6=setTimeout(function(){logger[_0xf3f0('0x9')]('[%s][AGENT]\x20ROUTING\x20END',_0x3982b8);clearTimeout(_0x5a44f6);_0x3bc426[_0xf3f0('0x1a')]();_0x23af7f[_0xf3f0('0x1c')]();},_0x511dae);strategy['agent'](_0x3bc426,_0x541643,_0x1a1a94,_0x4047b7);}else{logger[_0xf3f0('0x1d')](_0xf3f0('0x1e'),_0x3982b8,_0x4be38d[_0xf3f0('0xc')]);_0x23af7f[_0xf3f0('0x12')]();}}}catch(_0xca7c9b){console[_0xf3f0('0x1f')](_0xca7c9b);logger[_0xf3f0('0x1d')]('[%s][QUEUE]\x20%s',_0x3982b8,_0xca7c9b[_0xf3f0('0x20')]);_0x23af7f[_0xf3f0('0x12')]();}};};