839d88307c81d30d7f10c248a504c7ceb3bb17c1
[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 _0xac44=['timeout\x20is\x20a\x20number','info','format','name','toLowerCase','length','error','[%s][AGENT]\x20%s','map','join','find','timeout','createQueue','channel','START:%s','rules','end','close','stop','complete','[%s][AGENT]\x20ROUTING\x20END','next','agent','[%s][AGENT]\x20agent\x20not\x20found\x20%s','[%s][QUEUE]\x20%s','stack','validate','util','seq-queue','../../../../config/logger','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number'];(function(_0x254435,_0x2565da){var _0x484b59=function(_0x340b5a){while(--_0x340b5a){_0x254435['push'](_0x254435['shift']());}};_0x484b59(++_0x2565da);}(_0xac44,0x143));var _0x4ac4=function(_0x288598,_0x404a76){_0x288598=_0x288598-0x0;var _0x44c336=_0xac44[_0x288598];return _0x44c336;};'use strict';var schema=require(_0x4ac4('0x0'));var _=require('lodash');var util=require(_0x4ac4('0x1'));var seqqueue=require(_0x4ac4('0x2'));var logger=require(_0x4ac4('0x3'))('routing');var strategy=require('./strategy');var queue=schema({'name':{'type':_0x4ac4('0x4'),'required':!![],'message':_0x4ac4('0x5')},'timeout':{'type':_0x4ac4('0x6'),'message':_0x4ac4('0x7')}});function writeLog(_0x21ed24,_0x23654a,_0x4fcf24){return logger[_0x4ac4('0x8')](util[_0x4ac4('0x9')]('[%s][AGENT][NAME:%s][STATUS:%s]',_0x21ed24,_0x23654a['name'],_0x4fcf24));}function handleFindAgent(_0x4445e2){return function(_0x433437){return _0x433437[_0x4ac4('0xa')][_0x4ac4('0xb')]()===_0x4445e2['toLowerCase']();};}exports['consequence']=function(_0x22ea45,_0x58ea4b,_0x4f011f,_0x37a5c4){return function(_0xdd68ec){try{var _0x4c17db={'name':_0x58ea4b[0x0],'timeout':_0x58ea4b[0x1]};var _0x1117f8=queue['validate'](_0x4c17db,{'typecast':!![]});if(_0x1117f8[_0x4ac4('0xc')]){logger[_0x4ac4('0xd')](_0x4ac4('0xe'),_0x22ea45,_[_0x4ac4('0xf')](_0x1117f8,'message')[_0x4ac4('0x10')](',\x20'));_0xdd68ec['stop']();}else{var _0x4994d9=_[_0x4ac4('0x11')](_0x4f011f['agents'],handleFindAgent(_0x4c17db['name']));if(_0x4994d9){var _0xc372bc=(_0x4c17db[_0x4ac4('0x12')]||0xa)*0x3e8;var _0x55615b,_0x194e55;var _0x5028f1=seqqueue[_0x4ac4('0x13')](_0xc372bc);_0x5028f1['id']=_0x22ea45;_0x5028f1['atimeout']=_0xc372bc;_0x5028f1['channel']=_0x37a5c4[_0x4ac4('0x14')];writeLog(_0x22ea45,_0x4994d9,util[_0x4ac4('0x9')](_0x4ac4('0x15'),_0xc372bc));_0x4f011f[_0x4ac4('0x16')][_0x22ea45]['on'](_0x4ac4('0x17'),function(){logger['info']('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x22ea45);clearTimeout(_0x194e55);_0x194e55=undefined;_0x5028f1[_0x4ac4('0x18')]();if(_0x4f011f[_0x4ac4('0x16')][_0x22ea45]){delete _0x4f011f[_0x4ac4('0x16')][_0x22ea45];}_0xdd68ec[_0x4ac4('0x19')]();});_0x4f011f[_0x4ac4('0x16')][_0x22ea45]['on'](_0x4ac4('0x1a'),function(){if(_0x4f011f[_0x4ac4('0x16')][_0x22ea45]){delete _0x4f011f[_0x4ac4('0x16')][_0x22ea45];}});_0x194e55=setTimeout(function(){logger[_0x4ac4('0x8')](_0x4ac4('0x1b'),_0x22ea45);clearTimeout(_0x194e55);_0x5028f1[_0x4ac4('0x18')]();_0xdd68ec[_0x4ac4('0x1c')]();},_0xc372bc);strategy[_0x4ac4('0x1d')](_0x5028f1,_0x4994d9,_0x4f011f,_0x37a5c4);}else{logger[_0x4ac4('0xd')](_0x4ac4('0x1e'),_0x22ea45,_0x4c17db['name']);_0xdd68ec[_0x4ac4('0x19')]();}}}catch(_0x15fb3e){console['log'](_0x15fb3e);logger['error'](_0x4ac4('0x1f'),_0x22ea45,_0x15fb3e[_0x4ac4('0x20')]);_0xdd68ec['stop']();}};};