614f43c3e9208fb85866dad17f01197c7be8383e
[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 _0x0cac=['rules','complete','[%s][AGENT]\x20ROUTING\x20END','close','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','[%s][QUEUE]\x20%s','validate','seq-queue','../../../../config/logger','routing','./strategy','number','timeout\x20is\x20a\x20number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','map','join','stop','find','agents','timeout','channel','format','START:%s','end','[%s][AGENT]\x20ROUTING\x20STOPPED'];(function(_0xb24a3e,_0x4a3594){var _0x4038d7=function(_0x1ea3c3){while(--_0x1ea3c3){_0xb24a3e['push'](_0xb24a3e['shift']());}};_0x4038d7(++_0x4a3594);}(_0x0cac,0x18a));var _0xc0ca=function(_0x2ed57c,_0x2935b8){_0x2ed57c=_0x2ed57c-0x0;var _0x3c8041=_0x0cac[_0x2ed57c];return _0x3c8041;};'use strict';var schema=require(_0xc0ca('0x0'));var _=require('lodash');var util=require('util');var seqqueue=require(_0xc0ca('0x1'));var logger=require(_0xc0ca('0x2'))(_0xc0ca('0x3'));var strategy=require(_0xc0ca('0x4'));var queue=schema({'name':{'type':'string','required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':_0xc0ca('0x5'),'message':_0xc0ca('0x6')}});function writeLog(_0xa11214,_0x1139b5,_0x4fdcd3){return logger[_0xc0ca('0x7')](util['format'](_0xc0ca('0x8'),_0xa11214,_0x1139b5['name'],_0x4fdcd3));}function handleFindAgent(_0x50257b){return function(_0x293736){return _0x293736[_0xc0ca('0x9')]['toLowerCase']()===_0x50257b[_0xc0ca('0xa')]();};}exports[_0xc0ca('0xb')]=function(_0x26fbfe,_0x22c679,_0x3fbd2d,_0x431f5b){return function(_0x4b6598){try{var _0xefa226={'name':_0x22c679[0x0],'timeout':_0x22c679[0x1]};var _0x1dd9ba=queue[_0xc0ca('0x0')](_0xefa226,{'typecast':!![]});if(_0x1dd9ba[_0xc0ca('0xc')]){logger[_0xc0ca('0xd')](_0xc0ca('0xe'),_0x26fbfe,_[_0xc0ca('0xf')](_0x1dd9ba,'message')[_0xc0ca('0x10')](',\x20'));_0x4b6598[_0xc0ca('0x11')]();}else{var _0x26db18=_[_0xc0ca('0x12')](_0x3fbd2d[_0xc0ca('0x13')],handleFindAgent(_0xefa226['name']));if(_0x26db18){var _0x3a9a58=(_0xefa226[_0xc0ca('0x14')]||0xa)*0x3e8;var _0x62a186,_0x3a067c;var _0x1241ac=seqqueue['createQueue'](_0x3a9a58);_0x1241ac['id']=_0x26fbfe;_0x1241ac['atimeout']=_0x3a9a58;_0x1241ac[_0xc0ca('0x15')]=_0x431f5b[_0xc0ca('0x15')];writeLog(_0x26fbfe,_0x26db18,util[_0xc0ca('0x16')](_0xc0ca('0x17'),_0x3a9a58));_0x3fbd2d['rules'][_0x26fbfe]['on'](_0xc0ca('0x18'),function(){logger[_0xc0ca('0x7')](_0xc0ca('0x19'),_0x26fbfe);clearTimeout(_0x3a067c);_0x3a067c=undefined;_0x1241ac['close']();if(_0x3fbd2d[_0xc0ca('0x1a')][_0x26fbfe]){delete _0x3fbd2d['rules'][_0x26fbfe];}_0x4b6598['stop']();});_0x3fbd2d[_0xc0ca('0x1a')][_0x26fbfe]['on'](_0xc0ca('0x1b'),function(){if(_0x3fbd2d[_0xc0ca('0x1a')][_0x26fbfe]){delete _0x3fbd2d[_0xc0ca('0x1a')][_0x26fbfe];}});_0x3a067c=setTimeout(function(){logger[_0xc0ca('0x7')](_0xc0ca('0x1c'),_0x26fbfe);clearTimeout(_0x3a067c);_0x1241ac[_0xc0ca('0x1d')]();_0x4b6598[_0xc0ca('0x1e')]();},_0x3a9a58);strategy[_0xc0ca('0x1f')](_0x1241ac,_0x26db18,_0x3fbd2d,_0x431f5b);}else{logger[_0xc0ca('0xd')](_0xc0ca('0x20'),_0x26fbfe,_0xefa226[_0xc0ca('0x9')]);_0x4b6598[_0xc0ca('0x11')]();}}}catch(_0x53f59d){console[_0xc0ca('0x21')](_0x53f59d);logger[_0xc0ca('0xd')](_0xc0ca('0x22'),_0x26fbfe,_0x53f59d['stack']);_0x4b6598[_0xc0ca('0x11')]();}};};