5ba259aa98568c49e45a6842cc93b435ba023001
[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 _0xa414=['[%s][AGENT]\x20%s','map','message','stop','find','name','timeout','createQueue','atimeout','channel','rules','[%s][AGENT]\x20ROUTING\x20STOPPED','close','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','log','[%s][QUEUE]\x20%s','stack','validate','lodash','util','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','length','error'];(function(_0x2f1026,_0x3d013d){var _0x2e0112=function(_0x561de9){while(--_0x561de9){_0x2f1026['push'](_0x2f1026['shift']());}};_0x2e0112(++_0x3d013d);}(_0xa414,0x1f0));var _0x4a41=function(_0x22e6f0,_0x33f4ef){_0x22e6f0=_0x22e6f0-0x0;var _0x2f6395=_0xa414[_0x22e6f0];return _0x2f6395;};'use strict';var schema=require(_0x4a41('0x0'));var _=require(_0x4a41('0x1'));var util=require(_0x4a41('0x2'));var seqqueue=require('seq-queue');var logger=require(_0x4a41('0x3'))(_0x4a41('0x4'));var strategy=require(_0x4a41('0x5'));var queue=schema({'name':{'type':_0x4a41('0x6'),'required':!![],'message':_0x4a41('0x7')},'timeout':{'type':_0x4a41('0x8'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x40acc7,_0x223d13,_0x4eaa6a){return logger[_0x4a41('0x9')](util[_0x4a41('0xa')](_0x4a41('0xb'),_0x40acc7,_0x223d13['name'],_0x4eaa6a));}function handleFindAgent(_0x194296){return function(_0x3176d1){return _0x3176d1['name']['toLowerCase']()===_0x194296['toLowerCase']();};}exports['consequence']=function(_0x59725e,_0x4e68b3,_0x24c7d7,_0x20e9ac){return function(_0x33d0cb){try{var _0x3485d4={'name':_0x4e68b3[0x0],'timeout':_0x4e68b3[0x1]};var _0x4c3534=queue[_0x4a41('0x0')](_0x3485d4,{'typecast':!![]});if(_0x4c3534[_0x4a41('0xc')]){logger[_0x4a41('0xd')](_0x4a41('0xe'),_0x59725e,_[_0x4a41('0xf')](_0x4c3534,_0x4a41('0x10'))['join'](',\x20'));_0x33d0cb[_0x4a41('0x11')]();}else{var _0xd5b870=_[_0x4a41('0x12')](_0x24c7d7['agents'],handleFindAgent(_0x3485d4[_0x4a41('0x13')]));if(_0xd5b870){var _0x4e3247=(_0x3485d4[_0x4a41('0x14')]||0xa)*0x3e8;var _0x17c6a0,_0x1be7dc;var _0x21acb9=seqqueue[_0x4a41('0x15')](_0x4e3247);_0x21acb9['id']=_0x59725e;_0x21acb9[_0x4a41('0x16')]=_0x4e3247;_0x21acb9[_0x4a41('0x17')]=_0x20e9ac[_0x4a41('0x17')];writeLog(_0x59725e,_0xd5b870,util[_0x4a41('0xa')]('START:%s',_0x4e3247));_0x24c7d7[_0x4a41('0x18')][_0x59725e]['on']('end',function(){logger['info'](_0x4a41('0x19'),_0x59725e);clearTimeout(_0x1be7dc);_0x1be7dc=undefined;_0x21acb9[_0x4a41('0x1a')]();if(_0x24c7d7[_0x4a41('0x18')][_0x59725e]){delete _0x24c7d7[_0x4a41('0x18')][_0x59725e];}_0x33d0cb[_0x4a41('0x11')]();});_0x24c7d7[_0x4a41('0x18')][_0x59725e]['on'](_0x4a41('0x1b'),function(){if(_0x24c7d7[_0x4a41('0x18')][_0x59725e]){delete _0x24c7d7[_0x4a41('0x18')][_0x59725e];}});_0x1be7dc=setTimeout(function(){logger[_0x4a41('0x9')](_0x4a41('0x1c'),_0x59725e);clearTimeout(_0x1be7dc);_0x21acb9[_0x4a41('0x1a')]();_0x33d0cb[_0x4a41('0x1d')]();},_0x4e3247);strategy[_0x4a41('0x1e')](_0x21acb9,_0xd5b870,_0x24c7d7,_0x20e9ac);}else{logger['error']('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x59725e,_0x3485d4[_0x4a41('0x13')]);_0x33d0cb[_0x4a41('0x11')]();}}}catch(_0x34089a){console[_0x4a41('0x1f')](_0x34089a);logger['error'](_0x4a41('0x20'),_0x59725e,_0x34089a[_0x4a41('0x21')]);_0x33d0cb[_0x4a41('0x11')]();}};};