6d6878ad2ec67808f9da1108f8c54f6c1caa66e9
[motion-next.git] / server / services / routing / server / index.js
1 const a1217_0x3692=['matchPath','faxQueuesWaitingInteractions','./applications/','No\x20applications\x20to\x20execute','emit','waiting','UserId','length','../rpc/whatsappQueueReport','error\x20update\x20queue\x20report','openchannelQueues','condition','mailQueues','applications','Intervals','available','mailQueuesWaitingInteractions','loggedIn','execute','complete','slice','CurrentCapacity','intervals','agent\x20not\x20found','util','faxQueues','openchannelQueuesWaitingInteractions','dialogflow','interval','split','RPC\x20listening\x20on\x20port:','../../../config/logger','smsQueuesWaitingInteractions','../rpc/faxQueueReport','stringify','isArray','./interval','whatsappQueuesWaitingInteractions','\x20|\x20','%s:%s:%s','message\x20is\x20empty','error','routing','Please\x20create\x20a\x20new\x20file\x20under','chatQueues','log','agent','info','IntervalId','agents','map','capacity','%s.%s.%s','tag','name','join','interaction','catch','lodash','message','QueueReport','channel','priority','routing\x20is\x20empty','busyQueue','smsQueues','appdata','app','../rpc/mailQueueReport','existsSync','listen','format','paused','undefined','amazonlex','rules','on\x20interval','../rpc/chatQueueReport','path','chatQueuesWaitingInteractions','push','whatsappQueues','Push\x20new\x20rule','end','update','stack','values','TagId','isNil'];(function(_0x39340d,_0x3692db){const _0x1bf918=function(_0x3aa48d){while(--_0x3aa48d){_0x39340d['push'](_0x39340d['shift']());}};_0x1bf918(++_0x3692db);}(a1217_0x3692,0x15a));const a1217_0x1bf9=function(_0x39340d,_0x3692db){_0x39340d=_0x39340d-0x0;let _0x1bf918=a1217_0x3692[_0x39340d];return _0x1bf918;};const _0x2116d2=a1217_0x1bf9;'use strict';const _=require(_0x2116d2('0x44')),util=require(_0x2116d2('0x22')),path=require(_0x2116d2('0x58')),fs=require('fs'),jayson=require('jayson/promise'),logger=require(_0x2116d2('0x29'))(_0x2116d2('0x34')),rpc={'openchannelQueueReport':require('../rpc/openchannelQueueReport'),'mailQueueReport':require(_0x2116d2('0x4e')),'chatQueueReport':require(_0x2116d2('0x57')),'smsQueueReport':require('../rpc/smsQueueReport'),'faxQueueReport':require(_0x2116d2('0x2b')),'whatsappQueueReport':require(_0x2116d2('0x12'))},RuleEngine=require('../lib/rule-engine');function getId(_0x3aa48d,_0x38af7b,_0x2bf139){const _0xa796ea=_0x2116d2;return util[_0xa796ea('0x51')](_0xa796ea('0x3e'),_0x3aa48d,_0x38af7b||0x0,_0x2bf139||0x0);}function getIntervals(_0x445f4c,_0xbfbd79){const _0x299805=_0x2116d2;let _0x37e3ba=[];if(!_[_0x299805('0x9')](_0xbfbd79[_0x299805('0x3a')])&&!_[_0x299805('0x9')](_0x445f4c[_0xbfbd79[_0x299805('0x3a')]])&&!_[_0x299805('0x9')](_0x445f4c[_0xbfbd79[_0x299805('0x3a')]]['Intervals']))_0x37e3ba=_[_0x299805('0x3c')](_0x445f4c[_0xbfbd79[_0x299805('0x3a')]][_0x299805('0x18')],_0x299805('0x26'));else!_[_0x299805('0x9')](_0xbfbd79['interval'])&&(_0x37e3ba=[_0xbfbd79['interval']]);return _0x37e3ba;}exports[_0x2116d2('0x50')]=function(_0x17a592){const _0xf5c1ed=_0x2116d2;return _0x17a592[_0xf5c1ed('0x55')]={},new Promise(function(_0x2da213,_0x20b457){const _0x3c3a5f=_0xf5c1ed,_0x5ea3e8={'Start':function(_0x12d763){const _0x48ff9e=this;return new Promise(function(_0x12e6fb,_0x17dafd){const _0x27a5c5=a1217_0x1bf9;if(_0x12d763)try{const _0x36dab8=[],_0x2b2ef7=getId(_0x12d763[_0x27a5c5('0x47')],_0x12d763[_0x27a5c5('0x45')]?_0x12d763[_0x27a5c5('0x45')]['id']:0x0,_0x12d763[_0x27a5c5('0x42')]?_0x12d763[_0x27a5c5('0x42')]['id']:0x0);if(_0x12d763[_0x27a5c5('0x17')]&&_[_0x27a5c5('0x2d')](_0x12d763[_0x27a5c5('0x17')])&&_0x12d763['applications'][_0x27a5c5('0x11')]){for(let _0x55cfbf=0x0;_0x55cfbf<_0x12d763[_0x27a5c5('0x17')][_0x27a5c5('0x11')];_0x55cfbf+=0x1){const _0x3299e2=_0x12d763[_0x27a5c5('0x17')][_0x55cfbf];if(fs[_0x27a5c5('0x4f')](path[_0x27a5c5('0x41')](__dirname,_0x27a5c5('0x17'),_0x3299e2[_0x27a5c5('0x4d')]+'.js'))){let _0x4abb9d=[];switch(_0x3299e2['app']['toLowerCase']()){case'autoreply':{const _0x5502fd=_0x3299e2[_0x27a5c5('0x4c')][_0x27a5c5('0x27')](',');_0x4abb9d[_0x27a5c5('0x1')](_0x5502fd[0x0]),_0x4abb9d[_0x27a5c5('0x1')](_0x5502fd[_0x27a5c5('0x1e')](0x1,_0x5502fd['length'])[_0x27a5c5('0x41')](','));}break;case _0x27a5c5('0x25'):{const _0x23bf26=_0x3299e2[_0x27a5c5('0x4c')][_0x27a5c5('0x27')](',');_0x4abb9d[_0x27a5c5('0x1')](_0x23bf26[0x0]),_0x4abb9d['push'](_0x23bf26[0x1]),_0x4abb9d[_0x27a5c5('0x1')](_0x23bf26[_0x27a5c5('0x1e')](0x2,_0x23bf26[_0x27a5c5('0x11')])[_0x27a5c5('0x41')](','));}break;case _0x27a5c5('0x54'):{const _0x1a76eb=_0x3299e2[_0x27a5c5('0x4c')]['split'](',');_0x4abb9d[_0x27a5c5('0x1')](_0x1a76eb[0x0]),_0x4abb9d[_0x27a5c5('0x1')](_0x1a76eb[0x1]),_0x4abb9d[_0x27a5c5('0x1')](_0x1a76eb[0x2]),_0x4abb9d[_0x27a5c5('0x1')](_0x1a76eb[0x3]),_0x4abb9d['push'](_0x1a76eb[_0x27a5c5('0x1e')](0x4,_0x1a76eb['length'])[_0x27a5c5('0x41')](','));}break;case _0x27a5c5('0x45'):_0x4abb9d[_0x27a5c5('0x1')](_0x3299e2[_0x27a5c5('0x4c')]);break;case _0x27a5c5('0x3f'):_0x4abb9d['push'](_0x3299e2[_0x27a5c5('0x8')]),_0x4abb9d[_0x27a5c5('0x1')](_0x3299e2[_0x27a5c5('0x4c')]);break;default:_0x4abb9d=_[_0x27a5c5('0x9')](_0x3299e2[_0x27a5c5('0x4c')])?[]:_0x3299e2[_0x27a5c5('0x4c')]['split'](',');}const _0x359073={'id':util[_0x27a5c5('0x51')](_0x27a5c5('0x31'),_0x2b2ef7,_0x3299e2['id'],_0x3299e2[_0x27a5c5('0x4d')]),'condition':require(_0x27a5c5('0x2e'))[_0x27a5c5('0x15')](_0x2b2ef7,getIntervals(_0x17a592['intervals'],_0x3299e2),_0x17a592),'consequence':require(_0x27a5c5('0xc')+_0x3299e2[_0x27a5c5('0x4d')])['consequence'](_0x2b2ef7,_0x4abb9d,_0x17a592,_0x12d763),'p':_0x3299e2[_0x27a5c5('0x48')]||0x0};logger[_0x27a5c5('0x39')](_0x27a5c5('0x3'),_0x359073['id'],_0x27a5c5('0x56'),getIntervals(_0x17a592[_0x27a5c5('0x20')],_0x3299e2)[_0x27a5c5('0x41')](_0x27a5c5('0x30'))),_0x36dab8[_0x27a5c5('0x1')](_0x359073);}else logger[_0x27a5c5('0x33')](_0x27a5c5('0x35'),path['join'](__dirname,_0x27a5c5('0x17'),_0x3299e2[_0x27a5c5('0x4d')]+'.js'));}return _0x17a592[_0x27a5c5('0x55')][_0x2b2ef7]=new RuleEngine(_0x36dab8),_0x17a592[_0x27a5c5('0x55')][_0x2b2ef7][_0x27a5c5('0x1c')](_0x12d763,function(_0x468c58){const _0x58587d=_0x27a5c5;logger[_0x58587d('0x39')]('Applications\x20executed',JSON['stringify'](_0x468c58[_0x58587d('0xa')])),_0x17a592[_0x58587d('0x55')][_0x2b2ef7]&&_0x17a592[_0x58587d('0x55')][_0x2b2ef7][_0x58587d('0xe')](_0x58587d('0x1d'));}),_0x12e6fb({'code':0xc8,'message':_0x12d763});}else return logger[_0x27a5c5('0x39')](_0x27a5c5('0xd')),_0x12e6fb({'code':0xc8,'message':_0x12d763});}catch(_0x576b35){return logger[_0x27a5c5('0x33')](_0x576b35['stack']),_0x17dafd(_0x48ff9e['error'](0x1f4,_0x576b35));}return _0x17dafd(_0x27a5c5('0x49'));});},'AcceptMessage':function(_0x57417c){const _0x4eb861=this;return new Promise(function(_0x30e9a8,_0x423acb){const _0x58b1ff=a1217_0x1bf9;if(_0x57417c[_0x58b1ff('0x45')]&&_0x57417c[_0x58b1ff('0x45')]['id'])try{const _0x125be9=getId(_0x57417c[_0x58b1ff('0x47')],_0x57417c[_0x58b1ff('0x45')]?_0x57417c['message']['id']:0x0,_0x57417c['interaction']?_0x57417c['interaction']['id']:0x0);return _0x17a592[_0x58b1ff('0x55')][_0x125be9]&&(_0x17a592[_0x58b1ff('0x55')][_0x125be9][_0x58b1ff('0xe')](_0x58b1ff('0x4')),rpc[_0x57417c['channel']+_0x58b1ff('0x46')]&&rpc[_0x57417c[_0x58b1ff('0x47')]+_0x58b1ff('0x46')][_0x58b1ff('0x5')](_0x125be9,{'UserId':_0x57417c[_0x58b1ff('0x45')][_0x58b1ff('0x10')]})[_0x58b1ff('0x43')](function(){const _0x2a6017=_0x58b1ff;logger['error'](_0x2a6017('0x13'));})),_0x30e9a8({'code':0xc8,'message':_0x57417c});}catch(_0x2b7c24){return logger[_0x58b1ff('0x33')](_0x2b7c24[_0x58b1ff('0x6')]),_0x423acb(_0x4eb861[_0x58b1ff('0x33')](0x1f4,_0x2b7c24));}return logger[_0x58b1ff('0x33')](_0x58b1ff('0x32')),_0x423acb(_0x4eb861[_0x58b1ff('0x33')](0x1f4,_0x58b1ff('0x32')));});},'RejectMessage':function(_0x45a513){const _0x5c2a0e=this;return new Promise(function(_0x2390e9,_0x155dcb){const _0x158628=a1217_0x1bf9;if(_0x45a513[_0x158628('0x38')]&&_0x45a513[_0x158628('0x38')]['id'])try{return _0x17a592[_0x158628('0x3b')][_0x45a513['agent']['id']]&&(_0x17a592[_0x158628('0x3b')][_0x45a513[_0x158628('0x38')]['id']]['busy']=![],_0x17a592['agents'][_0x45a513['agent']['id']][_0x158628('0x4a')]=undefined),_0x2390e9({'code':0xc8,'message':_0x45a513});}catch(_0x315c22){return logger[_0x158628('0x33')](_0x315c22['stack']),_0x155dcb(_0x5c2a0e[_0x158628('0x33')](0x1f4,_0x315c22));}return logger[_0x158628('0x33')](_0x158628('0x32')),_0x155dcb(_0x5c2a0e[_0x158628('0x33')](0x1f4,_0x158628('0x32')));});},'AbandonInteraction':function(_0x38404c){const _0x48a2ce=this;return new Promise(function(_0x29a34f,_0x2da99d){const _0x55ee0c=a1217_0x1bf9;if(_0x38404c[_0x55ee0c('0x47')]&&_0x38404c[_0x55ee0c('0x42')]&&_0x38404c[_0x55ee0c('0x42')]['id'])try{const _0x480a5d=getId(_0x38404c[_0x55ee0c('0x47')],_0x38404c['message']?_0x38404c[_0x55ee0c('0x45')]['id']:0x0,_0x38404c[_0x55ee0c('0x42')]?_0x38404c[_0x55ee0c('0x42')]['id']:0x0);return _0x17a592[_0x55ee0c('0x55')][_0x480a5d]&&_0x17a592[_0x55ee0c('0x55')][_0x480a5d][_0x55ee0c('0xe')](_0x55ee0c('0x4')),_0x29a34f({'code':0xc8,'message':_0x38404c});}catch(_0x8ef9d1){return logger[_0x55ee0c('0x33')](_0x8ef9d1[_0x55ee0c('0x6')]),_0x2da99d(_0x48a2ce[_0x55ee0c('0x33')](0x1f4,_0x8ef9d1));}return logger['error'](_0x55ee0c('0x32')),_0x2da99d(_0x48a2ce['error'](0x1f4,_0x55ee0c('0x32')));});},'AgentCapacity':function(_0x4f1b9b){const _0x5556e1=this;return new Promise(function(_0x58ad56,_0x527891){const _0x3823b8=a1217_0x1bf9;if(typeof _0x17a592[_0x3823b8('0x3b')][_0x4f1b9b['id']]!=='undefined'){for(const _0x572148 in _0x4f1b9b[_0x3823b8('0x3d')]){typeof _0x4f1b9b[_0x3823b8('0x3d')][_0x572148]!==_0x3823b8('0x53')&&(typeof _0x17a592['agents'][_0x4f1b9b['id']][_0x572148+_0x3823b8('0x1f')]!==_0x3823b8('0x53')&&(_0x17a592[_0x3823b8('0x3b')][_0x4f1b9b['id']][_0x572148+_0x3823b8('0x1f')]=parseInt(_0x4f1b9b['capacity'][_0x572148],0xa)));}return _0x17a592[_0x3823b8('0x3b')][_0x4f1b9b['id']]['updateRealtime'](),_0x58ad56({'code':0xc8,'message':_0x17a592[_0x3823b8('0x3b')][_0x4f1b9b['id']]});}else return _0x527891(_0x5556e1['error'](0x1f4,_0x3823b8('0x21')));});},'Agents':function(){return new Promise(function(_0x549f0c){const _0x2f07f4=a1217_0x1bf9,_0x49fe0c=_[_0x2f07f4('0x7')](_0x17a592[_0x2f07f4('0x3b')]);_0x549f0c({'count':_0x49fe0c[_0x2f07f4('0x11')],'rows':_0x49fe0c});});},'ChatQueues':function(){return new Promise(function(_0x2bf6a9){const _0x5967ad=a1217_0x1bf9,_0xf1f9d6=[];for(const _0x57875d in _0x17a592[_0x5967ad('0x36')]){if(typeof _0x17a592[_0x5967ad('0x36')][_0x57875d]!==_0x5967ad('0x53')){const _0x2d7c8d=_0x17a592['chatQueues'][_0x57875d],_0x2f4119={'id':_0x2d7c8d['id'],'available':_0x2d7c8d['available'],'loggedIn':_0x2d7c8d[_0x5967ad('0x1b')],'name':_0x2d7c8d[_0x5967ad('0x40')],'paused':_0x2d7c8d[_0x5967ad('0x52')],'waiting':_0x2d7c8d[_0x5967ad('0xf')]};_0xf1f9d6[_0x5967ad('0x1')](_0x2f4119);}}_0x2bf6a9({'count':_0xf1f9d6[_0x5967ad('0x11')],'rows':_0xf1f9d6});});},'MailQueues':function(){return new Promise(function(_0x1be743){const _0x3708c0=a1217_0x1bf9,_0x380627=[];for(const _0x577d0f in _0x17a592[_0x3708c0('0x16')]){if(typeof _0x17a592[_0x3708c0('0x16')][_0x577d0f]!=='undefined'){const _0x25291b=_0x17a592[_0x3708c0('0x16')][_0x577d0f],_0x5dd722={'id':_0x25291b['id'],'available':_0x25291b['available'],'loggedIn':_0x25291b[_0x3708c0('0x1b')],'name':_0x25291b[_0x3708c0('0x40')],'paused':_0x25291b[_0x3708c0('0x52')],'waiting':_0x25291b[_0x3708c0('0xf')]};_0x380627[_0x3708c0('0x1')](_0x5dd722);}}_0x1be743({'count':_0x380627[_0x3708c0('0x11')],'rows':_0x380627});});},'OpenchannelQueues':function(){return new Promise(function(_0x3b83ac){const _0x374f26=a1217_0x1bf9,_0x28313e=[];for(const _0x1d9c69 in _0x17a592[_0x374f26('0x14')]){if(typeof _0x17a592[_0x374f26('0x14')][_0x1d9c69]!==_0x374f26('0x53')){const _0x323dc5=_0x17a592['openchannelQueues'][_0x1d9c69],_0x21eaad={'id':_0x323dc5['id'],'available':_0x323dc5[_0x374f26('0x19')],'loggedIn':_0x323dc5[_0x374f26('0x1b')],'name':_0x323dc5[_0x374f26('0x40')],'paused':_0x323dc5[_0x374f26('0x52')],'waiting':_0x323dc5[_0x374f26('0xf')]};_0x28313e[_0x374f26('0x1')](_0x21eaad);}}_0x3b83ac({'count':_0x28313e[_0x374f26('0x11')],'rows':_0x28313e});});},'SmsQueues':function(){return new Promise(function(_0x4294c7){const _0x12c9c2=a1217_0x1bf9,_0x204c11=[];for(const _0x1fcc31 in _0x17a592[_0x12c9c2('0x4b')]){if(typeof _0x17a592[_0x12c9c2('0x4b')][_0x1fcc31]!==_0x12c9c2('0x53')){const _0x4352f1=_0x17a592['smsQueues'][_0x1fcc31],_0x3ac858={'id':_0x4352f1['id'],'available':_0x4352f1['available'],'loggedIn':_0x4352f1[_0x12c9c2('0x1b')],'name':_0x4352f1[_0x12c9c2('0x40')],'paused':_0x4352f1[_0x12c9c2('0x52')],'waiting':_0x4352f1['waiting']};_0x204c11[_0x12c9c2('0x1')](_0x3ac858);}}_0x4294c7({'count':_0x204c11[_0x12c9c2('0x11')],'rows':_0x204c11});});},'FaxQueues':function(){return new Promise(function(_0x4092c3){const _0x48dc6a=a1217_0x1bf9,_0x56f34a=[];for(const _0x3a33b2 in _0x17a592[_0x48dc6a('0x23')]){if(typeof _0x17a592['faxQueues'][_0x3a33b2]!==_0x48dc6a('0x53')){const _0x219ad9=_0x17a592[_0x48dc6a('0x23')][_0x3a33b2],_0x1bf6a1={'id':_0x219ad9['id'],'available':_0x219ad9['available'],'loggedIn':_0x219ad9[_0x48dc6a('0x1b')],'name':_0x219ad9[_0x48dc6a('0x40')],'paused':_0x219ad9['paused'],'waiting':_0x219ad9[_0x48dc6a('0xf')]};_0x56f34a['push'](_0x1bf6a1);}}_0x4092c3({'count':_0x56f34a[_0x48dc6a('0x11')],'rows':_0x56f34a});});},'WhatsappQueues':function(){return new Promise(function(_0x280685){const _0x3fab70=a1217_0x1bf9,_0x4e925e=[];for(const _0x37d8de in _0x17a592[_0x3fab70('0x2')]){if(typeof _0x17a592[_0x3fab70('0x2')][_0x37d8de]!==_0x3fab70('0x53')){const _0x5dbd56=_0x17a592['whatsappQueues'][_0x37d8de],_0x15974b={'id':_0x5dbd56['id'],'available':_0x5dbd56[_0x3fab70('0x19')],'loggedIn':_0x5dbd56[_0x3fab70('0x1b')],'name':_0x5dbd56['name'],'paused':_0x5dbd56[_0x3fab70('0x52')],'waiting':_0x5dbd56[_0x3fab70('0xf')]};_0x4e925e['push'](_0x15974b);}}_0x280685({'count':_0x4e925e[_0x3fab70('0x11')],'rows':_0x4e925e});});},'ChatQueuesWaitingInteractions':function(){return new Promise(function(_0x55a5c2){const _0x357078=a1217_0x1bf9,_0x3d03e9=_['values'](_0x17a592[_0x357078('0x0')]);_0x55a5c2({'count':_0x3d03e9[_0x357078('0x11')],'rows':_0x3d03e9});});},'MailQueuesWaitingInteractions':function(){return new Promise(function(_0x5e2982){const _0x33fb3c=a1217_0x1bf9,_0x250ca8=_[_0x33fb3c('0x7')](_0x17a592[_0x33fb3c('0x1a')]);_0x5e2982({'count':_0x250ca8['length'],'rows':_0x250ca8});});},'OpenchannelQueuesWaitingInteractions':function(){return new Promise(function(_0x18c58c){const _0x55004b=a1217_0x1bf9,_0x4b9665=_['values'](_0x17a592[_0x55004b('0x24')]);_0x18c58c({'count':_0x4b9665[_0x55004b('0x11')],'rows':_0x4b9665});});},'SmsQueuesWaitingInteractions':function(){return new Promise(function(_0x4b511c){const _0x138d70=a1217_0x1bf9,_0x5059eb=_['values'](_0x17a592[_0x138d70('0x2a')]);_0x4b511c({'count':_0x5059eb[_0x138d70('0x11')],'rows':_0x5059eb});});},'FaxQueuesWaitingInteractions':function(){return new Promise(function(_0x3b08f5){const _0x190db1=a1217_0x1bf9,_0x22fa6c=_[_0x190db1('0x7')](_0x17a592[_0x190db1('0xb')]);_0x3b08f5({'count':_0x22fa6c['length'],'rows':_0x22fa6c});});},'WhatsappQueuesWaitingInteractions':function(){return new Promise(function(_0x57663b){const _0x5b18e5=a1217_0x1bf9,_0x479dea=_[_0x5b18e5('0x7')](_0x17a592[_0x5b18e5('0x2f')]);_0x57663b({'count':_0x479dea[_0x5b18e5('0x11')],'rows':_0x479dea});});}},_0x2684ee=jayson['server'](_0x5ea3e8)['http']();_0x2684ee['on'](_0x3c3a5f('0x33'),function(_0x48cc3a){const _0x21ed13=_0x3c3a5f;return logger['error'](JSON[_0x21ed13('0x2c')](_0x48cc3a)),_0x20b457(_0x48cc3a);}),_0x2684ee[_0x3c3a5f('0x50')](0x232c,'127.0.0.1',function(){const _0x45d826=_0x3c3a5f;return console[_0x45d826('0x37')]('Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!',0x232c),_0x2da213(_0x45d826('0x28')+0x232c);});});};