Built motion from commit 9d1906d1.|2.5.40
[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 _0xb7a6=['number','timeout\x20is\x20a\x20number','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','length','error','[%s][AGENT]\x20%s','message','join','find','agents','timeout','createQueue','atimeout','channel','format','START:%s','rules','info','[%s][AGENT]\x20ROUTING\x20STOPPED','close','stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','validate','lodash','seq-queue','../../../../config/logger','routing','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'];(function(_0x544463,_0x214963){var _0x1add2a=function(_0x5e1006){while(--_0x5e1006){_0x544463['push'](_0x544463['shift']());}};_0x1add2a(++_0x214963);}(_0xb7a6,0x66));var _0x6b7a=function(_0x1967f8,_0x126c17){_0x1967f8=_0x1967f8-0x0;var _0x2d67c5=_0xb7a6[_0x1967f8];return _0x2d67c5;};'use strict';var schema=require(_0x6b7a('0x0'));var _=require(_0x6b7a('0x1'));var util=require('util');var seqqueue=require(_0x6b7a('0x2'));var logger=require(_0x6b7a('0x3'))(_0x6b7a('0x4'));var strategy=require('./strategy');var queue=schema({'name':{'type':'string','required':!![],'message':_0x6b7a('0x5')},'timeout':{'type':_0x6b7a('0x6'),'message':_0x6b7a('0x7')}});function writeLog(_0x52271a,_0x5df617,_0x122521){return logger['info'](util['format'](_0x6b7a('0x8'),_0x52271a,_0x5df617[_0x6b7a('0x9')],_0x122521));}function handleFindAgent(_0x4f3449){return function(_0x4cd8ab){return _0x4cd8ab[_0x6b7a('0x9')][_0x6b7a('0xa')]()===_0x4f3449[_0x6b7a('0xa')]();};}exports[_0x6b7a('0xb')]=function(_0x195073,_0x48a754,_0x21eb42,_0x5b6833){return function(_0x127d0c){try{var _0x3cbf59={'name':_0x48a754[0x0],'timeout':_0x48a754[0x1]};var _0x3ef567=queue[_0x6b7a('0x0')](_0x3cbf59,{'typecast':!![]});if(_0x3ef567[_0x6b7a('0xc')]){logger[_0x6b7a('0xd')](_0x6b7a('0xe'),_0x195073,_['map'](_0x3ef567,_0x6b7a('0xf'))[_0x6b7a('0x10')](',\x20'));_0x127d0c['stop']();}else{var _0x507dc4=_[_0x6b7a('0x11')](_0x21eb42[_0x6b7a('0x12')],handleFindAgent(_0x3cbf59[_0x6b7a('0x9')]));if(_0x507dc4){var _0x23930e=(_0x3cbf59[_0x6b7a('0x13')]||0xa)*0x3e8;var _0x1eab7c,_0x4ce5a1;var _0x285957=seqqueue[_0x6b7a('0x14')](_0x23930e);_0x285957['id']=_0x195073;_0x285957[_0x6b7a('0x15')]=_0x23930e;_0x285957['channel']=_0x5b6833[_0x6b7a('0x16')];writeLog(_0x195073,_0x507dc4,util[_0x6b7a('0x17')](_0x6b7a('0x18'),_0x23930e));_0x21eb42[_0x6b7a('0x19')][_0x195073]['on']('end',function(){logger[_0x6b7a('0x1a')](_0x6b7a('0x1b'),_0x195073);clearTimeout(_0x4ce5a1);_0x4ce5a1=undefined;_0x285957[_0x6b7a('0x1c')]();if(_0x21eb42[_0x6b7a('0x19')][_0x195073]){delete _0x21eb42['rules'][_0x195073];}_0x127d0c[_0x6b7a('0x1d')]();});_0x21eb42[_0x6b7a('0x19')][_0x195073]['on'](_0x6b7a('0x1e'),function(){if(_0x21eb42['rules'][_0x195073]){delete _0x21eb42['rules'][_0x195073];}});_0x4ce5a1=setTimeout(function(){logger[_0x6b7a('0x1a')](_0x6b7a('0x1f'),_0x195073);clearTimeout(_0x4ce5a1);_0x285957[_0x6b7a('0x1c')]();_0x127d0c[_0x6b7a('0x20')]();},_0x23930e);strategy[_0x6b7a('0x21')](_0x285957,_0x507dc4,_0x21eb42,_0x5b6833);}else{logger[_0x6b7a('0xd')](_0x6b7a('0x22'),_0x195073,_0x3cbf59[_0x6b7a('0x9')]);_0x127d0c[_0x6b7a('0x1d')]();}}}catch(_0x1bf028){console['log'](_0x1bf028);logger['error'](_0x6b7a('0x23'),_0x195073,_0x1bf028['stack']);_0x127d0c[_0x6b7a('0x1d')]();}};};