Initial commit: Daily tech newsletter worker

A Node.js/TypeScript worker that sends daily AI-generated summaries
of tech news from X/Twitter via Nitter RSS feeds.

Features:
- Fetches tweets from 40+ curated tech accounts via Nitter RSS
- Filters and categorizes by topic (AI/ML, SWE, General Tech)
- Generates AI summaries using OpenRouter (Claude/GPT-4)
- Sends professional HTML email via Brevo SMTP
- Runs on cron schedule inside Docker container
- Instance rotation for Nitter reliability
- Graceful degradation if AI fails

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-11 20:23:38 +00:00
commit b3643fd5b0
23 changed files with 2091 additions and 0 deletions

94
src/index.ts Normal file
View File

@@ -0,0 +1,94 @@
import { config } from './config/index.js';
import { logger } from './utils/logger.js';
import { NewsletterPipeline } from './core/NewsletterPipeline.js';
import { CronScheduler } from './services/scheduler/CronScheduler.js';
import { EmailService } from './services/email/EmailService.js';
async function main() {
const args = process.argv.slice(2);
const runNow = args.includes('--run-now');
const dryRun = args.includes('--dry-run');
if (dryRun) {
process.env.DRY_RUN = 'true';
}
logger.info(
{
runNow,
dryRun: config.features.dryRun || dryRun,
cronSchedule: config.scheduler.cronExpression,
timezone: config.scheduler.timezone,
recipients: config.email.recipients.length,
},
'X-Newsletter starting'
);
const pipeline = new NewsletterPipeline();
if (runNow) {
logger.info('Running newsletter pipeline immediately');
const result = await pipeline.run();
if (result.success) {
logger.info('Newsletter sent successfully');
process.exit(0);
} else {
logger.error({ errors: result.errors }, 'Newsletter pipeline failed');
process.exit(1);
}
}
// Verify email connection on startup
const emailService = new EmailService();
const emailConnected = await emailService.verifyConnection();
if (!emailConnected) {
logger.warn('Email service connection could not be verified - will retry on send');
}
// Set up scheduled execution
const scheduler = new CronScheduler();
scheduler.schedule(
'daily-newsletter',
config.scheduler.cronExpression,
async () => {
const result = await pipeline.run();
if (!result.success) {
logger.error({ errors: result.errors }, 'Scheduled newsletter failed');
}
},
{ timezone: config.scheduler.timezone }
);
scheduler.start();
logger.info(
{
schedule: config.scheduler.cronExpression,
timezone: config.scheduler.timezone,
},
'Newsletter scheduler started. Waiting for next scheduled run...'
);
// Handle graceful shutdown
const shutdown = () => {
logger.info('Shutting down...');
scheduler.stop();
process.exit(0);
};
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
// Keep the process running
await new Promise(() => {});
}
main().catch((error) => {
logger.error({ error }, 'Fatal error');
process.exit(1);
});