Built motion from commit 753c950e.|2.5.42
[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 _0x685f=['toLowerCase','consequence','validate','length','error','[%s][AGENT]\x20%s','message','stop','timeout','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','[%s][AGENT]\x20ROUTING\x20END','next','agent','log','[%s][QUEUE]\x20%s','lodash','util','seq-queue','routing','./strategy','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','number','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name'];(function(_0x1bbc08,_0x444008){var _0x5d825b=function(_0x522920){while(--_0x522920){_0x1bbc08['push'](_0x1bbc08['shift']());}};_0x5d825b(++_0x444008);}(_0x685f,0x180));var _0xf685=function(_0x4b66bf,_0x581149){_0x4b66bf=_0x4b66bf-0x0;var _0x547ff4=_0x685f[_0x4b66bf];return _0x547ff4;};'use strict';var schema=require('validate');var _=require(_0xf685('0x0'));var util=require(_0xf685('0x1'));var seqqueue=require(_0xf685('0x2'));var logger=require('../../../../config/logger')(_0xf685('0x3'));var strategy=require(_0xf685('0x4'));var queue=schema({'name':{'type':'string','required':!![],'message':_0xf685('0x5')},'timeout':{'type':_0xf685('0x6'),'message':_0xf685('0x7')}});function writeLog(_0x141b3c,_0x321c34,_0x355538){return logger[_0xf685('0x8')](util[_0xf685('0x9')](_0xf685('0xa'),_0x141b3c,_0x321c34[_0xf685('0xb')],_0x355538));}function handleFindAgent(_0x28f713){return function(_0x2eee79){return _0x2eee79['name'][_0xf685('0xc')]()===_0x28f713[_0xf685('0xc')]();};}exports[_0xf685('0xd')]=function(_0x14cc46,_0x2e85c0,_0x1e6f31,_0x8eb10c){return function(_0x58b9cf){try{var _0x46d65c={'name':_0x2e85c0[0x0],'timeout':_0x2e85c0[0x1]};var _0xfefe58=queue[_0xf685('0xe')](_0x46d65c,{'typecast':!![]});if(_0xfefe58[_0xf685('0xf')]){logger[_0xf685('0x10')](_0xf685('0x11'),_0x14cc46,_['map'](_0xfefe58,_0xf685('0x12'))['join'](',\x20'));_0x58b9cf[_0xf685('0x13')]();}else{var _0x33ec40=_['find'](_0x1e6f31['agents'],handleFindAgent(_0x46d65c[_0xf685('0xb')]));if(_0x33ec40){var _0x11ecc1=(_0x46d65c[_0xf685('0x14')]||0xa)*0x3e8;var _0x493e4a,_0x1fc264;var _0x51a1c2=seqqueue['createQueue'](_0x11ecc1);_0x51a1c2['id']=_0x14cc46;_0x51a1c2[_0xf685('0x15')]=_0x11ecc1;_0x51a1c2[_0xf685('0x16')]=_0x8eb10c[_0xf685('0x16')];writeLog(_0x14cc46,_0x33ec40,util[_0xf685('0x9')](_0xf685('0x17'),_0x11ecc1));_0x1e6f31[_0xf685('0x18')][_0x14cc46]['on'](_0xf685('0x19'),function(){logger[_0xf685('0x8')](_0xf685('0x1a'),_0x14cc46);clearTimeout(_0x1fc264);_0x1fc264=undefined;_0x51a1c2[_0xf685('0x1b')]();if(_0x1e6f31[_0xf685('0x18')][_0x14cc46]){delete _0x1e6f31[_0xf685('0x18')][_0x14cc46];}_0x58b9cf[_0xf685('0x13')]();});_0x1e6f31[_0xf685('0x18')][_0x14cc46]['on']('complete',function(){if(_0x1e6f31[_0xf685('0x18')][_0x14cc46]){delete _0x1e6f31[_0xf685('0x18')][_0x14cc46];}});_0x1fc264=setTimeout(function(){logger['info'](_0xf685('0x1c'),_0x14cc46);clearTimeout(_0x1fc264);_0x51a1c2['close']();_0x58b9cf[_0xf685('0x1d')]();},_0x11ecc1);strategy[_0xf685('0x1e')](_0x51a1c2,_0x33ec40,_0x1e6f31,_0x8eb10c);}else{logger[_0xf685('0x10')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x14cc46,_0x46d65c[_0xf685('0xb')]);_0x58b9cf[_0xf685('0x13')]();}}}catch(_0x54f92f){console[_0xf685('0x1f')](_0x54f92f);logger['error'](_0xf685('0x20'),_0x14cc46,_0x54f92f['stack']);_0x58b9cf[_0xf685('0x13')]();}};};