Refactor gmail-agent to use native fetch instead of axios to fix node 18 startup crash
This commit is contained in:
parent
5d57630736
commit
4ace103937
|
|
@ -2,7 +2,6 @@ require('dotenv').config();
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const cron = require('node-cron');
|
const cron = require('node-cron');
|
||||||
const axios = require('axios');
|
|
||||||
const { google } = require('googleapis');
|
const { google } = require('googleapis');
|
||||||
|
|
||||||
const TOKENS_DIR = path.join(__dirname, 'tokens');
|
const TOKENS_DIR = path.join(__dirname, 'tokens');
|
||||||
|
|
@ -111,13 +110,18 @@ SUMMARY: <your summary if yes, otherwise leave blank>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(OLLAMA_URL, {
|
const res = await fetch(OLLAMA_URL, {
|
||||||
model: OLLAMA_MODEL,
|
method: 'POST',
|
||||||
prompt: prompt,
|
headers: { 'Content-Type': 'application/json' },
|
||||||
stream: false
|
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 isImportant = responseText.includes('IMPORTANT: YES');
|
||||||
const summaryMatch = responseText.match(/SUMMARY:\s*(.*)/);
|
const summaryMatch = responseText.match(/SUMMARY:\s*(.*)/);
|
||||||
const summary = summaryMatch ? summaryMatch[1].trim() : '';
|
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}`;
|
const message = `📧 *[${email.accountName}] Important Email*\n*From:* ${email.from}\n*Subject:* ${email.subject}\n\n🤖 *Summary:* ${summary}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post(WHATSAPP_GATEWAY_URL, {
|
await fetch(WHATSAPP_GATEWAY_URL, {
|
||||||
to: WHATSAPP_TO,
|
method: 'POST',
|
||||||
message: message
|
headers: {
|
||||||
}, {
|
'Content-Type': 'application/json',
|
||||||
headers: { 'x-app-name': 'Gmail Agent' }
|
'x-app-name': 'Gmail Agent'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
to: WHATSAPP_TO,
|
||||||
|
message: message
|
||||||
|
})
|
||||||
});
|
});
|
||||||
console.log(`Notification sent for: [${email.accountName}] ${email.subject}`);
|
console.log(`Notification sent for: [${email.accountName}] ${email.subject}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.17.0",
|
|
||||||
"cors": "^2.8.6",
|
"cors": "^2.8.6",
|
||||||
"dotenv": "^17.4.2",
|
"dotenv": "^17.4.2",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue