Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / services / routing / server / index.js
index 8f5ded6..eaf9b09 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbf4f=['dialogflow','dialogflowv2','amazonlex','TagId','%s:%s:%s','./interval','intervals','consequence','priority','on\x20interval','\x20|\x20','error','rules','execute','info','Applications\x20executed','stringify','matchPath','emit','complete','stack','routing\x20is\x20empty','channel','end','QueueReport','update','UserId','catch','error\x20update\x20queue\x20report','message\x20is\x20empty','agent','agents','busy','hasOwnProperty','capacity','CurrentCapacity','updateRealtime','values','chatQueues','loggedIn','waiting','mailQueues','available','name','paused','openchannelQueues','smsQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','server','http','listen','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','util','path','jayson/promise','bluebird','uuid','../../../config/environment','../../../config/logger','routing','../rpc/openchannelQueueReport','../rpc/mailQueueReport','../rpc/chatQueueReport','../rpc/smsQueueReport','../rpc/whatsappQueueReport','../lib/rule-engine','format','%s.%s.%s','isNil','IntervalId','Intervals','interval','message','interaction','length','applications','existsSync','join','app','.js','appdata','split','push','slice'];(function(_0xaa0c67,_0x3e63cb){var _0x34034f=function(_0x1dfa5a){while(--_0x1dfa5a){_0xaa0c67['push'](_0xaa0c67['shift']());}};_0x34034f(++_0x3e63cb);}(_0xbf4f,0x98));var _0xfbf4=function(_0xcc05ed,_0x44eb83){_0xcc05ed=_0xcc05ed-0x0;var _0x24a2f5=_0xbf4f[_0xcc05ed];return _0x24a2f5;};'use strict';var _=require('lodash');var util=require(_0xfbf4('0x0'));var path=require(_0xfbf4('0x1'));var fs=require('fs');var jayson=require(_0xfbf4('0x2'));var BPromise=require(_0xfbf4('0x3'));var uuid=require(_0xfbf4('0x4'));var config=require(_0xfbf4('0x5'));var logger=require(_0xfbf4('0x6'))(_0xfbf4('0x7'));var rpc={'openchannelQueueReport':require(_0xfbf4('0x8')),'mailQueueReport':require(_0xfbf4('0x9')),'chatQueueReport':require(_0xfbf4('0xa')),'smsQueueReport':require(_0xfbf4('0xb')),'faxQueueReport':require('../rpc/faxQueueReport'),'whatsappQueueReport':require(_0xfbf4('0xc'))};var RuleEngine=require(_0xfbf4('0xd'));function getId(_0x5a4a99,_0x5ce72f,_0x5cfb6e){return util[_0xfbf4('0xe')](_0xfbf4('0xf'),_0x5a4a99,_0x5ce72f||0x0,_0x5cfb6e||0x0);}function getIntervals(_0x2f2656,_0x43b640){var _0x1d18b1=[];if(!_[_0xfbf4('0x10')](_0x43b640[_0xfbf4('0x11')])&&!_['isNil'](_0x2f2656[_0x43b640['IntervalId']])&&!_[_0xfbf4('0x10')](_0x2f2656[_0x43b640[_0xfbf4('0x11')]][_0xfbf4('0x12')])){_0x1d18b1=_['map'](_0x2f2656[_0x43b640['IntervalId']][_0xfbf4('0x12')],_0xfbf4('0x13'));}else if(!_['isNil'](_0x43b640['interval'])){_0x1d18b1=[_0x43b640[_0xfbf4('0x13')]];}return _0x1d18b1;}exports['listen']=function(_0xc2cf41){_0xc2cf41['rules']={};return new BPromise(function(_0x46daba,_0xf5f23){var _0x43e1e3={'Start':function(_0x51fcc5){var _0x3225cd=this;return new Promise(function(_0x55f7d8,_0x2f1fda){if(_0x51fcc5){try{var _0x18a786=[];var _0x4b421d=getId(_0x51fcc5['channel'],_0x51fcc5[_0xfbf4('0x14')]?_0x51fcc5[_0xfbf4('0x14')]['id']:0x0,_0x51fcc5['interaction']?_0x51fcc5[_0xfbf4('0x15')]['id']:0x0);if(_0x51fcc5['applications']&&_['isArray'](_0x51fcc5['applications'])&&_0x51fcc5['applications'][_0xfbf4('0x16')]){for(var _0x23e644=0x0;_0x23e644<_0x51fcc5[_0xfbf4('0x17')][_0xfbf4('0x16')];_0x23e644+=0x1){var _0x5b83e4=_0x51fcc5[_0xfbf4('0x17')][_0x23e644];if(fs[_0xfbf4('0x18')](path[_0xfbf4('0x19')](__dirname,'applications',_0x5b83e4[_0xfbf4('0x1a')]+_0xfbf4('0x1b')))){var _0x158f07=[];switch(_0x5b83e4[_0xfbf4('0x1a')]['toLowerCase']()){case'autoreply':var _0x3066e1=_0x5b83e4[_0xfbf4('0x1c')][_0xfbf4('0x1d')](',');_0x158f07[_0xfbf4('0x1e')](_0x3066e1[0x0]);_0x158f07[_0xfbf4('0x1e')](_0x3066e1[_0xfbf4('0x1f')](0x1,_0x3066e1[_0xfbf4('0x16')])['join'](','));break;case _0xfbf4('0x20'):var _0xb68edb=_0x5b83e4[_0xfbf4('0x1c')]['split'](',');_0x158f07[_0xfbf4('0x1e')](_0xb68edb[0x0]);_0x158f07[_0xfbf4('0x1e')](_0xb68edb[0x1]);_0x158f07[_0xfbf4('0x1e')](_0xb68edb[_0xfbf4('0x1f')](0x2,_0xb68edb[_0xfbf4('0x16')])[_0xfbf4('0x19')](','));break;case _0xfbf4('0x21'):var _0x22c675=_0x5b83e4[_0xfbf4('0x1c')][_0xfbf4('0x1d')](',');_0x158f07[_0xfbf4('0x1e')](_0x22c675[0x0]);_0x158f07[_0xfbf4('0x1e')](_0x22c675[0x1]);_0x158f07[_0xfbf4('0x1e')](_0x22c675[0x2]);_0x158f07['push'](_0x22c675[0x3]);_0x158f07[_0xfbf4('0x1e')](_0x22c675[_0xfbf4('0x1f')](0x4,_0x22c675[_0xfbf4('0x16')])[_0xfbf4('0x19')](','));break;case _0xfbf4('0x22'):var _0xa45909=_0x5b83e4[_0xfbf4('0x1c')][_0xfbf4('0x1d')](',');_0x158f07[_0xfbf4('0x1e')](_0xa45909[0x0]);_0x158f07['push'](_0xa45909[0x1]);_0x158f07['push'](_0xa45909[0x2]);_0x158f07[_0xfbf4('0x1e')](_0xa45909[0x3]);_0x158f07[_0xfbf4('0x1e')](_0xa45909[_0xfbf4('0x1f')](0x4,_0xa45909[_0xfbf4('0x16')])[_0xfbf4('0x19')](','));break;case _0xfbf4('0x14'):_0x158f07['push'](_0x5b83e4[_0xfbf4('0x1c')]);break;case'tag':_0x158f07[_0xfbf4('0x1e')](_0x5b83e4[_0xfbf4('0x23')]);_0x158f07[_0xfbf4('0x1e')](_0x5b83e4[_0xfbf4('0x1c')]);break;default:_0x158f07=_['isNil'](_0x5b83e4[_0xfbf4('0x1c')])?[]:_0x5b83e4['appdata']['split'](',');}var _0xd54950={'id':util[_0xfbf4('0xe')](_0xfbf4('0x24'),_0x4b421d,_0x5b83e4['id'],_0x5b83e4['app']),'condition':require(_0xfbf4('0x25'))['condition'](_0x4b421d,getIntervals(_0xc2cf41[_0xfbf4('0x26')],_0x5b83e4),_0xc2cf41),'consequence':require('./applications/'+_0x5b83e4[_0xfbf4('0x1a')])[_0xfbf4('0x27')](_0x4b421d,_0x158f07,_0xc2cf41,_0x51fcc5),'p':_0x5b83e4[_0xfbf4('0x28')]||0x0};logger['info']('Push\x20new\x20rule',_0xd54950['id'],_0xfbf4('0x29'),getIntervals(_0xc2cf41[_0xfbf4('0x26')],_0x5b83e4)[_0xfbf4('0x19')](_0xfbf4('0x2a')));_0x18a786[_0xfbf4('0x1e')](_0xd54950);}else{logger[_0xfbf4('0x2b')]('Please\x20create\x20a\x20new\x20file\x20under',path[_0xfbf4('0x19')](__dirname,_0xfbf4('0x17'),_0x5b83e4['app']+'.js'));}}_0xc2cf41[_0xfbf4('0x2c')][_0x4b421d]=new RuleEngine(_0x18a786);_0xc2cf41[_0xfbf4('0x2c')][_0x4b421d][_0xfbf4('0x2d')](_0x51fcc5,function(_0x27f5d0){logger[_0xfbf4('0x2e')](_0xfbf4('0x2f'),JSON[_0xfbf4('0x30')](_0x27f5d0[_0xfbf4('0x31')]));if(_0xc2cf41[_0xfbf4('0x2c')][_0x4b421d]){_0xc2cf41[_0xfbf4('0x2c')][_0x4b421d][_0xfbf4('0x32')](_0xfbf4('0x33'));}});return _0x55f7d8({'code':0xc8,'message':_0x51fcc5});}else{logger[_0xfbf4('0x2e')]('No\x20applications\x20to\x20execute');return _0x55f7d8({'code':0xc8,'message':_0x51fcc5});}}catch(_0x44a284){logger['error'](_0x44a284[_0xfbf4('0x34')]);return _0x2f1fda(_0x3225cd['error'](0x1f4,_0x44a284));}}return _0x2f1fda(_0xfbf4('0x35'));});},'AcceptMessage':function(_0x596465){var _0xd789fb=this;return new Promise(function(_0x356b4c,_0x4b851f){if(_0x596465[_0xfbf4('0x14')]&&_0x596465['message']['id']){try{var _0x160959=getId(_0x596465[_0xfbf4('0x36')],_0x596465[_0xfbf4('0x14')]?_0x596465[_0xfbf4('0x14')]['id']:0x0,_0x596465[_0xfbf4('0x15')]?_0x596465[_0xfbf4('0x15')]['id']:0x0);if(_0xc2cf41['rules'][_0x160959]){_0xc2cf41[_0xfbf4('0x2c')][_0x160959][_0xfbf4('0x32')](_0xfbf4('0x37'));if(rpc[_0x596465[_0xfbf4('0x36')]+_0xfbf4('0x38')]){rpc[_0x596465[_0xfbf4('0x36')]+_0xfbf4('0x38')][_0xfbf4('0x39')](_0x160959,{'UserId':_0x596465[_0xfbf4('0x14')][_0xfbf4('0x3a')]})[_0xfbf4('0x3b')](function(_0x18aeb0){logger[_0xfbf4('0x2b')](_0xfbf4('0x3c'));});}}return _0x356b4c({'code':0xc8,'message':_0x596465});}catch(_0x4ed334){logger[_0xfbf4('0x2b')](_0x4ed334['stack']);return _0x4b851f(_0xd789fb[_0xfbf4('0x2b')](0x1f4,_0x4ed334));}}logger[_0xfbf4('0x2b')](_0xfbf4('0x3d'));return _0x4b851f(_0xd789fb['error'](0x1f4,'message\x20is\x20empty'));});},'RejectMessage':function(_0x490f25){var _0x5d7c87=this;return new Promise(function(_0x305e10,_0x588daf){if(_0x490f25[_0xfbf4('0x3e')]&&_0x490f25[_0xfbf4('0x3e')]['id']){try{if(_0xc2cf41[_0xfbf4('0x3f')][_0x490f25[_0xfbf4('0x3e')]['id']]){_0xc2cf41['agents'][_0x490f25[_0xfbf4('0x3e')]['id']][_0xfbf4('0x40')]=![];_0xc2cf41[_0xfbf4('0x3f')][_0x490f25['agent']['id']]['busyQueue']=undefined;}return _0x305e10({'code':0xc8,'message':_0x490f25});}catch(_0x30bd66){logger[_0xfbf4('0x2b')](_0x30bd66[_0xfbf4('0x34')]);return _0x588daf(_0x5d7c87[_0xfbf4('0x2b')](0x1f4,_0x30bd66));}}logger['error']('message\x20is\x20empty');return _0x588daf(_0x5d7c87[_0xfbf4('0x2b')](0x1f4,_0xfbf4('0x3d')));});},'AbandonInteraction':function(_0x1908ac){var _0x3aaa76=this;return new Promise(function(_0x3e3196,_0x502b7a){if(_0x1908ac[_0xfbf4('0x36')]&&_0x1908ac['interaction']&&_0x1908ac[_0xfbf4('0x15')]['id']){try{var _0x33147e=getId(_0x1908ac[_0xfbf4('0x36')],_0x1908ac[_0xfbf4('0x14')]?_0x1908ac[_0xfbf4('0x14')]['id']:0x0,_0x1908ac[_0xfbf4('0x15')]?_0x1908ac[_0xfbf4('0x15')]['id']:0x0);if(_0xc2cf41[_0xfbf4('0x2c')][_0x33147e]){_0xc2cf41[_0xfbf4('0x2c')][_0x33147e][_0xfbf4('0x32')](_0xfbf4('0x37'));}return _0x3e3196({'code':0xc8,'message':_0x1908ac});}catch(_0x1ab2d2){logger[_0xfbf4('0x2b')](_0x1ab2d2[_0xfbf4('0x34')]);return _0x502b7a(_0x3aaa76['error'](0x1f4,_0x1ab2d2));}}logger[_0xfbf4('0x2b')]('message\x20is\x20empty');return _0x502b7a(_0x3aaa76[_0xfbf4('0x2b')](0x1f4,_0xfbf4('0x3d')));});},'AgentCapacity':function(_0x5258d7){var _0x26bd7e=this;return new Promise(function(_0x4a42d8,_0x55cc04){if(_0xc2cf41[_0xfbf4('0x3f')][_0xfbf4('0x41')](_0x5258d7['id'])){for(var _0x9690cb in _0x5258d7['capacity']){if(_0x5258d7[_0xfbf4('0x42')][_0xfbf4('0x41')](_0x9690cb)){if(_0xc2cf41[_0xfbf4('0x3f')][_0x5258d7['id']]['hasOwnProperty'](_0x9690cb+_0xfbf4('0x43'))){_0xc2cf41[_0xfbf4('0x3f')][_0x5258d7['id']][_0x9690cb+'CurrentCapacity']=parseInt(_0x5258d7[_0xfbf4('0x42')][_0x9690cb],0xa);}}}_0xc2cf41[_0xfbf4('0x3f')][_0x5258d7['id']][_0xfbf4('0x44')]();return _0x4a42d8({'code':0xc8,'message':_0xc2cf41['agents'][_0x5258d7['id']]});}else{return _0x55cc04(_0x26bd7e[_0xfbf4('0x2b')](0x1f4,'agent\x20not\x20found'));}});},'Agents':function(_0x6caa4b){return new Promise(function(_0x4c6b3b,_0x4abdb0){var _0xc013e5=_[_0xfbf4('0x45')](_0xc2cf41['agents']);_0x4c6b3b({'count':_0xc013e5[_0xfbf4('0x16')],'rows':_0xc013e5});});},'ChatQueues':function(_0x4cd7e4){return new Promise(function(_0x281d1e,_0x333e6f){var _0x8a7cc9=[];for(var _0xc235d0 in _0xc2cf41['chatQueues']){if(_0xc2cf41[_0xfbf4('0x46')][_0xfbf4('0x41')](_0xc235d0)){var _0x3fc195=_0xc2cf41[_0xfbf4('0x46')][_0xc235d0];var _0x4f3bd9={'id':_0x3fc195['id'],'available':_0x3fc195['available'],'loggedIn':_0x3fc195[_0xfbf4('0x47')],'name':_0x3fc195['name'],'paused':_0x3fc195['paused'],'waiting':_0x3fc195[_0xfbf4('0x48')]};_0x8a7cc9[_0xfbf4('0x1e')](_0x4f3bd9);}}_0x281d1e({'count':_0x8a7cc9[_0xfbf4('0x16')],'rows':_0x8a7cc9});});},'MailQueues':function(_0x48b1c5){return new Promise(function(_0xdad4ae,_0x480a58){var _0x4da0bc=[];for(var _0x5ce8a6 in _0xc2cf41[_0xfbf4('0x49')]){if(_0xc2cf41['mailQueues'][_0xfbf4('0x41')](_0x5ce8a6)){var _0x29b09f=_0xc2cf41[_0xfbf4('0x49')][_0x5ce8a6];var _0x1b6505={'id':_0x29b09f['id'],'available':_0x29b09f[_0xfbf4('0x4a')],'loggedIn':_0x29b09f[_0xfbf4('0x47')],'name':_0x29b09f[_0xfbf4('0x4b')],'paused':_0x29b09f[_0xfbf4('0x4c')],'waiting':_0x29b09f[_0xfbf4('0x48')]};_0x4da0bc[_0xfbf4('0x1e')](_0x1b6505);}}_0xdad4ae({'count':_0x4da0bc[_0xfbf4('0x16')],'rows':_0x4da0bc});});},'OpenchannelQueues':function(_0x1caee2){return new Promise(function(_0x3345ec,_0x3d9228){var _0x48a08e=[];for(var _0xb68163 in _0xc2cf41[_0xfbf4('0x4d')]){if(_0xc2cf41[_0xfbf4('0x4d')][_0xfbf4('0x41')](_0xb68163)){var _0x33d5c3=_0xc2cf41['openchannelQueues'][_0xb68163];var _0x58509a={'id':_0x33d5c3['id'],'available':_0x33d5c3[_0xfbf4('0x4a')],'loggedIn':_0x33d5c3[_0xfbf4('0x47')],'name':_0x33d5c3[_0xfbf4('0x4b')],'paused':_0x33d5c3[_0xfbf4('0x4c')],'waiting':_0x33d5c3[_0xfbf4('0x48')]};_0x48a08e[_0xfbf4('0x1e')](_0x58509a);}}_0x3345ec({'count':_0x48a08e[_0xfbf4('0x16')],'rows':_0x48a08e});});},'SmsQueues':function(_0x38a28f){return new Promise(function(_0x18dd99,_0x2f5e2e){var _0x175ac5=[];for(var _0x15dbca in _0xc2cf41['smsQueues']){if(_0xc2cf41[_0xfbf4('0x4e')][_0xfbf4('0x41')](_0x15dbca)){var _0x1d5de5=_0xc2cf41['smsQueues'][_0x15dbca];var _0x3f388c={'id':_0x1d5de5['id'],'available':_0x1d5de5['available'],'loggedIn':_0x1d5de5[_0xfbf4('0x47')],'name':_0x1d5de5[_0xfbf4('0x4b')],'paused':_0x1d5de5[_0xfbf4('0x4c')],'waiting':_0x1d5de5[_0xfbf4('0x48')]};_0x175ac5[_0xfbf4('0x1e')](_0x3f388c);}}_0x18dd99({'count':_0x175ac5[_0xfbf4('0x16')],'rows':_0x175ac5});});},'FaxQueues':function(_0x131ff0){return new Promise(function(_0x244d92,_0x2773ef){var _0x330332=[];for(var _0x7b2ec0 in _0xc2cf41[_0xfbf4('0x4f')]){if(_0xc2cf41[_0xfbf4('0x4f')]['hasOwnProperty'](_0x7b2ec0)){var _0x3fc519=_0xc2cf41['faxQueues'][_0x7b2ec0];var _0x168696={'id':_0x3fc519['id'],'available':_0x3fc519[_0xfbf4('0x4a')],'loggedIn':_0x3fc519[_0xfbf4('0x47')],'name':_0x3fc519[_0xfbf4('0x4b')],'paused':_0x3fc519[_0xfbf4('0x4c')],'waiting':_0x3fc519[_0xfbf4('0x48')]};_0x330332[_0xfbf4('0x1e')](_0x168696);}}_0x244d92({'count':_0x330332[_0xfbf4('0x16')],'rows':_0x330332});});},'WhatsappQueues':function(_0x5dbc48){return new Promise(function(_0x431cb2,_0x9a69e7){var _0x215f9d=[];for(var _0x91e745 in _0xc2cf41['whatsappQueues']){if(_0xc2cf41[_0xfbf4('0x50')][_0xfbf4('0x41')](_0x91e745)){var _0x3876cf=_0xc2cf41['whatsappQueues'][_0x91e745];var _0x158b5c={'id':_0x3876cf['id'],'available':_0x3876cf[_0xfbf4('0x4a')],'loggedIn':_0x3876cf[_0xfbf4('0x47')],'name':_0x3876cf['name'],'paused':_0x3876cf[_0xfbf4('0x4c')],'waiting':_0x3876cf[_0xfbf4('0x48')]};_0x215f9d[_0xfbf4('0x1e')](_0x158b5c);}}_0x431cb2({'count':_0x215f9d['length'],'rows':_0x215f9d});});},'ChatQueuesWaitingInteractions':function(_0x58aa7f){return new Promise(function(_0x241405,_0x56e18e){var _0x542654=_[_0xfbf4('0x45')](_0xc2cf41[_0xfbf4('0x51')]);_0x241405({'count':_0x542654[_0xfbf4('0x16')],'rows':_0x542654});});},'MailQueuesWaitingInteractions':function(_0x352fe4){return new Promise(function(_0x3c341f,_0x12805e){var _0x32593d=_[_0xfbf4('0x45')](_0xc2cf41['mailQueuesWaitingInteractions']);_0x3c341f({'count':_0x32593d[_0xfbf4('0x16')],'rows':_0x32593d});});},'OpenchannelQueuesWaitingInteractions':function(_0x106f44){return new Promise(function(_0x5756d7,_0x5ca0f2){var _0x150b57=_[_0xfbf4('0x45')](_0xc2cf41[_0xfbf4('0x52')]);_0x5756d7({'count':_0x150b57[_0xfbf4('0x16')],'rows':_0x150b57});});},'SmsQueuesWaitingInteractions':function(_0x4fb260){return new Promise(function(_0x49971d,_0xc71a35){var _0x222dc3=_['values'](_0xc2cf41[_0xfbf4('0x53')]);_0x49971d({'count':_0x222dc3[_0xfbf4('0x16')],'rows':_0x222dc3});});},'FaxQueuesWaitingInteractions':function(_0xe5a996){return new Promise(function(_0x354c3b,_0xa72328){var _0x15b190=_['values'](_0xc2cf41[_0xfbf4('0x54')]);_0x354c3b({'count':_0x15b190[_0xfbf4('0x16')],'rows':_0x15b190});});},'WhatsappQueuesWaitingInteractions':function(_0x15598c){return new Promise(function(_0x400d2f,_0x4291be){var _0x2053f8=_[_0xfbf4('0x45')](_0xc2cf41[_0xfbf4('0x55')]);_0x400d2f({'count':_0x2053f8[_0xfbf4('0x16')],'rows':_0x2053f8});});}};var _0x3a4634=jayson[_0xfbf4('0x56')](_0x43e1e3)[_0xfbf4('0x57')]();_0x3a4634['on'](_0xfbf4('0x2b'),function(_0x34871f){logger['error'](JSON['stringify'](_0x34871f));return _0xf5f23(_0x34871f);});_0x3a4634[_0xfbf4('0x58')](0x232c,'127.0.0.1',function(){console[_0xfbf4('0x59')](_0xfbf4('0x5a'),0x232c);return _0x46daba(_0xfbf4('0x5b')+0x232c);});});};
\ No newline at end of file
+var _0x05b0=['existsSync','join','.js','app','toLowerCase','autoreply','split','mail','push','slice','dialogflow','appdata','dialogflowv2','amazonlex','tag','TagId','tvox','getMustacheRender','account','notificationTemplate','ChatWebsiteId','ContactId','body','%s:%s:%s','./interval','condition','intervals','./applications/','info','Push\x20new\x20rule','on\x20interval','error','Please\x20create\x20a\x20new\x20file\x20under','rules','execute','Applications\x20executed','stringify','matchPath','emit','complete','No\x20applications\x20to\x20execute','stack','routing\x20is\x20empty','agent','agents','end','QueueReport','update','UserId','catch','message\x20is\x20empty','hasOwnProperty','capacity','CurrentCapacity','updateRealtime','agent\x20not\x20found','values','chatQueues','available','loggedIn','name','paused','waiting','mailQueues','openchannelQueues','smsQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','server','http','listen','127.0.0.1','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','path','jayson/promise','uuid','./applications/utils','../../../config/logger','routing','../rpc/mailQueueReport','../rpc/chatQueueReport','../rpc/smsQueueReport','../rpc/faxQueueReport','../rpc/whatsappQueueReport','../lib/rule-engine','format','isNil','IntervalId','Intervals','map','interval','channel','message','interaction','isArray','applications','length'];(function(_0x10890a,_0x282ef5){var _0x4a91bb=function(_0x43d9d5){while(--_0x43d9d5){_0x10890a['push'](_0x10890a['shift']());}};_0x4a91bb(++_0x282ef5);}(_0x05b0,0x188));var _0x005b=function(_0x190f0f,_0x55ef9c){_0x190f0f=_0x190f0f-0x0;var _0x4d6736=_0x05b0[_0x190f0f];return _0x4d6736;};'use strict';var _=require('lodash');var util=require('util');var path=require(_0x005b('0x0'));var fs=require('fs');var jayson=require(_0x005b('0x1'));var BPromise=require('bluebird');var uuid=require(_0x005b('0x2'));var utils=require(_0x005b('0x3'));var config=require('../../../config/environment');var logger=require(_0x005b('0x4'))(_0x005b('0x5'));var rpc={'openchannelQueueReport':require('../rpc/openchannelQueueReport'),'mailQueueReport':require(_0x005b('0x6')),'chatQueueReport':require(_0x005b('0x7')),'smsQueueReport':require(_0x005b('0x8')),'faxQueueReport':require(_0x005b('0x9')),'whatsappQueueReport':require(_0x005b('0xa'))};var RuleEngine=require(_0x005b('0xb'));function getId(_0x263bc9,_0x5cff7f,_0x224892){return util[_0x005b('0xc')]('%s.%s.%s',_0x263bc9,_0x5cff7f||0x0,_0x224892||0x0);}function getIntervals(_0x53fff4,_0x451641){var _0x4d41b8=[];if(!_['isNil'](_0x451641['IntervalId'])&&!_[_0x005b('0xd')](_0x53fff4[_0x451641[_0x005b('0xe')]])&&!_['isNil'](_0x53fff4[_0x451641[_0x005b('0xe')]][_0x005b('0xf')])){_0x4d41b8=_[_0x005b('0x10')](_0x53fff4[_0x451641[_0x005b('0xe')]][_0x005b('0xf')],_0x005b('0x11'));}else if(!_[_0x005b('0xd')](_0x451641['interval'])){_0x4d41b8=[_0x451641['interval']];}return _0x4d41b8;}exports['listen']=function(_0x309c8f){_0x309c8f['rules']={};return new BPromise(function(_0x3e2c82,_0x52f822){var _0x1c8eed={'Start':function(_0x1f7743){var _0x2ce01e=this;return new Promise(function(_0x1991e8,_0x337ca1){if(_0x1f7743){try{var _0x500c1a=[];var _0xa3c3fb=getId(_0x1f7743[_0x005b('0x12')],_0x1f7743[_0x005b('0x13')]?_0x1f7743['message']['id']:0x0,_0x1f7743[_0x005b('0x14')]?_0x1f7743[_0x005b('0x14')]['id']:0x0);if(_0x1f7743['applications']&&_[_0x005b('0x15')](_0x1f7743[_0x005b('0x16')])&&_0x1f7743[_0x005b('0x16')][_0x005b('0x17')]){for(var _0xf51601=0x0;_0xf51601<_0x1f7743['applications'][_0x005b('0x17')];_0xf51601+=0x1){var _0x38cc3b=_0x1f7743['applications'][_0xf51601];if(fs[_0x005b('0x18')](path[_0x005b('0x19')](__dirname,_0x005b('0x16'),_0x38cc3b['app']+_0x005b('0x1a')))){var _0x145c36=[];switch(_0x38cc3b[_0x005b('0x1b')][_0x005b('0x1c')]()){case _0x005b('0x1d'):var _0x2e3ccd=_0x38cc3b['appdata'][_0x005b('0x1e')](',');if(_0x1f7743[_0x005b('0x12')]===_0x005b('0x1f')){_0x145c36['push'](_0x2e3ccd[0x0]);_0x145c36[_0x005b('0x20')](_0x2e3ccd[0x1]);_0x145c36['push'](_0x2e3ccd[_0x005b('0x21')](0x2,_0x2e3ccd['length'])['join'](','));}else{_0x145c36[_0x005b('0x20')](_0x2e3ccd[0x0]);_0x145c36[_0x005b('0x20')](_0x2e3ccd[_0x005b('0x21')](0x1,_0x2e3ccd[_0x005b('0x17')])[_0x005b('0x19')](','));}break;case _0x005b('0x22'):var _0x3d4a1c=_0x38cc3b[_0x005b('0x23')]['split'](',');_0x145c36[_0x005b('0x20')](_0x3d4a1c[0x0]);_0x145c36[_0x005b('0x20')](_0x3d4a1c[0x1]);_0x145c36[_0x005b('0x20')](_0x3d4a1c[_0x005b('0x21')](0x2,_0x3d4a1c[_0x005b('0x17')])[_0x005b('0x19')](','));break;case _0x005b('0x24'):var _0x49561a=_0x38cc3b[_0x005b('0x23')][_0x005b('0x1e')](',');_0x145c36[_0x005b('0x20')](_0x49561a[0x0]);_0x145c36[_0x005b('0x20')](_0x49561a[0x1]);_0x145c36['push'](_0x49561a[0x2]);_0x145c36['push'](_0x49561a[0x3]);_0x145c36[_0x005b('0x20')](_0x49561a[_0x005b('0x21')](0x4,_0x49561a['length'])['join'](','));break;case _0x005b('0x25'):var _0x5b555f=_0x38cc3b[_0x005b('0x23')][_0x005b('0x1e')](',');_0x145c36[_0x005b('0x20')](_0x5b555f[0x0]);_0x145c36['push'](_0x5b555f[0x1]);_0x145c36['push'](_0x5b555f[0x2]);_0x145c36[_0x005b('0x20')](_0x5b555f[0x3]);_0x145c36[_0x005b('0x20')](_0x5b555f[_0x005b('0x21')](0x4,_0x5b555f['length'])['join'](','));break;case _0x005b('0x13'):_0x145c36[_0x005b('0x20')](_0x38cc3b['appdata']);break;case _0x005b('0x26'):_0x145c36['push'](_0x38cc3b[_0x005b('0x27')]);_0x145c36['push'](_0x38cc3b['appdata']);break;case _0x005b('0x28'):var _0x413d90=utils[_0x005b('0x29')](_0x1f7743[_0x005b('0x2a')][_0x005b('0x2b')],_0x1f7743);var _0x52bffe=_0x38cc3b['appdata'][_0x005b('0x1e')](',');_0x145c36[_0x005b('0x20')](_0x52bffe[0x0]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x1]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x2]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x3]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x4]);_0x145c36['push'](_0x52bffe[0x5]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x6]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x7]);_0x145c36[_0x005b('0x20')](_0x52bffe[0x8]);_0x145c36['push'](_0x52bffe[0x9]);_0x145c36[_0x005b('0x20')](_0x52bffe[0xa]);_0x145c36[_0x005b('0x20')](_0x1f7743[_0x005b('0x14')]['id']);_0x145c36[_0x005b('0x20')](_0x1f7743[_0x005b('0x13')]['id']);_0x145c36[_0x005b('0x20')](_0x38cc3b[_0x005b('0x2c')]);_0x145c36[_0x005b('0x20')](_0x1f7743[_0x005b('0x14')][_0x005b('0x2d')]);_0x145c36['push'](_0x1f7743[_0x005b('0x2e')][_0x005b('0x2e')]);_0x145c36['push'](_0x413d90);break;default:_0x145c36=_[_0x005b('0xd')](_0x38cc3b[_0x005b('0x23')])?[]:_0x38cc3b[_0x005b('0x23')][_0x005b('0x1e')](',');}var _0x4ec11c={'id':util[_0x005b('0xc')](_0x005b('0x2f'),_0xa3c3fb,_0x38cc3b['id'],_0x38cc3b['app']),'condition':require(_0x005b('0x30'))[_0x005b('0x31')](_0xa3c3fb,getIntervals(_0x309c8f[_0x005b('0x32')],_0x38cc3b),_0x309c8f),'consequence':require(_0x005b('0x33')+_0x38cc3b[_0x005b('0x1b')])['consequence'](_0xa3c3fb,_0x145c36,_0x309c8f,_0x1f7743),'p':_0x38cc3b['priority']||0x0};logger[_0x005b('0x34')](_0x005b('0x35'),_0x4ec11c['id'],_0x005b('0x36'),getIntervals(_0x309c8f[_0x005b('0x32')],_0x38cc3b)[_0x005b('0x19')]('\x20|\x20'));_0x500c1a[_0x005b('0x20')](_0x4ec11c);}else{logger[_0x005b('0x37')](_0x005b('0x38'),path[_0x005b('0x19')](__dirname,_0x005b('0x16'),_0x38cc3b[_0x005b('0x1b')]+'.js'));}}_0x309c8f[_0x005b('0x39')][_0xa3c3fb]=new RuleEngine(_0x500c1a);_0x309c8f['rules'][_0xa3c3fb][_0x005b('0x3a')](_0x1f7743,function(_0x26375b){logger['info'](_0x005b('0x3b'),JSON[_0x005b('0x3c')](_0x26375b[_0x005b('0x3d')]));if(_0x309c8f[_0x005b('0x39')][_0xa3c3fb]){_0x309c8f['rules'][_0xa3c3fb][_0x005b('0x3e')](_0x005b('0x3f'));}});return _0x1991e8({'code':0xc8,'message':_0x1f7743});}else{logger[_0x005b('0x34')](_0x005b('0x40'));return _0x1991e8({'code':0xc8,'message':_0x1f7743});}}catch(_0x3a5d41){logger[_0x005b('0x37')](_0x3a5d41[_0x005b('0x41')]);return _0x337ca1(_0x2ce01e[_0x005b('0x37')](0x1f4,_0x3a5d41));}}return _0x337ca1(_0x005b('0x42'));});},'AcceptMessage':function(_0x5699d8){var _0x1fed84=this;return new Promise(function(_0x30947e,_0x34fabc){if(_0x5699d8[_0x005b('0x43')]&&_0x5699d8[_0x005b('0x43')]['id']){if(_0x309c8f['agents'][_0x5699d8[_0x005b('0x43')]['id']]){_0x309c8f[_0x005b('0x44')][_0x5699d8[_0x005b('0x43')]['id']]['busy']=![];_0x309c8f[_0x005b('0x44')][_0x5699d8['agent']['id']]['busyQueue']=undefined;}}if(_0x5699d8['message']&&_0x5699d8['message']['id']){try{var _0x134a46=getId(_0x5699d8[_0x005b('0x12')],_0x5699d8[_0x005b('0x13')]?_0x5699d8[_0x005b('0x13')]['id']:0x0,_0x5699d8['interaction']?_0x5699d8[_0x005b('0x14')]['id']:0x0);if(_0x309c8f[_0x005b('0x39')][_0x134a46]){_0x309c8f['rules'][_0x134a46][_0x005b('0x3e')](_0x005b('0x45'));if(rpc[_0x5699d8[_0x005b('0x12')]+_0x005b('0x46')]){rpc[_0x5699d8[_0x005b('0x12')]+'QueueReport'][_0x005b('0x47')](_0x134a46,{'UserId':_0x5699d8[_0x005b('0x13')][_0x005b('0x48')]})[_0x005b('0x49')](function(_0x19ca85){logger[_0x005b('0x37')]('error\x20update\x20queue\x20report');});}}return _0x30947e({'code':0xc8,'message':_0x5699d8});}catch(_0x44fee3){logger[_0x005b('0x37')](_0x44fee3[_0x005b('0x41')]);return _0x34fabc(_0x1fed84[_0x005b('0x37')](0x1f4,_0x44fee3));}}logger[_0x005b('0x37')](_0x005b('0x4a'));return _0x34fabc(_0x1fed84['error'](0x1f4,_0x005b('0x4a')));});},'RejectMessage':function(_0x13a680){var _0x5cea23=this;return new Promise(function(_0x5bbc78,_0x22bf46){if(_0x13a680[_0x005b('0x43')]&&_0x13a680[_0x005b('0x43')]['id']){try{if(_0x309c8f[_0x005b('0x44')][_0x13a680[_0x005b('0x43')]['id']]){_0x309c8f[_0x005b('0x44')][_0x13a680[_0x005b('0x43')]['id']]['busy']=![];_0x309c8f[_0x005b('0x44')][_0x13a680['agent']['id']]['busyQueue']=undefined;}return _0x5bbc78({'code':0xc8,'message':_0x13a680});}catch(_0x35d9df){logger[_0x005b('0x37')](_0x35d9df[_0x005b('0x41')]);return _0x22bf46(_0x5cea23['error'](0x1f4,_0x35d9df));}}logger[_0x005b('0x37')](_0x005b('0x4a'));return _0x22bf46(_0x5cea23[_0x005b('0x37')](0x1f4,'message\x20is\x20empty'));});},'AbandonInteraction':function(_0x17018b){var _0x4f4130=this;return new Promise(function(_0x41f077,_0x20540a){if(_0x17018b['channel']&&_0x17018b[_0x005b('0x14')]&&_0x17018b[_0x005b('0x14')]['id']){try{var _0x2a4559=getId(_0x17018b[_0x005b('0x12')],_0x17018b[_0x005b('0x13')]?_0x17018b[_0x005b('0x13')]['id']:0x0,_0x17018b['interaction']?_0x17018b[_0x005b('0x14')]['id']:0x0);if(_0x309c8f[_0x005b('0x39')][_0x2a4559]){_0x309c8f[_0x005b('0x39')][_0x2a4559][_0x005b('0x3e')](_0x005b('0x45'));}return _0x41f077({'code':0xc8,'message':_0x17018b});}catch(_0x630c8){logger['error'](_0x630c8[_0x005b('0x41')]);return _0x20540a(_0x4f4130['error'](0x1f4,_0x630c8));}}logger[_0x005b('0x37')](_0x005b('0x4a'));return _0x20540a(_0x4f4130[_0x005b('0x37')](0x1f4,_0x005b('0x4a')));});},'AgentCapacity':function(_0x31e6f5){var _0x2ee675=this;return new Promise(function(_0x31355d,_0x45f561){if(_0x309c8f[_0x005b('0x44')][_0x005b('0x4b')](_0x31e6f5['id'])){for(var _0x20a986 in _0x31e6f5[_0x005b('0x4c')]){if(_0x31e6f5[_0x005b('0x4c')][_0x005b('0x4b')](_0x20a986)){if(_0x309c8f[_0x005b('0x44')][_0x31e6f5['id']]['hasOwnProperty'](_0x20a986+_0x005b('0x4d'))){_0x309c8f[_0x005b('0x44')][_0x31e6f5['id']][_0x20a986+_0x005b('0x4d')]=parseInt(_0x31e6f5[_0x005b('0x4c')][_0x20a986],0xa);}}}_0x309c8f[_0x005b('0x44')][_0x31e6f5['id']][_0x005b('0x4e')]();return _0x31355d({'code':0xc8,'message':_0x309c8f[_0x005b('0x44')][_0x31e6f5['id']]});}else{return _0x45f561(_0x2ee675['error'](0x1f4,_0x005b('0x4f')));}});},'Agents':function(_0x4a5ae5){return new Promise(function(_0x379b37,_0x4bd368){var _0x21d474=_[_0x005b('0x50')](_0x309c8f['agents']);_0x379b37({'count':_0x21d474[_0x005b('0x17')],'rows':_0x21d474});});},'ChatQueues':function(_0x275094){return new Promise(function(_0x10d9d2,_0x2b7f3e){var _0x2d3aeb=[];for(var _0x6fc481 in _0x309c8f[_0x005b('0x51')]){if(_0x309c8f[_0x005b('0x51')][_0x005b('0x4b')](_0x6fc481)){var _0x4262d9=_0x309c8f['chatQueues'][_0x6fc481];var _0x56209a={'id':_0x4262d9['id'],'available':_0x4262d9[_0x005b('0x52')],'loggedIn':_0x4262d9[_0x005b('0x53')],'name':_0x4262d9[_0x005b('0x54')],'paused':_0x4262d9[_0x005b('0x55')],'waiting':_0x4262d9[_0x005b('0x56')]};_0x2d3aeb[_0x005b('0x20')](_0x56209a);}}_0x10d9d2({'count':_0x2d3aeb[_0x005b('0x17')],'rows':_0x2d3aeb});});},'MailQueues':function(_0x28f177){return new Promise(function(_0x396db4,_0x34069e){var _0x3f0853=[];for(var _0x42ce59 in _0x309c8f[_0x005b('0x57')]){if(_0x309c8f['mailQueues'][_0x005b('0x4b')](_0x42ce59)){var _0x453e64=_0x309c8f['mailQueues'][_0x42ce59];var _0xaca777={'id':_0x453e64['id'],'available':_0x453e64[_0x005b('0x52')],'loggedIn':_0x453e64[_0x005b('0x53')],'name':_0x453e64[_0x005b('0x54')],'paused':_0x453e64[_0x005b('0x55')],'waiting':_0x453e64[_0x005b('0x56')]};_0x3f0853[_0x005b('0x20')](_0xaca777);}}_0x396db4({'count':_0x3f0853[_0x005b('0x17')],'rows':_0x3f0853});});},'OpenchannelQueues':function(_0x2c4280){return new Promise(function(_0x5a6146,_0x46cd37){var _0x30e985=[];for(var _0x7a2336 in _0x309c8f[_0x005b('0x58')]){if(_0x309c8f[_0x005b('0x58')][_0x005b('0x4b')](_0x7a2336)){var _0x11c502=_0x309c8f[_0x005b('0x58')][_0x7a2336];var _0x21c970={'id':_0x11c502['id'],'available':_0x11c502[_0x005b('0x52')],'loggedIn':_0x11c502[_0x005b('0x53')],'name':_0x11c502[_0x005b('0x54')],'paused':_0x11c502[_0x005b('0x55')],'waiting':_0x11c502['waiting']};_0x30e985[_0x005b('0x20')](_0x21c970);}}_0x5a6146({'count':_0x30e985['length'],'rows':_0x30e985});});},'SmsQueues':function(_0xcf64fb){return new Promise(function(_0x511691,_0x38dba1){var _0x369819=[];for(var _0x38ff2b in _0x309c8f[_0x005b('0x59')]){if(_0x309c8f[_0x005b('0x59')][_0x005b('0x4b')](_0x38ff2b)){var _0x426340=_0x309c8f['smsQueues'][_0x38ff2b];var _0x4d1908={'id':_0x426340['id'],'available':_0x426340[_0x005b('0x52')],'loggedIn':_0x426340[_0x005b('0x53')],'name':_0x426340['name'],'paused':_0x426340[_0x005b('0x55')],'waiting':_0x426340[_0x005b('0x56')]};_0x369819['push'](_0x4d1908);}}_0x511691({'count':_0x369819[_0x005b('0x17')],'rows':_0x369819});});},'FaxQueues':function(_0x570c86){return new Promise(function(_0x46e257,_0x5496bf){var _0x16a3d8=[];for(var _0x1c38a4 in _0x309c8f['faxQueues']){if(_0x309c8f[_0x005b('0x5a')][_0x005b('0x4b')](_0x1c38a4)){var _0x1cd0b6=_0x309c8f[_0x005b('0x5a')][_0x1c38a4];var _0x1b3d90={'id':_0x1cd0b6['id'],'available':_0x1cd0b6[_0x005b('0x52')],'loggedIn':_0x1cd0b6[_0x005b('0x53')],'name':_0x1cd0b6['name'],'paused':_0x1cd0b6[_0x005b('0x55')],'waiting':_0x1cd0b6[_0x005b('0x56')]};_0x16a3d8[_0x005b('0x20')](_0x1b3d90);}}_0x46e257({'count':_0x16a3d8[_0x005b('0x17')],'rows':_0x16a3d8});});},'WhatsappQueues':function(_0x264d3a){return new Promise(function(_0x314ac6,_0x34ac7b){var _0x3fe0e3=[];for(var _0x4294b3 in _0x309c8f[_0x005b('0x5b')]){if(_0x309c8f[_0x005b('0x5b')][_0x005b('0x4b')](_0x4294b3)){var _0x372369=_0x309c8f[_0x005b('0x5b')][_0x4294b3];var _0x4e43f2={'id':_0x372369['id'],'available':_0x372369['available'],'loggedIn':_0x372369[_0x005b('0x53')],'name':_0x372369[_0x005b('0x54')],'paused':_0x372369['paused'],'waiting':_0x372369['waiting']};_0x3fe0e3[_0x005b('0x20')](_0x4e43f2);}}_0x314ac6({'count':_0x3fe0e3[_0x005b('0x17')],'rows':_0x3fe0e3});});},'ChatQueuesWaitingInteractions':function(_0x4291be){return new Promise(function(_0x65807b,_0x32b9bd){var _0x19addd=_[_0x005b('0x50')](_0x309c8f[_0x005b('0x5c')]);_0x65807b({'count':_0x19addd[_0x005b('0x17')],'rows':_0x19addd});});},'MailQueuesWaitingInteractions':function(_0x456e44){return new Promise(function(_0x59d464,_0x11a6ab){var _0x4a2e7a=_[_0x005b('0x50')](_0x309c8f[_0x005b('0x5d')]);_0x59d464({'count':_0x4a2e7a[_0x005b('0x17')],'rows':_0x4a2e7a});});},'OpenchannelQueuesWaitingInteractions':function(_0x581b79){return new Promise(function(_0x3aa379,_0x1921a5){var _0x2696fb=_[_0x005b('0x50')](_0x309c8f[_0x005b('0x5e')]);_0x3aa379({'count':_0x2696fb[_0x005b('0x17')],'rows':_0x2696fb});});},'SmsQueuesWaitingInteractions':function(_0x44dd54){return new Promise(function(_0x54a58b,_0x118e8f){var _0x4b5bf6=_[_0x005b('0x50')](_0x309c8f[_0x005b('0x5f')]);_0x54a58b({'count':_0x4b5bf6['length'],'rows':_0x4b5bf6});});},'FaxQueuesWaitingInteractions':function(_0x2de5b6){return new Promise(function(_0x103ef4,_0x1e9683){var _0x1a2efb=_[_0x005b('0x50')](_0x309c8f[_0x005b('0x60')]);_0x103ef4({'count':_0x1a2efb[_0x005b('0x17')],'rows':_0x1a2efb});});},'WhatsappQueuesWaitingInteractions':function(_0x2107cb){return new Promise(function(_0x14d189,_0xa30ed2){var _0x360b08=_[_0x005b('0x50')](_0x309c8f['whatsappQueuesWaitingInteractions']);_0x14d189({'count':_0x360b08[_0x005b('0x17')],'rows':_0x360b08});});}};var _0x3ab540=jayson[_0x005b('0x61')](_0x1c8eed)[_0x005b('0x62')]();_0x3ab540['on'](_0x005b('0x37'),function(_0x44bc20){logger[_0x005b('0x37')](JSON[_0x005b('0x3c')](_0x44bc20));return _0x52f822(_0x44bc20);});_0x3ab540[_0x005b('0x63')](0x232c,_0x005b('0x64'),function(){console[_0x005b('0x65')](_0x005b('0x66'),0x232c);return _0x3e2c82(_0x005b('0x67')+0x232c);});});};
\ No newline at end of file