Built motion from commit (unavailable).|2.5.11
[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 _0x9c5f=['[%s][AGENT]\x20agent\x20not\x20found\x20%s','log','stack','validate','routing','string','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','[%s][AGENT]\x20%s','map','stop','find','agents','createQueue','atimeout','channel','START:%s','rules','end','[%s][AGENT]\x20ROUTING\x20STOPPED','close','next','error'];(function(_0x3f56ed,_0xd8f0be){var _0x32cad8=function(_0x9ff1f7){while(--_0x9ff1f7){_0x3f56ed['push'](_0x3f56ed['shift']());}};_0x32cad8(++_0xd8f0be);}(_0x9c5f,0x13b));var _0xf9c5=function(_0x534eb2,_0x2b9f02){_0x534eb2=_0x534eb2-0x0;var _0xfae93b=_0x9c5f[_0x534eb2];return _0xfae93b;};'use strict';var schema=require(_0xf9c5('0x0'));var _=require('lodash');var util=require('util');var seqqueue=require('seq-queue');var logger=require('../../../../config/logger')(_0xf9c5('0x1'));var strategy=require('./strategy');var queue=schema({'name':{'type':_0xf9c5('0x2'),'required':!![],'message':'name\x20is\x20a\x20string\x20and\x20it\x20is\x20required'},'timeout':{'type':'number','message':'timeout\x20is\x20a\x20number'}});function writeLog(_0x1e7219,_0x426878,_0x15e717){return logger[_0xf9c5('0x3')](util[_0xf9c5('0x4')](_0xf9c5('0x5'),_0x1e7219,_0x426878[_0xf9c5('0x6')],_0x15e717));}function handleFindAgent(_0x32217a){return function(_0x17671a){return _0x17671a[_0xf9c5('0x6')][_0xf9c5('0x7')]()===_0x32217a['toLowerCase']();};}exports['consequence']=function(_0x1ddbe5,_0x2005ed,_0x502743,_0x434e3d){return function(_0x5c7ae1){try{var _0x8c436={'name':_0x2005ed[0x0],'timeout':_0x2005ed[0x1]};var _0x1c0b51=queue['validate'](_0x8c436,{'typecast':!![]});if(_0x1c0b51['length']){logger['error'](_0xf9c5('0x8'),_0x1ddbe5,_[_0xf9c5('0x9')](_0x1c0b51,'message')['join'](',\x20'));_0x5c7ae1[_0xf9c5('0xa')]();}else{var _0x50c54b=_[_0xf9c5('0xb')](_0x502743[_0xf9c5('0xc')],handleFindAgent(_0x8c436[_0xf9c5('0x6')]));if(_0x50c54b){var _0x3c97c5=(_0x8c436['timeout']||0xa)*0x3e8;var _0x132110,_0x474d00;var _0x169d92=seqqueue[_0xf9c5('0xd')](_0x3c97c5);_0x169d92['id']=_0x1ddbe5;_0x169d92[_0xf9c5('0xe')]=_0x3c97c5;_0x169d92['channel']=_0x434e3d[_0xf9c5('0xf')];writeLog(_0x1ddbe5,_0x50c54b,util[_0xf9c5('0x4')](_0xf9c5('0x10'),_0x3c97c5));_0x502743[_0xf9c5('0x11')][_0x1ddbe5]['on'](_0xf9c5('0x12'),function(){logger[_0xf9c5('0x3')](_0xf9c5('0x13'),_0x1ddbe5);clearTimeout(_0x474d00);_0x474d00=undefined;_0x169d92[_0xf9c5('0x14')]();if(_0x502743[_0xf9c5('0x11')][_0x1ddbe5]){delete _0x502743['rules'][_0x1ddbe5];}_0x5c7ae1[_0xf9c5('0xa')]();});_0x502743[_0xf9c5('0x11')][_0x1ddbe5]['on']('complete',function(){if(_0x502743['rules'][_0x1ddbe5]){delete _0x502743['rules'][_0x1ddbe5];}});_0x474d00=setTimeout(function(){logger[_0xf9c5('0x3')]('[%s][AGENT]\x20ROUTING\x20END',_0x1ddbe5);clearTimeout(_0x474d00);_0x169d92['close']();_0x5c7ae1[_0xf9c5('0x15')]();},_0x3c97c5);strategy['agent'](_0x169d92,_0x50c54b,_0x502743,_0x434e3d);}else{logger[_0xf9c5('0x16')](_0xf9c5('0x17'),_0x1ddbe5,_0x8c436['name']);_0x5c7ae1[_0xf9c5('0xa')]();}}}catch(_0x2ae394){console[_0xf9c5('0x18')](_0x2ae394);logger[_0xf9c5('0x16')]('[%s][QUEUE]\x20%s',_0x1ddbe5,_0x2ae394[_0xf9c5('0x19')]);_0x5c7ae1[_0xf9c5('0xa')]();}};};