Fix proxy routing for whatsapp and pod startup for gmail-agent
This commit is contained in:
parent
4b658c41de
commit
ba8d5f03c3
|
|
@ -68,12 +68,14 @@ spec:
|
|||
- name: credentials-volume
|
||||
secret:
|
||||
secretName: gmail-agent-auth
|
||||
optional: true
|
||||
items:
|
||||
- key: credentials.json
|
||||
path: credentials.json
|
||||
- name: tokens-volume
|
||||
secret:
|
||||
secretName: gmail-agent-tokens
|
||||
optional: true
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
|
|
|
|||
|
|
@ -18,33 +18,37 @@ let accounts = [];
|
|||
|
||||
function loadAuth() {
|
||||
if (!fs.existsSync(CREDENTIALS_PATH)) {
|
||||
console.error('Missing credentials.json. Please download it from Google Cloud Console and place it in the project directory.');
|
||||
process.exit(1);
|
||||
console.warn('⚠️ Missing credentials.json. Gmail Agent will not be able to process emails or authenticate new accounts until this file is provided.');
|
||||
return;
|
||||
}
|
||||
if (!fs.existsSync(TOKENS_DIR)) {
|
||||
console.error('Missing tokens directory. Please run "node auth.js <account-name>" to generate an account token.');
|
||||
process.exit(1);
|
||||
fs.mkdirSync(TOKENS_DIR, { recursive: true });
|
||||
console.log('Created empty tokens directory.');
|
||||
}
|
||||
|
||||
const creds = JSON.parse(fs.readFileSync(CREDENTIALS_PATH));
|
||||
const {client_secret, client_id, redirect_uris} = creds.installed || creds.web;
|
||||
baseOAuth2Client = { client_id, client_secret, redirect_uri: redirect_uris[0] || 'urn:ietf:wg:oauth:2.0:oob' };
|
||||
|
||||
const tokenFiles = fs.readdirSync(TOKENS_DIR).filter(file => file.endsWith('.json'));
|
||||
if (tokenFiles.length === 0) {
|
||||
console.error('No tokens found in tokens/. Please run "node auth.js <account-name>" to generate one.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
for (const file of tokenFiles) {
|
||||
const accountName = file.replace('.json', '');
|
||||
const tokenContent = JSON.parse(fs.readFileSync(path.join(TOKENS_DIR, file)));
|
||||
try {
|
||||
const creds = JSON.parse(fs.readFileSync(CREDENTIALS_PATH));
|
||||
const {client_secret, client_id, redirect_uris} = creds.installed || creds.web;
|
||||
baseOAuth2Client = { client_id, client_secret, redirect_uri: redirect_uris[0] || 'urn:ietf:wg:oauth:2.0:oob' };
|
||||
|
||||
const client = new google.auth.OAuth2(baseOAuth2Client.client_id, baseOAuth2Client.client_secret, baseOAuth2Client.redirect_uri);
|
||||
client.setCredentials(tokenContent);
|
||||
const tokenFiles = fs.readdirSync(TOKENS_DIR).filter(file => file.endsWith('.json'));
|
||||
if (tokenFiles.length === 0) {
|
||||
console.log('ℹ️ No token files found in tokens/. Waiting for accounts to be added via UI.');
|
||||
return;
|
||||
}
|
||||
|
||||
accounts.push({ name: accountName, client });
|
||||
console.log(`Loaded credentials for account: ${accountName}`);
|
||||
for (const file of tokenFiles) {
|
||||
const accountName = file.replace('.json', '');
|
||||
const tokenContent = JSON.parse(fs.readFileSync(path.join(TOKENS_DIR, file)));
|
||||
|
||||
const client = new google.auth.OAuth2(baseOAuth2Client.client_id, baseOAuth2Client.client_secret, baseOAuth2Client.redirect_uri);
|
||||
client.setCredentials(tokenContent);
|
||||
|
||||
accounts.push({ name: accountName, client });
|
||||
console.log(`✅ Loaded credentials for account: ${accountName}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('❌ Error loading auth files:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const socket = io();
|
||||
const socket = io({ path: '/proxy/whatsapp/socket.io' });
|
||||
|
||||
// UI Elements
|
||||
const statusBadge = document.getElementById('status-badge');
|
||||
|
|
@ -84,7 +84,7 @@ function renderQR(qrText) {
|
|||
async function fetchGroups() {
|
||||
groupsTableBody.innerHTML = '<tr><td colspan="3" class="text-center">Loading...</td></tr>';
|
||||
try {
|
||||
const res = await fetch('/api/groups');
|
||||
const res = await fetch('api/groups');
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.success) {
|
||||
|
|
@ -121,7 +121,7 @@ document.getElementById('btn-refresh-groups').addEventListener('click', fetchGro
|
|||
async function fetchApps() {
|
||||
appsTableBody.innerHTML = '<tr><td colspan="4" class="text-center">Loading...</td></tr>';
|
||||
try {
|
||||
const res = await fetch('/api/apps');
|
||||
const res = await fetch('api/apps');
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.success) {
|
||||
|
|
@ -164,7 +164,7 @@ document.getElementById('create-group-form').addEventListener('submit', async (e
|
|||
const participant = document.getElementById('new-group-participant').value;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/groups/create', {
|
||||
const res = await fetch('api/groups/create', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ title, initialParticipants: [participant] })
|
||||
|
|
@ -189,7 +189,7 @@ document.getElementById('create-group-form').addEventListener('submit', async (e
|
|||
// Invite Link Modal
|
||||
window.getInviteLink = async (groupId) => {
|
||||
try {
|
||||
const res = await fetch('/api/groups/invite', {
|
||||
const res = await fetch('api/groups/invite', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ groupId })
|
||||
|
|
@ -230,7 +230,7 @@ document.getElementById('test-msg-form').addEventListener('submit', async (e) =>
|
|||
const message = document.getElementById('test-body').value;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/send-message', {
|
||||
const res = await fetch('api/send-message', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ to, message })
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WhatsApp Gateway Dashboard</title>
|
||||
<base href="/proxy/whatsapp/">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue