Files
Synapsis/bot-cron.ts
T
AskIt 8ad3b97b7e feat(bots): Implement comprehensive bot system with autonomous posting, content management, and API endpoints
- Add bot management system with creation, suspension, and reinstatement functionality
- Implement autonomous bot posting with scheduling, rate limiting, and content generation
- Add content fetching system supporting RSS feeds and multiple content sources
- Implement LLM-based content generation with customizable bot personalities
- Add mention handling and automated response system for bot interactions
- Implement API key management with encryption using AUTH_SECRET for simplified deployment
- Add comprehensive bot logging system for activity tracking and error monitoring
- Create bot administration pages and settings UI for managing bot configurations
- Add database migrations for bot system schema including users, sources, and content items
- Implement cron job system for automated bot operations and scheduled tasks
- Add extensive test coverage with unit and property-based tests for core bot modules
- Simplify encryption by deriving keys from AUTH_SECRET instead of separate environment variable
- Implement automatic content fetching on post trigger with retry logic
- Add Reddit-specific link preview handling using oEmbed API for reliable metadata extraction
- Create utility scripts for bot inspection and cleanup operations
- Add comprehensive bot system documentation and improvement tracking
2026-01-25 16:22:41 +01:00

64 lines
1.7 KiB
TypeScript

/**
* Bot Cron Job Script
*
* Run with PM2:
* pm2 start bot-cron.ts --name "bot-cron" --cron "* * * * *" --no-autorestart
*
* Or for continuous running with internal interval:
* pm2 start bot-cron.ts --name "bot-cron"
*/
const INTERVAL_MS = 60 * 1000; // 1 minute
const API_URL = process.env.NEXT_PUBLIC_NODE_DOMAIN
? `https://${process.env.NEXT_PUBLIC_NODE_DOMAIN}/api/cron/bots`
: 'http://localhost:3000/api/cron/bots';
const AUTH_SECRET = process.env.AUTH_SECRET || '';
async function runCron() {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}] Running bot cron job...`);
try {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};
if (AUTH_SECRET) {
headers['Authorization'] = `Bearer ${AUTH_SECRET}`;
}
const response = await fetch(API_URL, {
method: 'POST',
headers,
});
const data = await response.json();
if (response.ok) {
console.log(`[${timestamp}] Cron completed:`, JSON.stringify(data, null, 2));
} else {
console.error(`[${timestamp}] Cron failed:`, data);
}
} catch (error) {
console.error(`[${timestamp}] Cron error:`, error);
}
}
// Check if running with PM2 cron (single execution) or continuous mode
const isPM2Cron = process.env.PM2_CRON === 'true' || process.argv.includes('--once');
if (isPM2Cron) {
// Single execution mode (PM2 handles scheduling)
runCron().then(() => process.exit(0));
} else {
// Continuous mode with internal interval
console.log(`Bot cron started. Running every ${INTERVAL_MS / 1000} seconds.`);
console.log(`API URL: ${API_URL}`);
// Run immediately on start
runCron();
// Then run on interval
setInterval(runCron, INTERVAL_MS);
}