Built motion from commit (unavailable).|2.5.30
[motion2.git] / server / services / routing / server / index.js
index 7b7e897..73270e8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x270b=['uuid','../../../config/environment','../../../config/logger','../rpc/openchannelQueueReport','../rpc/mailQueueReport','%s.%s.%s','isNil','IntervalId','Intervals','map','interval','listen','rules','channel','message','interaction','applications','length','join','app','.js','autoreply','split','push','appdata','slice','dialogflowv2','TagId','format','%s:%s:%s','condition','intervals','./applications/','consequence','info','Push\x20new\x20rule','on\x20interval','\x20|\x20','Applications\x20executed','emit','complete','No\x20applications\x20to\x20execute','error','stack','routing\x20is\x20empty','end','QueueReport','update','error\x20update\x20queue\x20report','message\x20is\x20empty','agent','agents','busy','busyQueue','hasOwnProperty','capacity','CurrentCapacity','updateRealtime','agent\x20not\x20found','values','chatQueues','available','name','paused','mailQueues','loggedIn','waiting','openchannelQueues','smsQueues','faxQueues','whatsappQueues','mailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','server','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','lodash','util','path','bluebird'];(function(_0x506f1f,_0x43362c){var _0x20f804=function(_0xb3924b){while(--_0xb3924b){_0x506f1f['push'](_0x506f1f['shift']());}};_0x20f804(++_0x43362c);}(_0x270b,0xf2));var _0xb270=function(_0x2cd096,_0x2517fc){_0x2cd096=_0x2cd096-0x0;var _0x20c6be=_0x270b[_0x2cd096];return _0x20c6be;};'use strict';var _=require(_0xb270('0x0'));var util=require(_0xb270('0x1'));var path=require(_0xb270('0x2'));var fs=require('fs');var jayson=require('jayson/promise');var BPromise=require(_0xb270('0x3'));var uuid=require(_0xb270('0x4'));var config=require(_0xb270('0x5'));var logger=require(_0xb270('0x6'))('routing');var rpc={'openchannelQueueReport':require(_0xb270('0x7')),'mailQueueReport':require(_0xb270('0x8')),'chatQueueReport':require('../rpc/chatQueueReport'),'smsQueueReport':require('../rpc/smsQueueReport'),'faxQueueReport':require('../rpc/faxQueueReport'),'whatsappQueueReport':require('../rpc/whatsappQueueReport')};var RuleEngine=require('../lib/rule-engine');function getId(_0xef248a,_0x456916,_0x1545ba){return util['format'](_0xb270('0x9'),_0xef248a,_0x456916||0x0,_0x1545ba||0x0);}function getIntervals(_0xc931f,_0x490a05){var _0x48170b=[];if(!_[_0xb270('0xa')](_0x490a05['IntervalId'])&&!_[_0xb270('0xa')](_0xc931f[_0x490a05[_0xb270('0xb')]])&&!_[_0xb270('0xa')](_0xc931f[_0x490a05[_0xb270('0xb')]][_0xb270('0xc')])){_0x48170b=_[_0xb270('0xd')](_0xc931f[_0x490a05[_0xb270('0xb')]]['Intervals'],_0xb270('0xe'));}else if(!_[_0xb270('0xa')](_0x490a05[_0xb270('0xe')])){_0x48170b=[_0x490a05[_0xb270('0xe')]];}return _0x48170b;}exports[_0xb270('0xf')]=function(_0x3eb9a6){_0x3eb9a6[_0xb270('0x10')]={};return new BPromise(function(_0x50c9b3,_0x1e0208){var _0x231d74={'Start':function(_0x566b1a){var _0x32aed6=this;return new Promise(function(_0x9bba99,_0x8d0149){if(_0x566b1a){try{var _0x1f473a=[];var _0x2f5053=getId(_0x566b1a[_0xb270('0x11')],_0x566b1a[_0xb270('0x12')]?_0x566b1a[_0xb270('0x12')]['id']:0x0,_0x566b1a[_0xb270('0x13')]?_0x566b1a[_0xb270('0x13')]['id']:0x0);if(_0x566b1a['applications']&&_['isArray'](_0x566b1a[_0xb270('0x14')])&&_0x566b1a[_0xb270('0x14')][_0xb270('0x15')]){for(var _0x42b818=0x0;_0x42b818<_0x566b1a['applications'][_0xb270('0x15')];_0x42b818+=0x1){var _0x47c380=_0x566b1a[_0xb270('0x14')][_0x42b818];if(fs['existsSync'](path[_0xb270('0x16')](__dirname,_0xb270('0x14'),_0x47c380[_0xb270('0x17')]+_0xb270('0x18')))){var _0x86402b=[];switch(_0x47c380[_0xb270('0x17')]['toLowerCase']()){case _0xb270('0x19'):var _0x24d5d7=_0x47c380['appdata'][_0xb270('0x1a')](',');_0x86402b[_0xb270('0x1b')](_0x24d5d7[0x0]);_0x86402b[_0xb270('0x1b')](_0x24d5d7['slice'](0x1,_0x24d5d7[_0xb270('0x15')])[_0xb270('0x16')](','));break;case'dialogflow':var _0x18f08f=_0x47c380[_0xb270('0x1c')]['split'](',');_0x86402b[_0xb270('0x1b')](_0x18f08f[0x0]);_0x86402b[_0xb270('0x1b')](_0x18f08f[0x1]);_0x86402b['push'](_0x18f08f[_0xb270('0x1d')](0x2,_0x18f08f[_0xb270('0x15')])['join'](','));break;case _0xb270('0x1e'):var _0x196f95=_0x47c380[_0xb270('0x1c')][_0xb270('0x1a')](',');_0x86402b[_0xb270('0x1b')](_0x196f95[0x0]);_0x86402b[_0xb270('0x1b')](_0x196f95[0x1]);_0x86402b['push'](_0x196f95[0x2]);_0x86402b[_0xb270('0x1b')](_0x196f95[0x3]);_0x86402b[_0xb270('0x1b')](_0x196f95[_0xb270('0x1d')](0x4,_0x196f95[_0xb270('0x15')])['join'](','));break;case'amazonlex':var _0xed56a1=_0x47c380['appdata'][_0xb270('0x1a')](',');_0x86402b['push'](_0xed56a1[0x0]);_0x86402b[_0xb270('0x1b')](_0xed56a1[0x1]);_0x86402b[_0xb270('0x1b')](_0xed56a1[0x2]);_0x86402b[_0xb270('0x1b')](_0xed56a1[0x3]);_0x86402b[_0xb270('0x1b')](_0xed56a1[_0xb270('0x1d')](0x4,_0xed56a1[_0xb270('0x15')])[_0xb270('0x16')](','));break;case _0xb270('0x12'):_0x86402b[_0xb270('0x1b')](_0x47c380[_0xb270('0x1c')]);break;case'tag':_0x86402b[_0xb270('0x1b')](_0x47c380[_0xb270('0x1f')]);_0x86402b[_0xb270('0x1b')](_0x47c380[_0xb270('0x1c')]);break;default:_0x86402b=_[_0xb270('0xa')](_0x47c380[_0xb270('0x1c')])?[]:_0x47c380[_0xb270('0x1c')][_0xb270('0x1a')](',');}var _0x206537={'id':util[_0xb270('0x20')](_0xb270('0x21'),_0x2f5053,_0x47c380['id'],_0x47c380[_0xb270('0x17')]),'condition':require('./interval')[_0xb270('0x22')](_0x2f5053,getIntervals(_0x3eb9a6[_0xb270('0x23')],_0x47c380),_0x3eb9a6),'consequence':require(_0xb270('0x24')+_0x47c380[_0xb270('0x17')])[_0xb270('0x25')](_0x2f5053,_0x86402b,_0x3eb9a6,_0x566b1a),'p':_0x47c380['priority']||0x0};logger[_0xb270('0x26')](_0xb270('0x27'),_0x206537['id'],_0xb270('0x28'),getIntervals(_0x3eb9a6['intervals'],_0x47c380)[_0xb270('0x16')](_0xb270('0x29')));_0x1f473a[_0xb270('0x1b')](_0x206537);}else{logger['error']('Please\x20create\x20a\x20new\x20file\x20under',path[_0xb270('0x16')](__dirname,_0xb270('0x14'),_0x47c380['app']+_0xb270('0x18')));}}_0x3eb9a6[_0xb270('0x10')][_0x2f5053]=new RuleEngine(_0x1f473a);_0x3eb9a6[_0xb270('0x10')][_0x2f5053]['execute'](_0x566b1a,function(_0x51063d){logger[_0xb270('0x26')](_0xb270('0x2a'),JSON['stringify'](_0x51063d['matchPath']));if(_0x3eb9a6[_0xb270('0x10')][_0x2f5053]){_0x3eb9a6[_0xb270('0x10')][_0x2f5053][_0xb270('0x2b')](_0xb270('0x2c'));}});return _0x9bba99({'code':0xc8,'message':_0x566b1a});}else{logger[_0xb270('0x26')](_0xb270('0x2d'));return _0x9bba99({'code':0xc8,'message':_0x566b1a});}}catch(_0x549f4c){logger[_0xb270('0x2e')](_0x549f4c[_0xb270('0x2f')]);return _0x8d0149(_0x32aed6['error'](0x1f4,_0x549f4c));}}return _0x8d0149(_0xb270('0x30'));});},'AcceptMessage':function(_0x2c9688){var _0x2508aa=this;return new Promise(function(_0x106c60,_0x19723e){if(_0x2c9688[_0xb270('0x12')]&&_0x2c9688[_0xb270('0x12')]['id']){try{var _0x1abf77=getId(_0x2c9688[_0xb270('0x11')],_0x2c9688[_0xb270('0x12')]?_0x2c9688[_0xb270('0x12')]['id']:0x0,_0x2c9688[_0xb270('0x13')]?_0x2c9688[_0xb270('0x13')]['id']:0x0);if(_0x3eb9a6[_0xb270('0x10')][_0x1abf77]){_0x3eb9a6[_0xb270('0x10')][_0x1abf77][_0xb270('0x2b')](_0xb270('0x31'));if(rpc[_0x2c9688['channel']+_0xb270('0x32')]){rpc[_0x2c9688['channel']+'QueueReport'][_0xb270('0x33')](_0x1abf77,{'UserId':_0x2c9688[_0xb270('0x12')]['UserId']})['catch'](function(_0x5ed705){logger[_0xb270('0x2e')](_0xb270('0x34'));});}}return _0x106c60({'code':0xc8,'message':_0x2c9688});}catch(_0x906219){logger[_0xb270('0x2e')](_0x906219[_0xb270('0x2f')]);return _0x19723e(_0x2508aa['error'](0x1f4,_0x906219));}}logger[_0xb270('0x2e')](_0xb270('0x35'));return _0x19723e(_0x2508aa[_0xb270('0x2e')](0x1f4,'message\x20is\x20empty'));});},'RejectMessage':function(_0x317c60){var _0x519b70=this;return new Promise(function(_0x82ad42,_0x10d549){if(_0x317c60['agent']&&_0x317c60[_0xb270('0x36')]['id']){try{if(_0x3eb9a6[_0xb270('0x37')][_0x317c60[_0xb270('0x36')]['id']]){_0x3eb9a6[_0xb270('0x37')][_0x317c60[_0xb270('0x36')]['id']][_0xb270('0x38')]=![];_0x3eb9a6[_0xb270('0x37')][_0x317c60[_0xb270('0x36')]['id']][_0xb270('0x39')]=undefined;}return _0x82ad42({'code':0xc8,'message':_0x317c60});}catch(_0x5c76df){logger[_0xb270('0x2e')](_0x5c76df[_0xb270('0x2f')]);return _0x10d549(_0x519b70[_0xb270('0x2e')](0x1f4,_0x5c76df));}}logger[_0xb270('0x2e')](_0xb270('0x35'));return _0x10d549(_0x519b70[_0xb270('0x2e')](0x1f4,_0xb270('0x35')));});},'AbandonInteraction':function(_0x1dcbb4){var _0x2f8236=this;return new Promise(function(_0x45aa2f,_0x54b0be){if(_0x1dcbb4[_0xb270('0x11')]&&_0x1dcbb4['interaction']&&_0x1dcbb4[_0xb270('0x13')]['id']){try{var _0x5a2430=getId(_0x1dcbb4[_0xb270('0x11')],_0x1dcbb4[_0xb270('0x12')]?_0x1dcbb4[_0xb270('0x12')]['id']:0x0,_0x1dcbb4[_0xb270('0x13')]?_0x1dcbb4[_0xb270('0x13')]['id']:0x0);if(_0x3eb9a6[_0xb270('0x10')][_0x5a2430]){_0x3eb9a6[_0xb270('0x10')][_0x5a2430]['emit']('end');}return _0x45aa2f({'code':0xc8,'message':_0x1dcbb4});}catch(_0x27a776){logger['error'](_0x27a776['stack']);return _0x54b0be(_0x2f8236[_0xb270('0x2e')](0x1f4,_0x27a776));}}logger[_0xb270('0x2e')](_0xb270('0x35'));return _0x54b0be(_0x2f8236[_0xb270('0x2e')](0x1f4,_0xb270('0x35')));});},'AgentCapacity':function(_0x1de0a5){var _0x217249=this;return new Promise(function(_0x9a968f,_0x2b0027){if(_0x3eb9a6[_0xb270('0x37')][_0xb270('0x3a')](_0x1de0a5['id'])){for(var _0xf1183 in _0x1de0a5[_0xb270('0x3b')]){if(_0x1de0a5['capacity'][_0xb270('0x3a')](_0xf1183)){if(_0x3eb9a6[_0xb270('0x37')][_0x1de0a5['id']]['hasOwnProperty'](_0xf1183+_0xb270('0x3c'))){_0x3eb9a6['agents'][_0x1de0a5['id']][_0xf1183+_0xb270('0x3c')]=parseInt(_0x1de0a5[_0xb270('0x3b')][_0xf1183],0xa);}}}_0x3eb9a6['agents'][_0x1de0a5['id']][_0xb270('0x3d')]();return _0x9a968f({'code':0xc8,'message':_0x3eb9a6['agents'][_0x1de0a5['id']]});}else{return _0x2b0027(_0x217249[_0xb270('0x2e')](0x1f4,_0xb270('0x3e')));}});},'Agents':function(_0x19b0fe){return new Promise(function(_0x28b178,_0x2a8b40){var _0x146216=_[_0xb270('0x3f')](_0x3eb9a6[_0xb270('0x37')]);_0x28b178({'count':_0x146216['length'],'rows':_0x146216});});},'ChatQueues':function(_0x183122){return new Promise(function(_0x49b587,_0x1a3485){var _0x8e33ca=[];for(var _0x8ec16e in _0x3eb9a6[_0xb270('0x40')]){if(_0x3eb9a6[_0xb270('0x40')]['hasOwnProperty'](_0x8ec16e)){var _0x95edff=_0x3eb9a6['chatQueues'][_0x8ec16e];var _0x44288f={'id':_0x95edff['id'],'available':_0x95edff[_0xb270('0x41')],'loggedIn':_0x95edff['loggedIn'],'name':_0x95edff[_0xb270('0x42')],'paused':_0x95edff[_0xb270('0x43')],'waiting':_0x95edff['waiting']};_0x8e33ca[_0xb270('0x1b')](_0x44288f);}}_0x49b587({'count':_0x8e33ca[_0xb270('0x15')],'rows':_0x8e33ca});});},'MailQueues':function(_0x3cbed5){return new Promise(function(_0x2e2a2a,_0x282fab){var _0x279b7c=[];for(var _0x2551ab in _0x3eb9a6[_0xb270('0x44')]){if(_0x3eb9a6[_0xb270('0x44')][_0xb270('0x3a')](_0x2551ab)){var _0x1f9241=_0x3eb9a6['mailQueues'][_0x2551ab];var _0x50d46e={'id':_0x1f9241['id'],'available':_0x1f9241['available'],'loggedIn':_0x1f9241[_0xb270('0x45')],'name':_0x1f9241['name'],'paused':_0x1f9241[_0xb270('0x43')],'waiting':_0x1f9241[_0xb270('0x46')]};_0x279b7c[_0xb270('0x1b')](_0x50d46e);}}_0x2e2a2a({'count':_0x279b7c[_0xb270('0x15')],'rows':_0x279b7c});});},'OpenchannelQueues':function(_0x227792){return new Promise(function(_0x3393c9,_0x232c42){var _0x4a004b=[];for(var _0x48256a in _0x3eb9a6[_0xb270('0x47')]){if(_0x3eb9a6[_0xb270('0x47')][_0xb270('0x3a')](_0x48256a)){var _0x49fc8f=_0x3eb9a6[_0xb270('0x47')][_0x48256a];var _0x1505f8={'id':_0x49fc8f['id'],'available':_0x49fc8f[_0xb270('0x41')],'loggedIn':_0x49fc8f['loggedIn'],'name':_0x49fc8f['name'],'paused':_0x49fc8f[_0xb270('0x43')],'waiting':_0x49fc8f[_0xb270('0x46')]};_0x4a004b[_0xb270('0x1b')](_0x1505f8);}}_0x3393c9({'count':_0x4a004b[_0xb270('0x15')],'rows':_0x4a004b});});},'SmsQueues':function(_0x52e906){return new Promise(function(_0x210375,_0x23c92a){var _0x173676=[];for(var _0x34d786 in _0x3eb9a6['smsQueues']){if(_0x3eb9a6[_0xb270('0x48')][_0xb270('0x3a')](_0x34d786)){var _0xc60a25=_0x3eb9a6['smsQueues'][_0x34d786];var _0x5a7fd8={'id':_0xc60a25['id'],'available':_0xc60a25['available'],'loggedIn':_0xc60a25[_0xb270('0x45')],'name':_0xc60a25[_0xb270('0x42')],'paused':_0xc60a25[_0xb270('0x43')],'waiting':_0xc60a25[_0xb270('0x46')]};_0x173676[_0xb270('0x1b')](_0x5a7fd8);}}_0x210375({'count':_0x173676[_0xb270('0x15')],'rows':_0x173676});});},'FaxQueues':function(_0x27527f){return new Promise(function(_0x2c84db,_0x292210){var _0x473f01=[];for(var _0x5443f9 in _0x3eb9a6['faxQueues']){if(_0x3eb9a6[_0xb270('0x49')][_0xb270('0x3a')](_0x5443f9)){var _0x4e5407=_0x3eb9a6[_0xb270('0x49')][_0x5443f9];var _0x218fc1={'id':_0x4e5407['id'],'available':_0x4e5407['available'],'loggedIn':_0x4e5407[_0xb270('0x45')],'name':_0x4e5407[_0xb270('0x42')],'paused':_0x4e5407[_0xb270('0x43')],'waiting':_0x4e5407['waiting']};_0x473f01['push'](_0x218fc1);}}_0x2c84db({'count':_0x473f01[_0xb270('0x15')],'rows':_0x473f01});});},'WhatsappQueues':function(_0x5651a5){return new Promise(function(_0x1474b4,_0x503810){var _0x4bc517=[];for(var _0x30c905 in _0x3eb9a6['whatsappQueues']){if(_0x3eb9a6['whatsappQueues']['hasOwnProperty'](_0x30c905)){var _0x47fb92=_0x3eb9a6[_0xb270('0x4a')][_0x30c905];var _0xcf70f5={'id':_0x47fb92['id'],'available':_0x47fb92[_0xb270('0x41')],'loggedIn':_0x47fb92[_0xb270('0x45')],'name':_0x47fb92[_0xb270('0x42')],'paused':_0x47fb92[_0xb270('0x43')],'waiting':_0x47fb92[_0xb270('0x46')]};_0x4bc517[_0xb270('0x1b')](_0xcf70f5);}}_0x1474b4({'count':_0x4bc517[_0xb270('0x15')],'rows':_0x4bc517});});},'ChatQueuesWaitingInteractions':function(_0x1dc9c4){return new Promise(function(_0xc228f1,_0x3c7ae1){var _0x2c10a6=_[_0xb270('0x3f')](_0x3eb9a6['chatQueuesWaitingInteractions']);_0xc228f1({'count':_0x2c10a6['length'],'rows':_0x2c10a6});});},'MailQueuesWaitingInteractions':function(_0x3e44f5){return new Promise(function(_0x34930a,_0x20ef22){var _0xebddf6=_[_0xb270('0x3f')](_0x3eb9a6[_0xb270('0x4b')]);_0x34930a({'count':_0xebddf6[_0xb270('0x15')],'rows':_0xebddf6});});},'OpenchannelQueuesWaitingInteractions':function(_0x3f288f){return new Promise(function(_0xb675bf,_0x9e367e){var _0x563fda=_[_0xb270('0x3f')](_0x3eb9a6[_0xb270('0x4c')]);_0xb675bf({'count':_0x563fda[_0xb270('0x15')],'rows':_0x563fda});});},'SmsQueuesWaitingInteractions':function(_0x2159e5){return new Promise(function(_0x17fe59,_0x22252b){var _0x272f9d=_[_0xb270('0x3f')](_0x3eb9a6[_0xb270('0x4d')]);_0x17fe59({'count':_0x272f9d[_0xb270('0x15')],'rows':_0x272f9d});});},'FaxQueuesWaitingInteractions':function(_0x26bc9c){return new Promise(function(_0x41ce0a,_0x213431){var _0x4030a2=_[_0xb270('0x3f')](_0x3eb9a6['faxQueuesWaitingInteractions']);_0x41ce0a({'count':_0x4030a2[_0xb270('0x15')],'rows':_0x4030a2});});},'WhatsappQueuesWaitingInteractions':function(_0x54fd5a){return new Promise(function(_0x333a61,_0x18d212){var _0x5d1c25=_['values'](_0x3eb9a6['whatsappQueuesWaitingInteractions']);_0x333a61({'count':_0x5d1c25[_0xb270('0x15')],'rows':_0x5d1c25});});}};var _0x4687ad=jayson[_0xb270('0x4e')](_0x231d74)['http']();_0x4687ad['on'](_0xb270('0x2e'),function(_0x33330f){logger['error'](JSON['stringify'](_0x33330f));return _0x1e0208(_0x33330f);});_0x4687ad['listen'](0x232c,'127.0.0.1',function(){console[_0xb270('0x4f')](_0xb270('0x50'),0x232c);return _0x50c9b3(_0xb270('0x51')+0x232c);});});};
\ No newline at end of file
+var _0xb7c8=['uuid','../../../config/environment','../../../config/logger','../rpc/openchannelQueueReport','../rpc/mailQueueReport','../rpc/chatQueueReport','../rpc/smsQueueReport','../rpc/faxQueueReport','../rpc/whatsappQueueReport','../lib/rule-engine','format','%s.%s.%s','isNil','IntervalId','Intervals','interval','listen','rules','channel','message','interaction','applications','isArray','length','existsSync','join','app','.js','toLowerCase','autoreply','appdata','split','mail','push','slice','dialogflow','dialogflowv2','amazonlex','tag','TagId','%s:%s:%s','condition','intervals','./applications/','priority','info','Push\x20new\x20rule','Please\x20create\x20a\x20new\x20file\x20under','execute','Applications\x20executed','stringify','matchPath','emit','complete','No\x20applications\x20to\x20execute','error','routing\x20is\x20empty','agent','agents','busy','busyQueue','end','QueueReport','update','catch','message\x20is\x20empty','stack','capacity','hasOwnProperty','CurrentCapacity','updateRealtime','agent\x20not\x20found','values','chatQueues','available','loggedIn','name','waiting','mailQueues','paused','openchannelQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','127.0.0.1','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','util','path','jayson/promise','bluebird'];(function(_0x119bfb,_0x14375b){var _0x5ef624=function(_0x10f8c2){while(--_0x10f8c2){_0x119bfb['push'](_0x119bfb['shift']());}};_0x5ef624(++_0x14375b);}(_0xb7c8,0x119));var _0x8b7c=function(_0x37f8f9,_0x32753d){_0x37f8f9=_0x37f8f9-0x0;var _0x2990c2=_0xb7c8[_0x37f8f9];return _0x2990c2;};'use strict';var _=require('lodash');var util=require(_0x8b7c('0x0'));var path=require(_0x8b7c('0x1'));var fs=require('fs');var jayson=require(_0x8b7c('0x2'));var BPromise=require(_0x8b7c('0x3'));var uuid=require(_0x8b7c('0x4'));var config=require(_0x8b7c('0x5'));var logger=require(_0x8b7c('0x6'))('routing');var rpc={'openchannelQueueReport':require(_0x8b7c('0x7')),'mailQueueReport':require(_0x8b7c('0x8')),'chatQueueReport':require(_0x8b7c('0x9')),'smsQueueReport':require(_0x8b7c('0xa')),'faxQueueReport':require(_0x8b7c('0xb')),'whatsappQueueReport':require(_0x8b7c('0xc'))};var RuleEngine=require(_0x8b7c('0xd'));function getId(_0x3c8fd6,_0x6afb55,_0x30a924){return util[_0x8b7c('0xe')](_0x8b7c('0xf'),_0x3c8fd6,_0x6afb55||0x0,_0x30a924||0x0);}function getIntervals(_0x48370e,_0x31bf3f){var _0x5986c1=[];if(!_[_0x8b7c('0x10')](_0x31bf3f[_0x8b7c('0x11')])&&!_['isNil'](_0x48370e[_0x31bf3f[_0x8b7c('0x11')]])&&!_[_0x8b7c('0x10')](_0x48370e[_0x31bf3f[_0x8b7c('0x11')]]['Intervals'])){_0x5986c1=_['map'](_0x48370e[_0x31bf3f[_0x8b7c('0x11')]][_0x8b7c('0x12')],_0x8b7c('0x13'));}else if(!_[_0x8b7c('0x10')](_0x31bf3f[_0x8b7c('0x13')])){_0x5986c1=[_0x31bf3f[_0x8b7c('0x13')]];}return _0x5986c1;}exports[_0x8b7c('0x14')]=function(_0x56e02b){_0x56e02b[_0x8b7c('0x15')]={};return new BPromise(function(_0x19c63e,_0x5857ac){var _0x52cfe7={'Start':function(_0xd37a82){var _0x4284a2=this;return new Promise(function(_0x496bc0,_0x3b8d62){if(_0xd37a82){try{var _0xcc0fcc=[];var _0x4262b5=getId(_0xd37a82[_0x8b7c('0x16')],_0xd37a82[_0x8b7c('0x17')]?_0xd37a82['message']['id']:0x0,_0xd37a82[_0x8b7c('0x18')]?_0xd37a82[_0x8b7c('0x18')]['id']:0x0);if(_0xd37a82[_0x8b7c('0x19')]&&_[_0x8b7c('0x1a')](_0xd37a82[_0x8b7c('0x19')])&&_0xd37a82['applications'][_0x8b7c('0x1b')]){for(var _0x2b0874=0x0;_0x2b0874<_0xd37a82[_0x8b7c('0x19')][_0x8b7c('0x1b')];_0x2b0874+=0x1){var _0x7b9e59=_0xd37a82[_0x8b7c('0x19')][_0x2b0874];if(fs[_0x8b7c('0x1c')](path[_0x8b7c('0x1d')](__dirname,_0x8b7c('0x19'),_0x7b9e59[_0x8b7c('0x1e')]+_0x8b7c('0x1f')))){var _0x1fe931=[];switch(_0x7b9e59['app'][_0x8b7c('0x20')]()){case _0x8b7c('0x21'):var _0x247c62=_0x7b9e59[_0x8b7c('0x22')][_0x8b7c('0x23')](',');if(_0xd37a82[_0x8b7c('0x16')]===_0x8b7c('0x24')){_0x1fe931[_0x8b7c('0x25')](_0x247c62[0x0]);_0x1fe931[_0x8b7c('0x25')](_0x247c62[0x1]);_0x1fe931[_0x8b7c('0x25')](_0x247c62['slice'](0x2,_0x247c62['length'])[_0x8b7c('0x1d')](','));}else{_0x1fe931['push'](_0x247c62[0x0]);_0x1fe931[_0x8b7c('0x25')](_0x247c62[_0x8b7c('0x26')](0x1,_0x247c62[_0x8b7c('0x1b')])[_0x8b7c('0x1d')](','));}break;case _0x8b7c('0x27'):var _0x3d2dfa=_0x7b9e59['appdata'][_0x8b7c('0x23')](',');_0x1fe931[_0x8b7c('0x25')](_0x3d2dfa[0x0]);_0x1fe931[_0x8b7c('0x25')](_0x3d2dfa[0x1]);_0x1fe931[_0x8b7c('0x25')](_0x3d2dfa[_0x8b7c('0x26')](0x2,_0x3d2dfa[_0x8b7c('0x1b')])[_0x8b7c('0x1d')](','));break;case _0x8b7c('0x28'):var _0x329998=_0x7b9e59[_0x8b7c('0x22')]['split'](',');_0x1fe931['push'](_0x329998[0x0]);_0x1fe931[_0x8b7c('0x25')](_0x329998[0x1]);_0x1fe931[_0x8b7c('0x25')](_0x329998[0x2]);_0x1fe931[_0x8b7c('0x25')](_0x329998[0x3]);_0x1fe931[_0x8b7c('0x25')](_0x329998[_0x8b7c('0x26')](0x4,_0x329998[_0x8b7c('0x1b')])[_0x8b7c('0x1d')](','));break;case _0x8b7c('0x29'):var _0x256681=_0x7b9e59[_0x8b7c('0x22')]['split'](',');_0x1fe931[_0x8b7c('0x25')](_0x256681[0x0]);_0x1fe931['push'](_0x256681[0x1]);_0x1fe931[_0x8b7c('0x25')](_0x256681[0x2]);_0x1fe931[_0x8b7c('0x25')](_0x256681[0x3]);_0x1fe931['push'](_0x256681[_0x8b7c('0x26')](0x4,_0x256681['length'])[_0x8b7c('0x1d')](','));break;case _0x8b7c('0x17'):_0x1fe931[_0x8b7c('0x25')](_0x7b9e59[_0x8b7c('0x22')]);break;case _0x8b7c('0x2a'):_0x1fe931[_0x8b7c('0x25')](_0x7b9e59[_0x8b7c('0x2b')]);_0x1fe931[_0x8b7c('0x25')](_0x7b9e59[_0x8b7c('0x22')]);break;default:_0x1fe931=_['isNil'](_0x7b9e59[_0x8b7c('0x22')])?[]:_0x7b9e59[_0x8b7c('0x22')]['split'](',');}var _0x56a272={'id':util['format'](_0x8b7c('0x2c'),_0x4262b5,_0x7b9e59['id'],_0x7b9e59[_0x8b7c('0x1e')]),'condition':require('./interval')[_0x8b7c('0x2d')](_0x4262b5,getIntervals(_0x56e02b[_0x8b7c('0x2e')],_0x7b9e59),_0x56e02b),'consequence':require(_0x8b7c('0x2f')+_0x7b9e59[_0x8b7c('0x1e')])['consequence'](_0x4262b5,_0x1fe931,_0x56e02b,_0xd37a82),'p':_0x7b9e59[_0x8b7c('0x30')]||0x0};logger[_0x8b7c('0x31')](_0x8b7c('0x32'),_0x56a272['id'],'on\x20interval',getIntervals(_0x56e02b[_0x8b7c('0x2e')],_0x7b9e59)[_0x8b7c('0x1d')]('\x20|\x20'));_0xcc0fcc['push'](_0x56a272);}else{logger['error'](_0x8b7c('0x33'),path[_0x8b7c('0x1d')](__dirname,_0x8b7c('0x19'),_0x7b9e59[_0x8b7c('0x1e')]+_0x8b7c('0x1f')));}}_0x56e02b[_0x8b7c('0x15')][_0x4262b5]=new RuleEngine(_0xcc0fcc);_0x56e02b['rules'][_0x4262b5][_0x8b7c('0x34')](_0xd37a82,function(_0x59b721){logger[_0x8b7c('0x31')](_0x8b7c('0x35'),JSON[_0x8b7c('0x36')](_0x59b721[_0x8b7c('0x37')]));if(_0x56e02b['rules'][_0x4262b5]){_0x56e02b[_0x8b7c('0x15')][_0x4262b5][_0x8b7c('0x38')](_0x8b7c('0x39'));}});return _0x496bc0({'code':0xc8,'message':_0xd37a82});}else{logger[_0x8b7c('0x31')](_0x8b7c('0x3a'));return _0x496bc0({'code':0xc8,'message':_0xd37a82});}}catch(_0x3252f9){logger['error'](_0x3252f9['stack']);return _0x3b8d62(_0x4284a2[_0x8b7c('0x3b')](0x1f4,_0x3252f9));}}return _0x3b8d62(_0x8b7c('0x3c'));});},'AcceptMessage':function(_0x4ccebb){var _0x50908c=this;return new Promise(function(_0x1c9058,_0x3119be){if(_0x4ccebb[_0x8b7c('0x3d')]&&_0x4ccebb[_0x8b7c('0x3d')]['id']){if(_0x56e02b[_0x8b7c('0x3e')][_0x4ccebb[_0x8b7c('0x3d')]['id']]){_0x56e02b[_0x8b7c('0x3e')][_0x4ccebb[_0x8b7c('0x3d')]['id']][_0x8b7c('0x3f')]=![];_0x56e02b[_0x8b7c('0x3e')][_0x4ccebb[_0x8b7c('0x3d')]['id']][_0x8b7c('0x40')]=undefined;}}if(_0x4ccebb['message']&&_0x4ccebb[_0x8b7c('0x17')]['id']){try{var _0x21a690=getId(_0x4ccebb[_0x8b7c('0x16')],_0x4ccebb[_0x8b7c('0x17')]?_0x4ccebb[_0x8b7c('0x17')]['id']:0x0,_0x4ccebb['interaction']?_0x4ccebb['interaction']['id']:0x0);if(_0x56e02b[_0x8b7c('0x15')][_0x21a690]){_0x56e02b[_0x8b7c('0x15')][_0x21a690][_0x8b7c('0x38')](_0x8b7c('0x41'));if(rpc[_0x4ccebb[_0x8b7c('0x16')]+_0x8b7c('0x42')]){rpc[_0x4ccebb['channel']+'QueueReport'][_0x8b7c('0x43')](_0x21a690,{'UserId':_0x4ccebb[_0x8b7c('0x17')]['UserId']})[_0x8b7c('0x44')](function(_0x18dea0){logger[_0x8b7c('0x3b')]('error\x20update\x20queue\x20report');});}}return _0x1c9058({'code':0xc8,'message':_0x4ccebb});}catch(_0x4c1a90){logger[_0x8b7c('0x3b')](_0x4c1a90['stack']);return _0x3119be(_0x50908c[_0x8b7c('0x3b')](0x1f4,_0x4c1a90));}}logger[_0x8b7c('0x3b')](_0x8b7c('0x45'));return _0x3119be(_0x50908c[_0x8b7c('0x3b')](0x1f4,_0x8b7c('0x45')));});},'RejectMessage':function(_0x39219c){var _0x29aec5=this;return new Promise(function(_0x52e6f4,_0x6179ec){if(_0x39219c[_0x8b7c('0x3d')]&&_0x39219c[_0x8b7c('0x3d')]['id']){try{if(_0x56e02b[_0x8b7c('0x3e')][_0x39219c['agent']['id']]){_0x56e02b['agents'][_0x39219c['agent']['id']][_0x8b7c('0x3f')]=![];_0x56e02b[_0x8b7c('0x3e')][_0x39219c[_0x8b7c('0x3d')]['id']]['busyQueue']=undefined;}return _0x52e6f4({'code':0xc8,'message':_0x39219c});}catch(_0x190192){logger[_0x8b7c('0x3b')](_0x190192[_0x8b7c('0x46')]);return _0x6179ec(_0x29aec5[_0x8b7c('0x3b')](0x1f4,_0x190192));}}logger[_0x8b7c('0x3b')](_0x8b7c('0x45'));return _0x6179ec(_0x29aec5['error'](0x1f4,_0x8b7c('0x45')));});},'AbandonInteraction':function(_0x34413b){var _0x2e2ea8=this;return new Promise(function(_0x5d9307,_0x2c85c1){if(_0x34413b[_0x8b7c('0x16')]&&_0x34413b[_0x8b7c('0x18')]&&_0x34413b[_0x8b7c('0x18')]['id']){try{var _0x4e4a4a=getId(_0x34413b['channel'],_0x34413b[_0x8b7c('0x17')]?_0x34413b[_0x8b7c('0x17')]['id']:0x0,_0x34413b['interaction']?_0x34413b[_0x8b7c('0x18')]['id']:0x0);if(_0x56e02b[_0x8b7c('0x15')][_0x4e4a4a]){_0x56e02b[_0x8b7c('0x15')][_0x4e4a4a]['emit'](_0x8b7c('0x41'));}return _0x5d9307({'code':0xc8,'message':_0x34413b});}catch(_0x119110){logger[_0x8b7c('0x3b')](_0x119110[_0x8b7c('0x46')]);return _0x2c85c1(_0x2e2ea8[_0x8b7c('0x3b')](0x1f4,_0x119110));}}logger[_0x8b7c('0x3b')]('message\x20is\x20empty');return _0x2c85c1(_0x2e2ea8['error'](0x1f4,_0x8b7c('0x45')));});},'AgentCapacity':function(_0xea8953){var _0x4f8828=this;return new Promise(function(_0x539241,_0x4b67b5){if(_0x56e02b[_0x8b7c('0x3e')]['hasOwnProperty'](_0xea8953['id'])){for(var _0x559b98 in _0xea8953[_0x8b7c('0x47')]){if(_0xea8953['capacity'][_0x8b7c('0x48')](_0x559b98)){if(_0x56e02b[_0x8b7c('0x3e')][_0xea8953['id']][_0x8b7c('0x48')](_0x559b98+_0x8b7c('0x49'))){_0x56e02b[_0x8b7c('0x3e')][_0xea8953['id']][_0x559b98+'CurrentCapacity']=parseInt(_0xea8953[_0x8b7c('0x47')][_0x559b98],0xa);}}}_0x56e02b[_0x8b7c('0x3e')][_0xea8953['id']][_0x8b7c('0x4a')]();return _0x539241({'code':0xc8,'message':_0x56e02b[_0x8b7c('0x3e')][_0xea8953['id']]});}else{return _0x4b67b5(_0x4f8828[_0x8b7c('0x3b')](0x1f4,_0x8b7c('0x4b')));}});},'Agents':function(_0x4458fd){return new Promise(function(_0x21e779,_0x3db1a6){var _0x2a50e3=_[_0x8b7c('0x4c')](_0x56e02b[_0x8b7c('0x3e')]);_0x21e779({'count':_0x2a50e3['length'],'rows':_0x2a50e3});});},'ChatQueues':function(_0x2c2403){return new Promise(function(_0x32d2e4,_0x57bb41){var _0x4ac7fe=[];for(var _0x5dbfc6 in _0x56e02b[_0x8b7c('0x4d')]){if(_0x56e02b[_0x8b7c('0x4d')][_0x8b7c('0x48')](_0x5dbfc6)){var _0x4b8075=_0x56e02b[_0x8b7c('0x4d')][_0x5dbfc6];var _0x275071={'id':_0x4b8075['id'],'available':_0x4b8075[_0x8b7c('0x4e')],'loggedIn':_0x4b8075[_0x8b7c('0x4f')],'name':_0x4b8075[_0x8b7c('0x50')],'paused':_0x4b8075['paused'],'waiting':_0x4b8075[_0x8b7c('0x51')]};_0x4ac7fe[_0x8b7c('0x25')](_0x275071);}}_0x32d2e4({'count':_0x4ac7fe[_0x8b7c('0x1b')],'rows':_0x4ac7fe});});},'MailQueues':function(_0x232b26){return new Promise(function(_0x263dde,_0x183a99){var _0x38ab9e=[];for(var _0x6b6b14 in _0x56e02b[_0x8b7c('0x52')]){if(_0x56e02b[_0x8b7c('0x52')][_0x8b7c('0x48')](_0x6b6b14)){var _0x4a3c56=_0x56e02b[_0x8b7c('0x52')][_0x6b6b14];var _0x474dce={'id':_0x4a3c56['id'],'available':_0x4a3c56[_0x8b7c('0x4e')],'loggedIn':_0x4a3c56[_0x8b7c('0x4f')],'name':_0x4a3c56[_0x8b7c('0x50')],'paused':_0x4a3c56[_0x8b7c('0x53')],'waiting':_0x4a3c56[_0x8b7c('0x51')]};_0x38ab9e[_0x8b7c('0x25')](_0x474dce);}}_0x263dde({'count':_0x38ab9e[_0x8b7c('0x1b')],'rows':_0x38ab9e});});},'OpenchannelQueues':function(_0xd1d677){return new Promise(function(_0x1e3817,_0x31b4c0){var _0x16a318=[];for(var _0x88ebe5 in _0x56e02b[_0x8b7c('0x54')]){if(_0x56e02b[_0x8b7c('0x54')][_0x8b7c('0x48')](_0x88ebe5)){var _0x2f28f9=_0x56e02b[_0x8b7c('0x54')][_0x88ebe5];var _0x13f3ae={'id':_0x2f28f9['id'],'available':_0x2f28f9['available'],'loggedIn':_0x2f28f9['loggedIn'],'name':_0x2f28f9['name'],'paused':_0x2f28f9[_0x8b7c('0x53')],'waiting':_0x2f28f9[_0x8b7c('0x51')]};_0x16a318[_0x8b7c('0x25')](_0x13f3ae);}}_0x1e3817({'count':_0x16a318[_0x8b7c('0x1b')],'rows':_0x16a318});});},'SmsQueues':function(_0x24a109){return new Promise(function(_0x4e8624,_0x473c17){var _0x2a3e3a=[];for(var _0x3475c2 in _0x56e02b['smsQueues']){if(_0x56e02b['smsQueues'][_0x8b7c('0x48')](_0x3475c2)){var _0x4e7f41=_0x56e02b['smsQueues'][_0x3475c2];var _0x11d609={'id':_0x4e7f41['id'],'available':_0x4e7f41[_0x8b7c('0x4e')],'loggedIn':_0x4e7f41[_0x8b7c('0x4f')],'name':_0x4e7f41[_0x8b7c('0x50')],'paused':_0x4e7f41['paused'],'waiting':_0x4e7f41[_0x8b7c('0x51')]};_0x2a3e3a[_0x8b7c('0x25')](_0x11d609);}}_0x4e8624({'count':_0x2a3e3a['length'],'rows':_0x2a3e3a});});},'FaxQueues':function(_0x18e9e8){return new Promise(function(_0x1a89c3,_0x57e0a6){var _0x429ebe=[];for(var _0x182632 in _0x56e02b[_0x8b7c('0x55')]){if(_0x56e02b[_0x8b7c('0x55')][_0x8b7c('0x48')](_0x182632)){var _0x5906b6=_0x56e02b['faxQueues'][_0x182632];var _0x368986={'id':_0x5906b6['id'],'available':_0x5906b6['available'],'loggedIn':_0x5906b6[_0x8b7c('0x4f')],'name':_0x5906b6[_0x8b7c('0x50')],'paused':_0x5906b6[_0x8b7c('0x53')],'waiting':_0x5906b6[_0x8b7c('0x51')]};_0x429ebe[_0x8b7c('0x25')](_0x368986);}}_0x1a89c3({'count':_0x429ebe[_0x8b7c('0x1b')],'rows':_0x429ebe});});},'WhatsappQueues':function(_0x3206f3){return new Promise(function(_0x25cd92,_0x3fd9ed){var _0x5a891a=[];for(var _0x3da940 in _0x56e02b[_0x8b7c('0x56')]){if(_0x56e02b[_0x8b7c('0x56')]['hasOwnProperty'](_0x3da940)){var _0x3a1c8f=_0x56e02b['whatsappQueues'][_0x3da940];var _0x5d3b4a={'id':_0x3a1c8f['id'],'available':_0x3a1c8f['available'],'loggedIn':_0x3a1c8f[_0x8b7c('0x4f')],'name':_0x3a1c8f[_0x8b7c('0x50')],'paused':_0x3a1c8f[_0x8b7c('0x53')],'waiting':_0x3a1c8f[_0x8b7c('0x51')]};_0x5a891a[_0x8b7c('0x25')](_0x5d3b4a);}}_0x25cd92({'count':_0x5a891a[_0x8b7c('0x1b')],'rows':_0x5a891a});});},'ChatQueuesWaitingInteractions':function(_0xba04f6){return new Promise(function(_0xc9a4a6,_0x329bd5){var _0x26e228=_[_0x8b7c('0x4c')](_0x56e02b[_0x8b7c('0x57')]);_0xc9a4a6({'count':_0x26e228[_0x8b7c('0x1b')],'rows':_0x26e228});});},'MailQueuesWaitingInteractions':function(_0x3f38b2){return new Promise(function(_0x13e718,_0x297e1f){var _0x56e623=_[_0x8b7c('0x4c')](_0x56e02b['mailQueuesWaitingInteractions']);_0x13e718({'count':_0x56e623[_0x8b7c('0x1b')],'rows':_0x56e623});});},'OpenchannelQueuesWaitingInteractions':function(_0x43bef2){return new Promise(function(_0x17db87,_0x3eef37){var _0x900b5c=_[_0x8b7c('0x4c')](_0x56e02b[_0x8b7c('0x58')]);_0x17db87({'count':_0x900b5c[_0x8b7c('0x1b')],'rows':_0x900b5c});});},'SmsQueuesWaitingInteractions':function(_0x2ad50f){return new Promise(function(_0x21e09d,_0x3b7e24){var _0x5b8d8f=_[_0x8b7c('0x4c')](_0x56e02b[_0x8b7c('0x59')]);_0x21e09d({'count':_0x5b8d8f['length'],'rows':_0x5b8d8f});});},'FaxQueuesWaitingInteractions':function(_0x966e37){return new Promise(function(_0x297224,_0x621699){var _0x39e24f=_[_0x8b7c('0x4c')](_0x56e02b['faxQueuesWaitingInteractions']);_0x297224({'count':_0x39e24f['length'],'rows':_0x39e24f});});},'WhatsappQueuesWaitingInteractions':function(_0x2687a0){return new Promise(function(_0x506ba7,_0x35694f){var _0x166d3c=_[_0x8b7c('0x4c')](_0x56e02b[_0x8b7c('0x5a')]);_0x506ba7({'count':_0x166d3c[_0x8b7c('0x1b')],'rows':_0x166d3c});});}};var _0x48c7dd=jayson['server'](_0x52cfe7)['http']();_0x48c7dd['on'](_0x8b7c('0x3b'),function(_0x2a534b){logger['error'](JSON[_0x8b7c('0x36')](_0x2a534b));return _0x5857ac(_0x2a534b);});_0x48c7dd['listen'](0x232c,_0x8b7c('0x5b'),function(){console[_0x8b7c('0x5c')](_0x8b7c('0x5d'),0x232c);return _0x19c63e(_0x8b7c('0x5e')+0x232c);});});};
\ No newline at end of file