Fix proxy routing for whatsapp and pod startup for gmail-agent

This commit is contained in:
Antigravity 2026-06-13 16:21:18 -04:00
parent 4b658c41de
commit ba8d5f03c3
4 changed files with 34 additions and 27 deletions

View File

@ -68,12 +68,14 @@ spec:
- name: credentials-volume - name: credentials-volume
secret: secret:
secretName: gmail-agent-auth secretName: gmail-agent-auth
optional: true
items: items:
- key: credentials.json - key: credentials.json
path: credentials.json path: credentials.json
- name: tokens-volume - name: tokens-volume
secret: secret:
secretName: gmail-agent-tokens secretName: gmail-agent-tokens
optional: true
--- ---
apiVersion: v1 apiVersion: v1

View File

@ -18,33 +18,37 @@ let accounts = [];
function loadAuth() { function loadAuth() {
if (!fs.existsSync(CREDENTIALS_PATH)) { if (!fs.existsSync(CREDENTIALS_PATH)) {
console.error('Missing credentials.json. Please download it from Google Cloud Console and place it in the project directory.'); console.warn('⚠️ Missing credentials.json. Gmail Agent will not be able to process emails or authenticate new accounts until this file is provided.');
process.exit(1); return;
} }
if (!fs.existsSync(TOKENS_DIR)) { if (!fs.existsSync(TOKENS_DIR)) {
console.error('Missing tokens directory. Please run "node auth.js <account-name>" to generate an account token.'); fs.mkdirSync(TOKENS_DIR, { recursive: true });
process.exit(1); console.log('Created empty tokens directory.');
} }
const creds = JSON.parse(fs.readFileSync(CREDENTIALS_PATH)); try {
const {client_secret, client_id, redirect_uris} = creds.installed || creds.web; const creds = JSON.parse(fs.readFileSync(CREDENTIALS_PATH));
baseOAuth2Client = { client_id, client_secret, redirect_uri: redirect_uris[0] || 'urn:ietf:wg:oauth:2.0:oob' }; 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)));
const client = new google.auth.OAuth2(baseOAuth2Client.client_id, baseOAuth2Client.client_secret, baseOAuth2Client.redirect_uri); const tokenFiles = fs.readdirSync(TOKENS_DIR).filter(file => file.endsWith('.json'));
client.setCredentials(tokenContent); 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 }); for (const file of tokenFiles) {
console.log(`Loaded credentials for account: ${accountName}`); 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);
} }
} }

View File

@ -1,4 +1,4 @@
const socket = io(); const socket = io({ path: '/proxy/whatsapp/socket.io' });
// UI Elements // UI Elements
const statusBadge = document.getElementById('status-badge'); const statusBadge = document.getElementById('status-badge');
@ -84,7 +84,7 @@ function renderQR(qrText) {
async function fetchGroups() { async function fetchGroups() {
groupsTableBody.innerHTML = '<tr><td colspan="3" class="text-center">Loading...</td></tr>'; groupsTableBody.innerHTML = '<tr><td colspan="3" class="text-center">Loading...</td></tr>';
try { try {
const res = await fetch('/api/groups'); const res = await fetch('api/groups');
const data = await res.json(); const data = await res.json();
if (!data.success) { if (!data.success) {
@ -121,7 +121,7 @@ document.getElementById('btn-refresh-groups').addEventListener('click', fetchGro
async function fetchApps() { async function fetchApps() {
appsTableBody.innerHTML = '<tr><td colspan="4" class="text-center">Loading...</td></tr>'; appsTableBody.innerHTML = '<tr><td colspan="4" class="text-center">Loading...</td></tr>';
try { try {
const res = await fetch('/api/apps'); const res = await fetch('api/apps');
const data = await res.json(); const data = await res.json();
if (!data.success) { if (!data.success) {
@ -164,7 +164,7 @@ document.getElementById('create-group-form').addEventListener('submit', async (e
const participant = document.getElementById('new-group-participant').value; const participant = document.getElementById('new-group-participant').value;
try { try {
const res = await fetch('/api/groups/create', { const res = await fetch('api/groups/create', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, initialParticipants: [participant] }) body: JSON.stringify({ title, initialParticipants: [participant] })
@ -189,7 +189,7 @@ document.getElementById('create-group-form').addEventListener('submit', async (e
// Invite Link Modal // Invite Link Modal
window.getInviteLink = async (groupId) => { window.getInviteLink = async (groupId) => {
try { try {
const res = await fetch('/api/groups/invite', { const res = await fetch('api/groups/invite', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ groupId }) body: JSON.stringify({ groupId })
@ -230,7 +230,7 @@ document.getElementById('test-msg-form').addEventListener('submit', async (e) =>
const message = document.getElementById('test-body').value; const message = document.getElementById('test-body').value;
try { try {
const res = await fetch('/api/send-message', { const res = await fetch('api/send-message', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ to, message }) body: JSON.stringify({ to, message })

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WhatsApp Gateway Dashboard</title> <title>WhatsApp Gateway Dashboard</title>
<base href="/proxy/whatsapp/">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"> <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> <script src="/socket.io/socket.io.js"></script>