9f1632d5c1b0ef324c6ddbb992e239851d95a5cf
[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 _0x371a=['util','../../../../config/logger','routing','./strategy','string','name\x20is\x20a\x20string\x20and\x20it\x20is\x20required','timeout\x20is\x20a\x20number','info','format','[%s][AGENT][NAME:%s][STATUS:%s]','name','toLowerCase','validate','length','map','message','stop','agents','timeout','createQueue','atimeout','channel','START:%s','end','close','rules','next','error','log','[%s][QUEUE]\x20%s','stack','lodash'];(function(_0x436c0e,_0x491bdb){var _0x465f20=function(_0x10c2af){while(--_0x10c2af){_0x436c0e['push'](_0x436c0e['shift']());}};_0x465f20(++_0x491bdb);}(_0x371a,0x7f));var _0xa371=function(_0x3b0772,_0x178fb9){_0x3b0772=_0x3b0772-0x0;var _0x5ee687=_0x371a[_0x3b0772];return _0x5ee687;};'use strict';var schema=require('validate');var _=require(_0xa371('0x0'));var util=require(_0xa371('0x1'));var seqqueue=require('seq-queue');var logger=require(_0xa371('0x2'))(_0xa371('0x3'));var strategy=require(_0xa371('0x4'));var queue=schema({'name':{'type':_0xa371('0x5'),'required':!![],'message':_0xa371('0x6')},'timeout':{'type':'number','message':_0xa371('0x7')}});function writeLog(_0x296f7c,_0x30e843,_0xb9db76){return logger[_0xa371('0x8')](util[_0xa371('0x9')](_0xa371('0xa'),_0x296f7c,_0x30e843[_0xa371('0xb')],_0xb9db76));}function handleFindAgent(_0x7df0f){return function(_0x4696aa){return _0x4696aa['name']['toLowerCase']()===_0x7df0f[_0xa371('0xc')]();};}exports['consequence']=function(_0x25f149,_0xa38241,_0x3410b5,_0x3ee654){return function(_0x2cb6e4){try{var _0x4d9ae2={'name':_0xa38241[0x0],'timeout':_0xa38241[0x1]};var _0x2266f5=queue[_0xa371('0xd')](_0x4d9ae2,{'typecast':!![]});if(_0x2266f5[_0xa371('0xe')]){logger['error']('[%s][AGENT]\x20%s',_0x25f149,_[_0xa371('0xf')](_0x2266f5,_0xa371('0x10'))['join'](',\x20'));_0x2cb6e4[_0xa371('0x11')]();}else{var _0x51d11c=_['find'](_0x3410b5[_0xa371('0x12')],handleFindAgent(_0x4d9ae2[_0xa371('0xb')]));if(_0x51d11c){var _0x5709d5=(_0x4d9ae2[_0xa371('0x13')]||0xa)*0x3e8;var _0x449bd4,_0x30b387;var _0x5a9d6f=seqqueue[_0xa371('0x14')](_0x5709d5);_0x5a9d6f['id']=_0x25f149;_0x5a9d6f[_0xa371('0x15')]=_0x5709d5;_0x5a9d6f['channel']=_0x3ee654[_0xa371('0x16')];writeLog(_0x25f149,_0x51d11c,util['format'](_0xa371('0x17'),_0x5709d5));_0x3410b5['rules'][_0x25f149]['on'](_0xa371('0x18'),function(){logger[_0xa371('0x8')]('[%s][AGENT]\x20ROUTING\x20STOPPED',_0x25f149);clearTimeout(_0x30b387);_0x30b387=undefined;_0x5a9d6f[_0xa371('0x19')]();if(_0x3410b5[_0xa371('0x1a')][_0x25f149]){delete _0x3410b5[_0xa371('0x1a')][_0x25f149];}_0x2cb6e4['stop']();});_0x3410b5[_0xa371('0x1a')][_0x25f149]['on']('complete',function(){if(_0x3410b5[_0xa371('0x1a')][_0x25f149]){delete _0x3410b5[_0xa371('0x1a')][_0x25f149];}});_0x30b387=setTimeout(function(){logger[_0xa371('0x8')]('[%s][AGENT]\x20ROUTING\x20END',_0x25f149);clearTimeout(_0x30b387);_0x5a9d6f[_0xa371('0x19')]();_0x2cb6e4[_0xa371('0x1b')]();},_0x5709d5);strategy['agent'](_0x5a9d6f,_0x51d11c,_0x3410b5,_0x3ee654);}else{logger[_0xa371('0x1c')]('[%s][AGENT]\x20agent\x20not\x20found\x20%s',_0x25f149,_0x4d9ae2[_0xa371('0xb')]);_0x2cb6e4['stop']();}}}catch(_0x75445d){console[_0xa371('0x1d')](_0x75445d);logger[_0xa371('0x1c')](_0xa371('0x1e'),_0x25f149,_0x75445d[_0xa371('0x1f')]);_0x2cb6e4[_0xa371('0x11')]();}};};