Refactor gmail-agent to use native fetch instead of axios to fix node 18 startup crash

This commit is contained in:
Antigravity 2026-06-13 17:19:20 -04:00
parent 5d57630736
commit 4ace103937
2 changed files with 20 additions and 12 deletions

View File

@ -2,7 +2,6 @@ require('dotenv').config();
const fs = require('fs');
const path = require('path');
const cron = require('node-cron');
const axios = require('axios');
const { google } = require('googleapis');
const TOKENS_DIR = path.join(__dirname, 'tokens');
@ -111,13 +110,18 @@ SUMMARY: <your summary if yes, otherwise leave blank>
`;
try {
const res = await axios.post(OLLAMA_URL, {
model: OLLAMA_MODEL,
prompt: prompt,
stream: false
const res = await fetch(OLLAMA_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: OLLAMA_MODEL,
prompt: prompt,
stream: false
})
});
const responseText = res.data.response || '';
const data = await res.json();
const responseText = data.response || '';
const isImportant = responseText.includes('IMPORTANT: YES');
const summaryMatch = responseText.match(/SUMMARY:\s*(.*)/);
const summary = summaryMatch ? summaryMatch[1].trim() : '';
@ -133,11 +137,16 @@ async function sendWhatsAppNotification(email, summary) {
const message = `📧 *[${email.accountName}] Important Email*\n*From:* ${email.from}\n*Subject:* ${email.subject}\n\n🤖 *Summary:* ${summary}`;
try {
await axios.post(WHATSAPP_GATEWAY_URL, {
to: WHATSAPP_TO,
message: message
}, {
headers: { 'x-app-name': 'Gmail Agent' }
await fetch(WHATSAPP_GATEWAY_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-app-name': 'Gmail Agent'
},
body: JSON.stringify({
to: WHATSAPP_TO,
message: message
})
});
console.log(`Notification sent for: [${email.accountName}] ${email.subject}`);
} catch (err) {

View File

@ -11,7 +11,6 @@
"license": "ISC",
"type": "commonjs",
"dependencies": {
"axios": "^1.17.0",
"cors": "^2.8.6",
"dotenv": "^17.4.2",
"express": "^5.2.1",