Built motion from commit 9d1906d1.|2.5.40
[motion2.git] / server / services / routing / server / index.js
index dfd3067..c99e9ef 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfb11=['dialogflowv2','amazonlex','tag','format','%s:%s:%s','./interval','condition','intervals','./applications/','consequence','Push\x20new\x20rule','on\x20interval','\x20|\x20','error','Please\x20create\x20a\x20new\x20file\x20under','execute','info','Applications\x20executed','stringify','matchPath','complete','No\x20applications\x20to\x20execute','stack','routing\x20is\x20empty','emit','end','QueueReport','update','UserId','catch','message\x20is\x20empty','agent','agents','busy','busyQueue','hasOwnProperty','capacity','CurrentCapacity','updateRealtime','agent\x20not\x20found','values','chatQueues','loggedIn','name','paused','waiting','mailQueues','available','openchannelQueues','smsQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','http','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','lodash','path','bluebird','uuid','../../../config/environment','routing','../rpc/openchannelQueueReport','../rpc/chatQueueReport','../rpc/smsQueueReport','../rpc/faxQueueReport','../rpc/whatsappQueueReport','../lib/rule-engine','%s.%s.%s','isNil','IntervalId','Intervals','map','interval','rules','channel','message','interaction','isArray','applications','length','existsSync','app','.js','toLowerCase','autoreply','appdata','push','slice','join','dialogflow','split'];(function(_0x3e17e0,_0x48de7b){var _0x3239f9=function(_0x459f0){while(--_0x459f0){_0x3e17e0['push'](_0x3e17e0['shift']());}};_0x3239f9(++_0x48de7b);}(_0xfb11,0x160));var _0x1fb1=function(_0x220dbb,_0x99328d){_0x220dbb=_0x220dbb-0x0;var _0x2b77de=_0xfb11[_0x220dbb];return _0x2b77de;};'use strict';var _=require(_0x1fb1('0x0'));var util=require('util');var path=require(_0x1fb1('0x1'));var fs=require('fs');var jayson=require('jayson/promise');var BPromise=require(_0x1fb1('0x2'));var uuid=require(_0x1fb1('0x3'));var config=require(_0x1fb1('0x4'));var logger=require('../../../config/logger')(_0x1fb1('0x5'));var rpc={'openchannelQueueReport':require(_0x1fb1('0x6')),'mailQueueReport':require('../rpc/mailQueueReport'),'chatQueueReport':require(_0x1fb1('0x7')),'smsQueueReport':require(_0x1fb1('0x8')),'faxQueueReport':require(_0x1fb1('0x9')),'whatsappQueueReport':require(_0x1fb1('0xa'))};var RuleEngine=require(_0x1fb1('0xb'));function getId(_0x5d794b,_0xc075c9,_0x15f0de){return util['format'](_0x1fb1('0xc'),_0x5d794b,_0xc075c9||0x0,_0x15f0de||0x0);}function getIntervals(_0x58c2e0,_0x162287){var _0x46ad93=[];if(!_[_0x1fb1('0xd')](_0x162287[_0x1fb1('0xe')])&&!_['isNil'](_0x58c2e0[_0x162287[_0x1fb1('0xe')]])&&!_[_0x1fb1('0xd')](_0x58c2e0[_0x162287['IntervalId']][_0x1fb1('0xf')])){_0x46ad93=_[_0x1fb1('0x10')](_0x58c2e0[_0x162287[_0x1fb1('0xe')]][_0x1fb1('0xf')],_0x1fb1('0x11'));}else if(!_[_0x1fb1('0xd')](_0x162287[_0x1fb1('0x11')])){_0x46ad93=[_0x162287[_0x1fb1('0x11')]];}return _0x46ad93;}exports['listen']=function(_0x558b86){_0x558b86[_0x1fb1('0x12')]={};return new BPromise(function(_0x58996c,_0x37d143){var _0x130e45={'Start':function(_0x5b8740){var _0x5e7cd9=this;return new Promise(function(_0x111a00,_0x210195){if(_0x5b8740){try{var _0x1e9dcb=[];var _0x1e954e=getId(_0x5b8740[_0x1fb1('0x13')],_0x5b8740[_0x1fb1('0x14')]?_0x5b8740['message']['id']:0x0,_0x5b8740['interaction']?_0x5b8740[_0x1fb1('0x15')]['id']:0x0);if(_0x5b8740['applications']&&_[_0x1fb1('0x16')](_0x5b8740[_0x1fb1('0x17')])&&_0x5b8740[_0x1fb1('0x17')][_0x1fb1('0x18')]){for(var _0x13b125=0x0;_0x13b125<_0x5b8740[_0x1fb1('0x17')][_0x1fb1('0x18')];_0x13b125+=0x1){var _0x132014=_0x5b8740[_0x1fb1('0x17')][_0x13b125];if(fs[_0x1fb1('0x19')](path['join'](__dirname,_0x1fb1('0x17'),_0x132014[_0x1fb1('0x1a')]+_0x1fb1('0x1b')))){var _0x3eea53=[];switch(_0x132014[_0x1fb1('0x1a')][_0x1fb1('0x1c')]()){case _0x1fb1('0x1d'):var _0x41c81f=_0x132014[_0x1fb1('0x1e')]['split'](',');_0x3eea53['push'](_0x41c81f[0x0]);_0x3eea53[_0x1fb1('0x1f')](_0x41c81f[_0x1fb1('0x20')](0x1,_0x41c81f[_0x1fb1('0x18')])[_0x1fb1('0x21')](','));break;case _0x1fb1('0x22'):var _0x2bc84e=_0x132014['appdata'][_0x1fb1('0x23')](',');_0x3eea53[_0x1fb1('0x1f')](_0x2bc84e[0x0]);_0x3eea53[_0x1fb1('0x1f')](_0x2bc84e[0x1]);_0x3eea53[_0x1fb1('0x1f')](_0x2bc84e['slice'](0x2,_0x2bc84e[_0x1fb1('0x18')])[_0x1fb1('0x21')](','));break;case _0x1fb1('0x24'):var _0x509532=_0x132014['appdata'][_0x1fb1('0x23')](',');_0x3eea53['push'](_0x509532[0x0]);_0x3eea53[_0x1fb1('0x1f')](_0x509532[0x1]);_0x3eea53[_0x1fb1('0x1f')](_0x509532[0x2]);_0x3eea53[_0x1fb1('0x1f')](_0x509532[0x3]);_0x3eea53[_0x1fb1('0x1f')](_0x509532['slice'](0x4,_0x509532[_0x1fb1('0x18')])['join'](','));break;case _0x1fb1('0x25'):var _0x5477b1=_0x132014['appdata'][_0x1fb1('0x23')](',');_0x3eea53[_0x1fb1('0x1f')](_0x5477b1[0x0]);_0x3eea53[_0x1fb1('0x1f')](_0x5477b1[0x1]);_0x3eea53[_0x1fb1('0x1f')](_0x5477b1[0x2]);_0x3eea53['push'](_0x5477b1[0x3]);_0x3eea53['push'](_0x5477b1[_0x1fb1('0x20')](0x4,_0x5477b1[_0x1fb1('0x18')])[_0x1fb1('0x21')](','));break;case'message':_0x3eea53[_0x1fb1('0x1f')](_0x132014[_0x1fb1('0x1e')]);break;case _0x1fb1('0x26'):_0x3eea53[_0x1fb1('0x1f')](_0x132014['TagId']);_0x3eea53[_0x1fb1('0x1f')](_0x132014[_0x1fb1('0x1e')]);break;default:_0x3eea53=_[_0x1fb1('0xd')](_0x132014[_0x1fb1('0x1e')])?[]:_0x132014[_0x1fb1('0x1e')]['split'](',');}var _0x5982c0={'id':util[_0x1fb1('0x27')](_0x1fb1('0x28'),_0x1e954e,_0x132014['id'],_0x132014['app']),'condition':require(_0x1fb1('0x29'))[_0x1fb1('0x2a')](_0x1e954e,getIntervals(_0x558b86[_0x1fb1('0x2b')],_0x132014),_0x558b86),'consequence':require(_0x1fb1('0x2c')+_0x132014[_0x1fb1('0x1a')])[_0x1fb1('0x2d')](_0x1e954e,_0x3eea53,_0x558b86,_0x5b8740),'p':_0x132014['priority']||0x0};logger['info'](_0x1fb1('0x2e'),_0x5982c0['id'],_0x1fb1('0x2f'),getIntervals(_0x558b86[_0x1fb1('0x2b')],_0x132014)['join'](_0x1fb1('0x30')));_0x1e9dcb[_0x1fb1('0x1f')](_0x5982c0);}else{logger[_0x1fb1('0x31')](_0x1fb1('0x32'),path['join'](__dirname,_0x1fb1('0x17'),_0x132014[_0x1fb1('0x1a')]+'.js'));}}_0x558b86[_0x1fb1('0x12')][_0x1e954e]=new RuleEngine(_0x1e9dcb);_0x558b86[_0x1fb1('0x12')][_0x1e954e][_0x1fb1('0x33')](_0x5b8740,function(_0x339211){logger[_0x1fb1('0x34')](_0x1fb1('0x35'),JSON[_0x1fb1('0x36')](_0x339211[_0x1fb1('0x37')]));if(_0x558b86['rules'][_0x1e954e]){_0x558b86[_0x1fb1('0x12')][_0x1e954e]['emit'](_0x1fb1('0x38'));}});return _0x111a00({'code':0xc8,'message':_0x5b8740});}else{logger[_0x1fb1('0x34')](_0x1fb1('0x39'));return _0x111a00({'code':0xc8,'message':_0x5b8740});}}catch(_0x4d5df2){logger['error'](_0x4d5df2[_0x1fb1('0x3a')]);return _0x210195(_0x5e7cd9[_0x1fb1('0x31')](0x1f4,_0x4d5df2));}}return _0x210195(_0x1fb1('0x3b'));});},'AcceptMessage':function(_0x1f6d41){var _0x4dc2ad=this;return new Promise(function(_0x39d701,_0x3693d8){if(_0x1f6d41[_0x1fb1('0x14')]&&_0x1f6d41[_0x1fb1('0x14')]['id']){try{var _0x130de0=getId(_0x1f6d41[_0x1fb1('0x13')],_0x1f6d41['message']?_0x1f6d41[_0x1fb1('0x14')]['id']:0x0,_0x1f6d41[_0x1fb1('0x15')]?_0x1f6d41[_0x1fb1('0x15')]['id']:0x0);if(_0x558b86[_0x1fb1('0x12')][_0x130de0]){_0x558b86[_0x1fb1('0x12')][_0x130de0][_0x1fb1('0x3c')](_0x1fb1('0x3d'));if(rpc[_0x1f6d41[_0x1fb1('0x13')]+_0x1fb1('0x3e')]){rpc[_0x1f6d41[_0x1fb1('0x13')]+_0x1fb1('0x3e')][_0x1fb1('0x3f')](_0x130de0,{'UserId':_0x1f6d41[_0x1fb1('0x14')][_0x1fb1('0x40')]})[_0x1fb1('0x41')](function(_0x55c305){logger[_0x1fb1('0x31')]('error\x20update\x20queue\x20report');});}}return _0x39d701({'code':0xc8,'message':_0x1f6d41});}catch(_0x818023){logger[_0x1fb1('0x31')](_0x818023['stack']);return _0x3693d8(_0x4dc2ad[_0x1fb1('0x31')](0x1f4,_0x818023));}}logger[_0x1fb1('0x31')](_0x1fb1('0x42'));return _0x3693d8(_0x4dc2ad['error'](0x1f4,_0x1fb1('0x42')));});},'RejectMessage':function(_0x539f13){var _0xa7454b=this;return new Promise(function(_0x6142a5,_0x2a5d18){if(_0x539f13[_0x1fb1('0x43')]&&_0x539f13[_0x1fb1('0x43')]['id']){try{if(_0x558b86[_0x1fb1('0x44')][_0x539f13['agent']['id']]){_0x558b86[_0x1fb1('0x44')][_0x539f13[_0x1fb1('0x43')]['id']][_0x1fb1('0x45')]=![];_0x558b86['agents'][_0x539f13['agent']['id']][_0x1fb1('0x46')]=undefined;}return _0x6142a5({'code':0xc8,'message':_0x539f13});}catch(_0x3e4d53){logger[_0x1fb1('0x31')](_0x3e4d53['stack']);return _0x2a5d18(_0xa7454b[_0x1fb1('0x31')](0x1f4,_0x3e4d53));}}logger[_0x1fb1('0x31')](_0x1fb1('0x42'));return _0x2a5d18(_0xa7454b[_0x1fb1('0x31')](0x1f4,_0x1fb1('0x42')));});},'AbandonInteraction':function(_0x5396d9){var _0x41f61c=this;return new Promise(function(_0x38891e,_0x18e48e){if(_0x5396d9[_0x1fb1('0x13')]&&_0x5396d9[_0x1fb1('0x15')]&&_0x5396d9[_0x1fb1('0x15')]['id']){try{var _0x11c801=getId(_0x5396d9[_0x1fb1('0x13')],_0x5396d9[_0x1fb1('0x14')]?_0x5396d9[_0x1fb1('0x14')]['id']:0x0,_0x5396d9['interaction']?_0x5396d9[_0x1fb1('0x15')]['id']:0x0);if(_0x558b86[_0x1fb1('0x12')][_0x11c801]){_0x558b86[_0x1fb1('0x12')][_0x11c801][_0x1fb1('0x3c')](_0x1fb1('0x3d'));}return _0x38891e({'code':0xc8,'message':_0x5396d9});}catch(_0x223ef4){logger[_0x1fb1('0x31')](_0x223ef4[_0x1fb1('0x3a')]);return _0x18e48e(_0x41f61c['error'](0x1f4,_0x223ef4));}}logger[_0x1fb1('0x31')](_0x1fb1('0x42'));return _0x18e48e(_0x41f61c[_0x1fb1('0x31')](0x1f4,_0x1fb1('0x42')));});},'AgentCapacity':function(_0x3db8f8){var _0x1112c1=this;return new Promise(function(_0x30e55e,_0x4663c4){if(_0x558b86[_0x1fb1('0x44')][_0x1fb1('0x47')](_0x3db8f8['id'])){for(var _0x470716 in _0x3db8f8[_0x1fb1('0x48')]){if(_0x3db8f8['capacity'][_0x1fb1('0x47')](_0x470716)){if(_0x558b86['agents'][_0x3db8f8['id']][_0x1fb1('0x47')](_0x470716+'CurrentCapacity')){_0x558b86[_0x1fb1('0x44')][_0x3db8f8['id']][_0x470716+_0x1fb1('0x49')]=parseInt(_0x3db8f8[_0x1fb1('0x48')][_0x470716],0xa);}}}_0x558b86[_0x1fb1('0x44')][_0x3db8f8['id']][_0x1fb1('0x4a')]();return _0x30e55e({'code':0xc8,'message':_0x558b86['agents'][_0x3db8f8['id']]});}else{return _0x4663c4(_0x1112c1['error'](0x1f4,_0x1fb1('0x4b')));}});},'Agents':function(_0x325b76){return new Promise(function(_0xdeebba,_0x1da46a){var _0x5eb7d7=_[_0x1fb1('0x4c')](_0x558b86[_0x1fb1('0x44')]);_0xdeebba({'count':_0x5eb7d7[_0x1fb1('0x18')],'rows':_0x5eb7d7});});},'ChatQueues':function(_0x43b64c){return new Promise(function(_0x312328,_0x32f19b){var _0x3d5d26=[];for(var _0x40f0e7 in _0x558b86[_0x1fb1('0x4d')]){if(_0x558b86[_0x1fb1('0x4d')]['hasOwnProperty'](_0x40f0e7)){var _0x479d9c=_0x558b86[_0x1fb1('0x4d')][_0x40f0e7];var _0x298d96={'id':_0x479d9c['id'],'available':_0x479d9c['available'],'loggedIn':_0x479d9c[_0x1fb1('0x4e')],'name':_0x479d9c[_0x1fb1('0x4f')],'paused':_0x479d9c[_0x1fb1('0x50')],'waiting':_0x479d9c[_0x1fb1('0x51')]};_0x3d5d26['push'](_0x298d96);}}_0x312328({'count':_0x3d5d26[_0x1fb1('0x18')],'rows':_0x3d5d26});});},'MailQueues':function(_0x50a061){return new Promise(function(_0x3fa206,_0x20aed1){var _0x31393c=[];for(var _0x9f8330 in _0x558b86[_0x1fb1('0x52')]){if(_0x558b86['mailQueues']['hasOwnProperty'](_0x9f8330)){var _0x3bd6f3=_0x558b86[_0x1fb1('0x52')][_0x9f8330];var _0x22dafa={'id':_0x3bd6f3['id'],'available':_0x3bd6f3[_0x1fb1('0x53')],'loggedIn':_0x3bd6f3['loggedIn'],'name':_0x3bd6f3[_0x1fb1('0x4f')],'paused':_0x3bd6f3[_0x1fb1('0x50')],'waiting':_0x3bd6f3[_0x1fb1('0x51')]};_0x31393c[_0x1fb1('0x1f')](_0x22dafa);}}_0x3fa206({'count':_0x31393c[_0x1fb1('0x18')],'rows':_0x31393c});});},'OpenchannelQueues':function(_0x336e39){return new Promise(function(_0x6be349,_0x508bf){var _0x55d07e=[];for(var _0x8d4f7a in _0x558b86[_0x1fb1('0x54')]){if(_0x558b86[_0x1fb1('0x54')][_0x1fb1('0x47')](_0x8d4f7a)){var _0x4a4708=_0x558b86[_0x1fb1('0x54')][_0x8d4f7a];var _0x584f13={'id':_0x4a4708['id'],'available':_0x4a4708[_0x1fb1('0x53')],'loggedIn':_0x4a4708[_0x1fb1('0x4e')],'name':_0x4a4708[_0x1fb1('0x4f')],'paused':_0x4a4708['paused'],'waiting':_0x4a4708[_0x1fb1('0x51')]};_0x55d07e[_0x1fb1('0x1f')](_0x584f13);}}_0x6be349({'count':_0x55d07e[_0x1fb1('0x18')],'rows':_0x55d07e});});},'SmsQueues':function(_0x422898){return new Promise(function(_0x249c82,_0x4aa711){var _0x752b22=[];for(var _0x491fb9 in _0x558b86[_0x1fb1('0x55')]){if(_0x558b86[_0x1fb1('0x55')]['hasOwnProperty'](_0x491fb9)){var _0x207414=_0x558b86[_0x1fb1('0x55')][_0x491fb9];var _0x28a0f6={'id':_0x207414['id'],'available':_0x207414[_0x1fb1('0x53')],'loggedIn':_0x207414[_0x1fb1('0x4e')],'name':_0x207414[_0x1fb1('0x4f')],'paused':_0x207414[_0x1fb1('0x50')],'waiting':_0x207414['waiting']};_0x752b22[_0x1fb1('0x1f')](_0x28a0f6);}}_0x249c82({'count':_0x752b22[_0x1fb1('0x18')],'rows':_0x752b22});});},'FaxQueues':function(_0x53ee18){return new Promise(function(_0x2334f9,_0x2eee69){var _0x3733c5=[];for(var _0x5691a5 in _0x558b86[_0x1fb1('0x56')]){if(_0x558b86[_0x1fb1('0x56')][_0x1fb1('0x47')](_0x5691a5)){var _0x3e69f2=_0x558b86['faxQueues'][_0x5691a5];var _0x3cd518={'id':_0x3e69f2['id'],'available':_0x3e69f2[_0x1fb1('0x53')],'loggedIn':_0x3e69f2[_0x1fb1('0x4e')],'name':_0x3e69f2[_0x1fb1('0x4f')],'paused':_0x3e69f2['paused'],'waiting':_0x3e69f2[_0x1fb1('0x51')]};_0x3733c5[_0x1fb1('0x1f')](_0x3cd518);}}_0x2334f9({'count':_0x3733c5[_0x1fb1('0x18')],'rows':_0x3733c5});});},'WhatsappQueues':function(_0x1b88cc){return new Promise(function(_0x7f23da,_0xb43f85){var _0x4135da=[];for(var _0x4e181d in _0x558b86[_0x1fb1('0x57')]){if(_0x558b86['whatsappQueues']['hasOwnProperty'](_0x4e181d)){var _0xfdc85=_0x558b86[_0x1fb1('0x57')][_0x4e181d];var _0x5403ff={'id':_0xfdc85['id'],'available':_0xfdc85[_0x1fb1('0x53')],'loggedIn':_0xfdc85[_0x1fb1('0x4e')],'name':_0xfdc85['name'],'paused':_0xfdc85[_0x1fb1('0x50')],'waiting':_0xfdc85[_0x1fb1('0x51')]};_0x4135da[_0x1fb1('0x1f')](_0x5403ff);}}_0x7f23da({'count':_0x4135da['length'],'rows':_0x4135da});});},'ChatQueuesWaitingInteractions':function(_0x2d9c84){return new Promise(function(_0x3cb29d,_0x5d8a51){var _0x3aa541=_[_0x1fb1('0x4c')](_0x558b86[_0x1fb1('0x58')]);_0x3cb29d({'count':_0x3aa541[_0x1fb1('0x18')],'rows':_0x3aa541});});},'MailQueuesWaitingInteractions':function(_0x3ea942){return new Promise(function(_0x1a55a5,_0x194947){var _0x54e91a=_[_0x1fb1('0x4c')](_0x558b86['mailQueuesWaitingInteractions']);_0x1a55a5({'count':_0x54e91a['length'],'rows':_0x54e91a});});},'OpenchannelQueuesWaitingInteractions':function(_0x16cefb){return new Promise(function(_0x2ad9fd,_0x2ef6d3){var _0x4d0465=_['values'](_0x558b86[_0x1fb1('0x59')]);_0x2ad9fd({'count':_0x4d0465[_0x1fb1('0x18')],'rows':_0x4d0465});});},'SmsQueuesWaitingInteractions':function(_0x155693){return new Promise(function(_0x3dfe0e,_0x48f8f8){var _0xe6fb64=_['values'](_0x558b86[_0x1fb1('0x5a')]);_0x3dfe0e({'count':_0xe6fb64['length'],'rows':_0xe6fb64});});},'FaxQueuesWaitingInteractions':function(_0x62b9af){return new Promise(function(_0x43eaba,_0x596d09){var _0x77ac58=_[_0x1fb1('0x4c')](_0x558b86[_0x1fb1('0x5b')]);_0x43eaba({'count':_0x77ac58[_0x1fb1('0x18')],'rows':_0x77ac58});});},'WhatsappQueuesWaitingInteractions':function(_0x3e2b13){return new Promise(function(_0x2ca027,_0x99dcf6){var _0x348828=_[_0x1fb1('0x4c')](_0x558b86[_0x1fb1('0x5c')]);_0x2ca027({'count':_0x348828[_0x1fb1('0x18')],'rows':_0x348828});});}};var _0x1504c7=jayson['server'](_0x130e45)[_0x1fb1('0x5d')]();_0x1504c7['on']('error',function(_0x4bb437){logger[_0x1fb1('0x31')](JSON[_0x1fb1('0x36')](_0x4bb437));return _0x37d143(_0x4bb437);});_0x1504c7['listen'](0x232c,'127.0.0.1',function(){console[_0x1fb1('0x5e')](_0x1fb1('0x5f'),0x232c);return _0x58996c(_0x1fb1('0x60')+0x232c);});});};
\ No newline at end of file
+var _0x8164=['rules','channel','message','applications','isArray','length','existsSync','app','.js','autoreply','mail','push','slice','join','dialogflow','split','dialogflowv2','appdata','amazonlex','tag','TagId','getMustacheRender','account','notificationTemplate','ChatWebsiteId','interaction','ContactId','body','%s:%s:%s','./interval','condition','intervals','./applications/','consequence','priority','Push\x20new\x20rule','\x20|\x20','error','Please\x20create\x20a\x20new\x20file\x20under','execute','Applications\x20executed','emit','complete','info','No\x20applications\x20to\x20execute','stack','routing\x20is\x20empty','agent','agents','busyQueue','end','QueueReport','update','UserId','catch','error\x20update\x20queue\x20report','message\x20is\x20empty','busy','hasOwnProperty','CurrentCapacity','capacity','updateRealtime','values','chatQueues','available','loggedIn','name','paused','mailQueues','openchannelQueues','waiting','smsQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','server','stringify','log','lodash','util','path','bluebird','uuid','../../../config/environment','routing','../rpc/chatQueueReport','../rpc/whatsappQueueReport','../lib/rule-engine','format','%s.%s.%s','isNil','IntervalId','interval','listen'];(function(_0x4bc65f,_0x39ec43){var _0x44f85f=function(_0x175343){while(--_0x175343){_0x4bc65f['push'](_0x4bc65f['shift']());}};_0x44f85f(++_0x39ec43);}(_0x8164,0x170));var _0x4816=function(_0x1f88f0,_0x2dc0ac){_0x1f88f0=_0x1f88f0-0x0;var _0x3684f5=_0x8164[_0x1f88f0];return _0x3684f5;};'use strict';var _=require(_0x4816('0x0'));var util=require(_0x4816('0x1'));var path=require(_0x4816('0x2'));var fs=require('fs');var jayson=require('jayson/promise');var BPromise=require(_0x4816('0x3'));var uuid=require(_0x4816('0x4'));var utils=require('./applications/utils');var config=require(_0x4816('0x5'));var logger=require('../../../config/logger')(_0x4816('0x6'));var rpc={'openchannelQueueReport':require('../rpc/openchannelQueueReport'),'mailQueueReport':require('../rpc/mailQueueReport'),'chatQueueReport':require(_0x4816('0x7')),'smsQueueReport':require('../rpc/smsQueueReport'),'faxQueueReport':require('../rpc/faxQueueReport'),'whatsappQueueReport':require(_0x4816('0x8'))};var RuleEngine=require(_0x4816('0x9'));function getId(_0x170e7a,_0x383974,_0x2421e1){return util[_0x4816('0xa')](_0x4816('0xb'),_0x170e7a,_0x383974||0x0,_0x2421e1||0x0);}function getIntervals(_0x1e0118,_0x23d125){var _0x520153=[];if(!_[_0x4816('0xc')](_0x23d125['IntervalId'])&&!_[_0x4816('0xc')](_0x1e0118[_0x23d125[_0x4816('0xd')]])&&!_['isNil'](_0x1e0118[_0x23d125[_0x4816('0xd')]]['Intervals'])){_0x520153=_['map'](_0x1e0118[_0x23d125[_0x4816('0xd')]]['Intervals'],'interval');}else if(!_[_0x4816('0xc')](_0x23d125['interval'])){_0x520153=[_0x23d125[_0x4816('0xe')]];}return _0x520153;}exports[_0x4816('0xf')]=function(_0x13a685){_0x13a685[_0x4816('0x10')]={};return new BPromise(function(_0x42fc52,_0x248163){var _0x1eb683={'Start':function(_0x2a58b7){var _0x45c006=this;return new Promise(function(_0x21354c,_0x1ce1fb){if(_0x2a58b7){try{var _0x4678a9=[];var _0x6119f=getId(_0x2a58b7[_0x4816('0x11')],_0x2a58b7[_0x4816('0x12')]?_0x2a58b7[_0x4816('0x12')]['id']:0x0,_0x2a58b7['interaction']?_0x2a58b7['interaction']['id']:0x0);if(_0x2a58b7[_0x4816('0x13')]&&_[_0x4816('0x14')](_0x2a58b7[_0x4816('0x13')])&&_0x2a58b7[_0x4816('0x13')][_0x4816('0x15')]){for(var _0x37effd=0x0;_0x37effd<_0x2a58b7[_0x4816('0x13')][_0x4816('0x15')];_0x37effd+=0x1){var _0x3df423=_0x2a58b7['applications'][_0x37effd];if(fs[_0x4816('0x16')](path['join'](__dirname,'applications',_0x3df423[_0x4816('0x17')]+_0x4816('0x18')))){var _0x5de184=[];switch(_0x3df423[_0x4816('0x17')]['toLowerCase']()){case _0x4816('0x19'):var _0x41d7f0=_0x3df423['appdata']['split'](',');if(_0x2a58b7[_0x4816('0x11')]===_0x4816('0x1a')){_0x5de184[_0x4816('0x1b')](_0x41d7f0[0x0]);_0x5de184['push'](_0x41d7f0[0x1]);_0x5de184[_0x4816('0x1b')](_0x41d7f0[_0x4816('0x1c')](0x2,_0x41d7f0[_0x4816('0x15')])[_0x4816('0x1d')](','));}else{_0x5de184['push'](_0x41d7f0[0x0]);_0x5de184['push'](_0x41d7f0[_0x4816('0x1c')](0x1,_0x41d7f0[_0x4816('0x15')])['join'](','));}break;case _0x4816('0x1e'):var _0x4f9386=_0x3df423['appdata'][_0x4816('0x1f')](',');_0x5de184[_0x4816('0x1b')](_0x4f9386[0x0]);_0x5de184[_0x4816('0x1b')](_0x4f9386[0x1]);_0x5de184['push'](_0x4f9386[_0x4816('0x1c')](0x2,_0x4f9386['length'])[_0x4816('0x1d')](','));break;case _0x4816('0x20'):var _0x49c337=_0x3df423[_0x4816('0x21')][_0x4816('0x1f')](',');_0x5de184[_0x4816('0x1b')](_0x49c337[0x0]);_0x5de184[_0x4816('0x1b')](_0x49c337[0x1]);_0x5de184[_0x4816('0x1b')](_0x49c337[0x2]);_0x5de184[_0x4816('0x1b')](_0x49c337[0x3]);_0x5de184[_0x4816('0x1b')](_0x49c337[_0x4816('0x1c')](0x4,_0x49c337[_0x4816('0x15')])['join'](','));break;case _0x4816('0x22'):var _0x902962=_0x3df423['appdata']['split'](',');_0x5de184[_0x4816('0x1b')](_0x902962[0x0]);_0x5de184[_0x4816('0x1b')](_0x902962[0x1]);_0x5de184[_0x4816('0x1b')](_0x902962[0x2]);_0x5de184[_0x4816('0x1b')](_0x902962[0x3]);_0x5de184[_0x4816('0x1b')](_0x902962['slice'](0x4,_0x902962['length'])['join'](','));break;case _0x4816('0x12'):_0x5de184[_0x4816('0x1b')](_0x3df423[_0x4816('0x21')]);break;case _0x4816('0x23'):_0x5de184[_0x4816('0x1b')](_0x3df423[_0x4816('0x24')]);_0x5de184['push'](_0x3df423[_0x4816('0x21')]);break;case'tvox':var _0xc92865=utils[_0x4816('0x25')](_0x2a58b7[_0x4816('0x26')][_0x4816('0x27')],_0x2a58b7);var _0x192476=_0x3df423['appdata'][_0x4816('0x1f')](',');_0x5de184['push'](_0x192476[0x0]);_0x5de184['push'](_0x192476[0x1]);_0x5de184[_0x4816('0x1b')](_0x192476[0x2]);_0x5de184['push'](_0x192476[0x3]);_0x5de184['push'](_0x192476[0x4]);_0x5de184['push'](_0x192476[0x5]);_0x5de184['push'](_0x192476[0x6]);_0x5de184[_0x4816('0x1b')](_0x192476[0x7]);_0x5de184[_0x4816('0x1b')](_0x192476[0x8]);_0x5de184['push'](_0x192476[0x9]);_0x5de184[_0x4816('0x1b')](_0x192476[0xa]);_0x5de184[_0x4816('0x1b')](_0x2a58b7['interaction']['id']);_0x5de184[_0x4816('0x1b')](_0x2a58b7[_0x4816('0x12')]['id']);_0x5de184[_0x4816('0x1b')](_0x3df423[_0x4816('0x28')]);_0x5de184['push'](_0x2a58b7[_0x4816('0x29')][_0x4816('0x2a')]);_0x5de184[_0x4816('0x1b')](_0x2a58b7[_0x4816('0x2b')][_0x4816('0x2b')]);_0x5de184[_0x4816('0x1b')](_0xc92865);break;default:_0x5de184=_[_0x4816('0xc')](_0x3df423[_0x4816('0x21')])?[]:_0x3df423[_0x4816('0x21')][_0x4816('0x1f')](',');}var _0xcbded0={'id':util[_0x4816('0xa')](_0x4816('0x2c'),_0x6119f,_0x3df423['id'],_0x3df423['app']),'condition':require(_0x4816('0x2d'))[_0x4816('0x2e')](_0x6119f,getIntervals(_0x13a685[_0x4816('0x2f')],_0x3df423),_0x13a685),'consequence':require(_0x4816('0x30')+_0x3df423[_0x4816('0x17')])[_0x4816('0x31')](_0x6119f,_0x5de184,_0x13a685,_0x2a58b7),'p':_0x3df423[_0x4816('0x32')]||0x0};logger['info'](_0x4816('0x33'),_0xcbded0['id'],'on\x20interval',getIntervals(_0x13a685['intervals'],_0x3df423)[_0x4816('0x1d')](_0x4816('0x34')));_0x4678a9['push'](_0xcbded0);}else{logger[_0x4816('0x35')](_0x4816('0x36'),path[_0x4816('0x1d')](__dirname,'applications',_0x3df423[_0x4816('0x17')]+_0x4816('0x18')));}}_0x13a685[_0x4816('0x10')][_0x6119f]=new RuleEngine(_0x4678a9);_0x13a685[_0x4816('0x10')][_0x6119f][_0x4816('0x37')](_0x2a58b7,function(_0x39c713){logger['info'](_0x4816('0x38'),JSON['stringify'](_0x39c713['matchPath']));if(_0x13a685['rules'][_0x6119f]){_0x13a685[_0x4816('0x10')][_0x6119f][_0x4816('0x39')](_0x4816('0x3a'));}});return _0x21354c({'code':0xc8,'message':_0x2a58b7});}else{logger[_0x4816('0x3b')](_0x4816('0x3c'));return _0x21354c({'code':0xc8,'message':_0x2a58b7});}}catch(_0x22d8d3){logger[_0x4816('0x35')](_0x22d8d3[_0x4816('0x3d')]);return _0x1ce1fb(_0x45c006[_0x4816('0x35')](0x1f4,_0x22d8d3));}}return _0x1ce1fb(_0x4816('0x3e'));});},'AcceptMessage':function(_0x5e24bf){var _0x4ffae3=this;return new Promise(function(_0x258f5f,_0x374d25){if(_0x5e24bf[_0x4816('0x3f')]&&_0x5e24bf[_0x4816('0x3f')]['id']){if(_0x13a685[_0x4816('0x40')][_0x5e24bf[_0x4816('0x3f')]['id']]){_0x13a685[_0x4816('0x40')][_0x5e24bf[_0x4816('0x3f')]['id']]['busy']=![];_0x13a685[_0x4816('0x40')][_0x5e24bf[_0x4816('0x3f')]['id']][_0x4816('0x41')]=undefined;}}if(_0x5e24bf['message']&&_0x5e24bf['message']['id']){try{var _0x2ad19b=getId(_0x5e24bf[_0x4816('0x11')],_0x5e24bf[_0x4816('0x12')]?_0x5e24bf['message']['id']:0x0,_0x5e24bf[_0x4816('0x29')]?_0x5e24bf[_0x4816('0x29')]['id']:0x0);if(_0x13a685[_0x4816('0x10')][_0x2ad19b]){_0x13a685[_0x4816('0x10')][_0x2ad19b][_0x4816('0x39')](_0x4816('0x42'));if(rpc[_0x5e24bf[_0x4816('0x11')]+'QueueReport']){rpc[_0x5e24bf[_0x4816('0x11')]+_0x4816('0x43')][_0x4816('0x44')](_0x2ad19b,{'UserId':_0x5e24bf[_0x4816('0x12')][_0x4816('0x45')]})[_0x4816('0x46')](function(_0x309778){logger[_0x4816('0x35')](_0x4816('0x47'));});}}return _0x258f5f({'code':0xc8,'message':_0x5e24bf});}catch(_0x443d0d){logger[_0x4816('0x35')](_0x443d0d[_0x4816('0x3d')]);return _0x374d25(_0x4ffae3[_0x4816('0x35')](0x1f4,_0x443d0d));}}logger[_0x4816('0x35')](_0x4816('0x48'));return _0x374d25(_0x4ffae3[_0x4816('0x35')](0x1f4,_0x4816('0x48')));});},'RejectMessage':function(_0x11272b){var _0x2e619f=this;return new Promise(function(_0x56321c,_0x1702bf){if(_0x11272b[_0x4816('0x3f')]&&_0x11272b['agent']['id']){try{if(_0x13a685[_0x4816('0x40')][_0x11272b[_0x4816('0x3f')]['id']]){_0x13a685['agents'][_0x11272b[_0x4816('0x3f')]['id']][_0x4816('0x49')]=![];_0x13a685[_0x4816('0x40')][_0x11272b[_0x4816('0x3f')]['id']][_0x4816('0x41')]=undefined;}return _0x56321c({'code':0xc8,'message':_0x11272b});}catch(_0x3f6bf2){logger[_0x4816('0x35')](_0x3f6bf2[_0x4816('0x3d')]);return _0x1702bf(_0x2e619f[_0x4816('0x35')](0x1f4,_0x3f6bf2));}}logger[_0x4816('0x35')]('message\x20is\x20empty');return _0x1702bf(_0x2e619f[_0x4816('0x35')](0x1f4,'message\x20is\x20empty'));});},'AbandonInteraction':function(_0x440ba5){var _0x199363=this;return new Promise(function(_0x57d72e,_0x157ee3){if(_0x440ba5[_0x4816('0x11')]&&_0x440ba5[_0x4816('0x29')]&&_0x440ba5[_0x4816('0x29')]['id']){try{var _0x170c23=getId(_0x440ba5['channel'],_0x440ba5[_0x4816('0x12')]?_0x440ba5[_0x4816('0x12')]['id']:0x0,_0x440ba5[_0x4816('0x29')]?_0x440ba5[_0x4816('0x29')]['id']:0x0);if(_0x13a685[_0x4816('0x10')][_0x170c23]){_0x13a685[_0x4816('0x10')][_0x170c23]['emit'](_0x4816('0x42'));}return _0x57d72e({'code':0xc8,'message':_0x440ba5});}catch(_0x43c287){logger[_0x4816('0x35')](_0x43c287['stack']);return _0x157ee3(_0x199363[_0x4816('0x35')](0x1f4,_0x43c287));}}logger[_0x4816('0x35')](_0x4816('0x48'));return _0x157ee3(_0x199363['error'](0x1f4,_0x4816('0x48')));});},'AgentCapacity':function(_0x1f790b){var _0xa67f45=this;return new Promise(function(_0xfb9e4a,_0x56d223){if(_0x13a685[_0x4816('0x40')][_0x4816('0x4a')](_0x1f790b['id'])){for(var _0x5210d2 in _0x1f790b['capacity']){if(_0x1f790b['capacity'][_0x4816('0x4a')](_0x5210d2)){if(_0x13a685[_0x4816('0x40')][_0x1f790b['id']][_0x4816('0x4a')](_0x5210d2+_0x4816('0x4b'))){_0x13a685[_0x4816('0x40')][_0x1f790b['id']][_0x5210d2+_0x4816('0x4b')]=parseInt(_0x1f790b[_0x4816('0x4c')][_0x5210d2],0xa);}}}_0x13a685['agents'][_0x1f790b['id']][_0x4816('0x4d')]();return _0xfb9e4a({'code':0xc8,'message':_0x13a685[_0x4816('0x40')][_0x1f790b['id']]});}else{return _0x56d223(_0xa67f45[_0x4816('0x35')](0x1f4,'agent\x20not\x20found'));}});},'Agents':function(_0x356878){return new Promise(function(_0x27392e,_0xcc9277){var _0x2c2a8c=_[_0x4816('0x4e')](_0x13a685[_0x4816('0x40')]);_0x27392e({'count':_0x2c2a8c[_0x4816('0x15')],'rows':_0x2c2a8c});});},'ChatQueues':function(_0x52cf85){return new Promise(function(_0x171c2b,_0x11e6f9){var _0x11b12a=[];for(var _0x4a3cf9 in _0x13a685[_0x4816('0x4f')]){if(_0x13a685[_0x4816('0x4f')]['hasOwnProperty'](_0x4a3cf9)){var _0x3a1cf7=_0x13a685[_0x4816('0x4f')][_0x4a3cf9];var _0x211a2b={'id':_0x3a1cf7['id'],'available':_0x3a1cf7[_0x4816('0x50')],'loggedIn':_0x3a1cf7[_0x4816('0x51')],'name':_0x3a1cf7[_0x4816('0x52')],'paused':_0x3a1cf7[_0x4816('0x53')],'waiting':_0x3a1cf7['waiting']};_0x11b12a[_0x4816('0x1b')](_0x211a2b);}}_0x171c2b({'count':_0x11b12a['length'],'rows':_0x11b12a});});},'MailQueues':function(_0x483ad3){return new Promise(function(_0x4f357f,_0x4b3a3c){var _0x553093=[];for(var _0x15649e in _0x13a685[_0x4816('0x54')]){if(_0x13a685[_0x4816('0x54')]['hasOwnProperty'](_0x15649e)){var _0x3d6908=_0x13a685[_0x4816('0x54')][_0x15649e];var _0x115dc8={'id':_0x3d6908['id'],'available':_0x3d6908[_0x4816('0x50')],'loggedIn':_0x3d6908[_0x4816('0x51')],'name':_0x3d6908[_0x4816('0x52')],'paused':_0x3d6908[_0x4816('0x53')],'waiting':_0x3d6908['waiting']};_0x553093[_0x4816('0x1b')](_0x115dc8);}}_0x4f357f({'count':_0x553093['length'],'rows':_0x553093});});},'OpenchannelQueues':function(_0x44c2ec){return new Promise(function(_0x2cbc59,_0x5277dc){var _0x3002b7=[];for(var _0x9165c8 in _0x13a685[_0x4816('0x55')]){if(_0x13a685['openchannelQueues'][_0x4816('0x4a')](_0x9165c8)){var _0xd5d3b0=_0x13a685[_0x4816('0x55')][_0x9165c8];var _0x56b799={'id':_0xd5d3b0['id'],'available':_0xd5d3b0[_0x4816('0x50')],'loggedIn':_0xd5d3b0[_0x4816('0x51')],'name':_0xd5d3b0[_0x4816('0x52')],'paused':_0xd5d3b0['paused'],'waiting':_0xd5d3b0[_0x4816('0x56')]};_0x3002b7[_0x4816('0x1b')](_0x56b799);}}_0x2cbc59({'count':_0x3002b7[_0x4816('0x15')],'rows':_0x3002b7});});},'SmsQueues':function(_0x391329){return new Promise(function(_0x1c7fb4,_0x3d7d8b){var _0x23cfc4=[];for(var _0x5b7156 in _0x13a685[_0x4816('0x57')]){if(_0x13a685[_0x4816('0x57')][_0x4816('0x4a')](_0x5b7156)){var _0x24b0d5=_0x13a685[_0x4816('0x57')][_0x5b7156];var _0x24df14={'id':_0x24b0d5['id'],'available':_0x24b0d5[_0x4816('0x50')],'loggedIn':_0x24b0d5['loggedIn'],'name':_0x24b0d5[_0x4816('0x52')],'paused':_0x24b0d5[_0x4816('0x53')],'waiting':_0x24b0d5[_0x4816('0x56')]};_0x23cfc4[_0x4816('0x1b')](_0x24df14);}}_0x1c7fb4({'count':_0x23cfc4['length'],'rows':_0x23cfc4});});},'FaxQueues':function(_0x1e0bab){return new Promise(function(_0x1af0dc,_0x46f5f4){var _0xbb9848=[];for(var _0x12de01 in _0x13a685[_0x4816('0x58')]){if(_0x13a685[_0x4816('0x58')][_0x4816('0x4a')](_0x12de01)){var _0x28419c=_0x13a685[_0x4816('0x58')][_0x12de01];var _0x436d35={'id':_0x28419c['id'],'available':_0x28419c[_0x4816('0x50')],'loggedIn':_0x28419c[_0x4816('0x51')],'name':_0x28419c['name'],'paused':_0x28419c[_0x4816('0x53')],'waiting':_0x28419c[_0x4816('0x56')]};_0xbb9848[_0x4816('0x1b')](_0x436d35);}}_0x1af0dc({'count':_0xbb9848[_0x4816('0x15')],'rows':_0xbb9848});});},'WhatsappQueues':function(_0x21fe50){return new Promise(function(_0x35093e,_0x12d58f){var _0x619070=[];for(var _0x202d18 in _0x13a685[_0x4816('0x59')]){if(_0x13a685[_0x4816('0x59')][_0x4816('0x4a')](_0x202d18)){var _0xf439b3=_0x13a685['whatsappQueues'][_0x202d18];var _0xf05f49={'id':_0xf439b3['id'],'available':_0xf439b3[_0x4816('0x50')],'loggedIn':_0xf439b3[_0x4816('0x51')],'name':_0xf439b3['name'],'paused':_0xf439b3['paused'],'waiting':_0xf439b3[_0x4816('0x56')]};_0x619070[_0x4816('0x1b')](_0xf05f49);}}_0x35093e({'count':_0x619070['length'],'rows':_0x619070});});},'ChatQueuesWaitingInteractions':function(_0x1e2ead){return new Promise(function(_0x192832,_0x357800){var _0x317f3f=_['values'](_0x13a685[_0x4816('0x5a')]);_0x192832({'count':_0x317f3f[_0x4816('0x15')],'rows':_0x317f3f});});},'MailQueuesWaitingInteractions':function(_0x5f391e){return new Promise(function(_0x370439,_0x32ced6){var _0x4957e6=_[_0x4816('0x4e')](_0x13a685['mailQueuesWaitingInteractions']);_0x370439({'count':_0x4957e6[_0x4816('0x15')],'rows':_0x4957e6});});},'OpenchannelQueuesWaitingInteractions':function(_0x485505){return new Promise(function(_0x27ff4f,_0xa7f23c){var _0x30a190=_[_0x4816('0x4e')](_0x13a685['openchannelQueuesWaitingInteractions']);_0x27ff4f({'count':_0x30a190[_0x4816('0x15')],'rows':_0x30a190});});},'SmsQueuesWaitingInteractions':function(_0x4194f6){return new Promise(function(_0x1d0192,_0x2246b3){var _0x5e0b7e=_[_0x4816('0x4e')](_0x13a685[_0x4816('0x5b')]);_0x1d0192({'count':_0x5e0b7e[_0x4816('0x15')],'rows':_0x5e0b7e});});},'FaxQueuesWaitingInteractions':function(_0x1f0f2a){return new Promise(function(_0x5c68cc,_0xc1f850){var _0x37c2a1=_[_0x4816('0x4e')](_0x13a685[_0x4816('0x5c')]);_0x5c68cc({'count':_0x37c2a1[_0x4816('0x15')],'rows':_0x37c2a1});});},'WhatsappQueuesWaitingInteractions':function(_0x4a4e89){return new Promise(function(_0x2765ae,_0x4f43eb){var _0x1c0799=_[_0x4816('0x4e')](_0x13a685['whatsappQueuesWaitingInteractions']);_0x2765ae({'count':_0x1c0799[_0x4816('0x15')],'rows':_0x1c0799});});}};var _0x205cf1=jayson[_0x4816('0x5d')](_0x1eb683)['http']();_0x205cf1['on'](_0x4816('0x35'),function(_0x33eabd){logger['error'](JSON[_0x4816('0x5e')](_0x33eabd));return _0x248163(_0x33eabd);});_0x205cf1[_0x4816('0xf')](0x232c,'127.0.0.1',function(){console[_0x4816('0x5f')]('Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!',0x232c);return _0x42fc52('RPC\x20listening\x20on\x20port:'+0x232c);});});};
\ No newline at end of file