4717afee61921574d40d386b4aee2004d8004928
[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 _0x13ba=['stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','error','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack','lodash','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','info','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','consequence','[%s][AGENT]\x20%s','map','message','join','find','agents','timeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close'];(function(_0x3dd637,_0x4af815){var _0x1441f4=function(_0x514b6e){while(--_0x514b6e){_0x3dd637['push'](_0x3dd637['shift']());}};_0x1441f4(++_0x4af815);}(_0x13ba,0x1e5));var _0xa13b=function(_0x56857c,_0x4868cb){_0x56857c=_0x56857c-0x0;var _0x4027e7=_0x13ba[_0x56857c];return _0x4027e7;};'use strict';var schema=require('validate');var _=require(_0xa13b('0x0'));var util=require('util');var seqqueue=require('seq-queue');var logger=require(_0xa13b('0x1'))(_0xa13b('0x2'));var strategy=require(_0xa13b('0x3'));var queue=schema({'name':{'type':_0xa13b('0x4'),'required':!![],'message':_0xa13b('0x5')},'timeout':{'type':_0xa13b('0x6'),'message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x1de8f7,_0x112d5c,_0x31fd33){return logger[_0xa13b('0x7')](util['format'](_0xa13b('0x8'),_0x1de8f7,_0x112d5c[_0xa13b('0x9')],_0x31fd33));}function handleFindAgent(_0x151ae5){return function(_0x1f42d3){return _0x1f42d3['name']['toLowerCase']()===_0x151ae5[_0xa13b('0xa')]();};}exports[_0xa13b('0xb')]=function(_0x308e3d,_0x318ddb,_0xd6b962,_0x2f9f10){return function(_0x3d85a2){try{var _0x522ef9={'name':_0x318ddb[0x0],'timeout':_0x318ddb[0x1]};var _0x3ddffb=queue['validate'](_0x522ef9,{'typecast':!![]});if(_0x3ddffb['length']){logger['error'](_0xa13b('0xc'),_0x308e3d,_[_0xa13b('0xd')](_0x3ddffb,_0xa13b('0xe'))[_0xa13b('0xf')](',\x20'));_0x3d85a2['stop']();}else{var _0x2425fb=_[_0xa13b('0x10')](_0xd6b962[_0xa13b('0x11')],handleFindAgent(_0x522ef9[_0xa13b('0x9')]));if(_0x2425fb){var _0xa968fd=(_0x522ef9[_0xa13b('0x12')]||0xa)*0x3e8;var _0x21d318,_0x1c2a71;var _0x383686=seqqueue['createQueue'](_0xa968fd);_0x383686['id']=_0x308e3d;_0x383686['atimeout']=_0xa968fd;_0x383686[_0xa13b('0x13')]=_0x2f9f10[_0xa13b('0x13')];writeLog(_0x308e3d,_0x2425fb,util['format'](_0xa13b('0x14'),_0xa968fd));_0xd6b962[_0xa13b('0x15')][_0x308e3d]['on'](_0xa13b('0x16'),function(){logger[_0xa13b('0x7')](_0xa13b('0x17'),_0x308e3d);clearTimeout(_0x1c2a71);_0x1c2a71=undefined;_0x383686[_0xa13b('0x18')]();if(_0xd6b962[_0xa13b('0x15')][_0x308e3d]){delete _0xd6b962[_0xa13b('0x15')][_0x308e3d];}_0x3d85a2[_0xa13b('0x19')]();});_0xd6b962[_0xa13b('0x15')][_0x308e3d]['on'](_0xa13b('0x1a'),function(){if(_0xd6b962[_0xa13b('0x15')][_0x308e3d]){delete _0xd6b962[_0xa13b('0x15')][_0x308e3d];}});_0x1c2a71=setTimeout(function(){logger[_0xa13b('0x7')](_0xa13b('0x1b'),_0x308e3d);clearTimeout(_0x1c2a71);_0x383686[_0xa13b('0x18')]();_0x3d85a2[_0xa13b('0x1c')]();},_0xa968fd);strategy[_0xa13b('0x1d')](_0x383686,_0x2425fb,_0xd6b962,_0x2f9f10);}else{logger[_0xa13b('0x1e')](_0xa13b('0x1f'),_0x308e3d,_0x522ef9['name']);_0x3d85a2[_0xa13b('0x19')]();}}}catch(_0x5d76f7){console['log'](_0x5d76f7);logger[_0xa13b('0x1e')](_0xa13b('0x20'),_0x308e3d,_0x5d76f7[_0xa13b('0x21')]);_0x3d85a2[_0xa13b('0x19')]();}};};