🎬 Open-source, self-hosted AI agent that runs a YouTube channel end to end: researches topics, writes scripts, generates narration, visuals and video, optimizes SEO, and publishes after your approval, then learns from analytics. Works with Gemini, OpenAI, OpenRouter, DeepSeek and more.
JavaScript ai-agentsautomationcontent-automationcontent-creationcontent-strategygoogle-geminijavascriptnodejsopenaiself-hostedseo-optimizationsocial-media-automationthumbnail-generatorvideo-generationyoutube-apiyoutube-automationyoutube-botyoutube-channelyoutube-shortsyoutube-uploader
feat: schedule tapered audience comment sync every four hours
darkzOGxfcd4354e5506
diff --git a/index.js b/index.jsindex 18326ea..acb5f07 100644--- a/index.js+++ b/index.js@@ -123,7 +123,8 @@ class YouTubeAutomationAgent {// Initialize schedulerthis.logger.info('Setting up automation scheduler...');this.scheduler = new DailyAutomation(this.agents, this.db, {- generateContent: input => this.queueScheduledContent(input)+ generateContent: input => this.queueScheduledContent(input),+ engagement: this.engagement});await this.scheduler.initialize();diff --git a/schedules/daily-automation.js b/schedules/daily-automation.jsindex d9f41a5..2549a41 100644--- a/schedules/daily-automation.js+++ b/schedules/daily-automation.js@@ -11,6 +11,7 @@ class DailyAutomation {this.healthCheckInterval = null;this.lastHealthCheck = null;this.generateContent = options.generateContent || null;+ this.engagement = options.engagement || null;}async initialize() {@@ -80,6 +81,15 @@ class DailyAutomation {}, { scheduled: false }));+ // Audience comment sync every 4 hours; the service's own taper decides which videos are due+ this.scheduledTasks.set('audience-engagement-sync',+ cron.schedule('0 */4 * * *', async () => {+ if (this.isEnabled) {+ await this.collectAudienceEngagement();+ }+ }, { scheduled: false })+ );+// Start all scheduled tasksthis.scheduledTasks.forEach((task, name) => {task.start();@@ -279,6 +289,25 @@ class DailyAutomation {}}+ async collectAudienceEngagement() {+ if (!this.engagement) return;+ try {+ this.logger.info('Starting audience comment sync...');+ const recentVideos = await this.getRecentlyPublishedVideos(30);+ const results = await this.engagement.syncDueVideos(recentVideos.map(video => ({+ youtubeId: video.youtube_id,+ title: video.title,+ publishedAt: video.published_at,+ productionId: video.production_id || null+ })));+ this.logger.success(`Audience engagement sync completed: ${results.synced} synced, ${results.skipped} skipped, ${results.failed} failed`);+ await this.logAutomationEvent('audience_engagement_sync', 'success', results);+ } catch (error) {+ this.logger.error('Audience engagement sync failed:', error);+ await this.logAutomationEvent('audience_engagement_sync', 'error', { error: error.message });+ }+ }+async weeklyStrategyReview() {try {this.logger.info('Starting weekly strategy review...');diff --git a/test.js b/test.jsindex 59b7c9d..a165577 100644--- a/test.js+++ b/test.js@@ -2,6 +2,7 @@ const { Database } = require('./database/db');const { Logger } = require('./utils/logger');const { CredentialManager } = require('./utils/credential-manager');const { AudienceEngagementService } = require('./utils/audience-engagement-service');+const { DailyAutomation } = require('./schedules/daily-automation');const chalk = require('chalk');const path = require('path');const { ProductionReadinessService } = require('./utils/production-readiness-service');@@ -56,7 +57,8 @@ class SystemTest {{ name: 'Audience Comment Analysis', test: () => this.testAudienceCommentAnalysis() },{ name: 'Audience Idea Mining', test: () => this.testAudienceIdeaMining() },{ name: 'Reply Drafting', test: () => this.testReplyDrafting() },- { name: 'Reply Approval and Posting', test: () => this.testReplyApprovalAndPosting() }+ { name: 'Reply Approval and Posting', test: () => this.testReplyApprovalAndPosting() },+ { name: 'Engagement Sync Schedule', test: () => this.testEngagementSyncSchedule() }];let passed = 0;@@ -2786,6 +2788,38 @@ class SystemTest {await db.close();}}++ async testEngagementSyncSchedule() {+ let captured = null;+ const events = [];+ const fakeDb = {+ getAllRows: async () => [+ { youtube_id: 'vid_sched_1', title: 'Scheduled video', published_at: '2026-08-22T00:00:00.000Z', production_id: 'prod_1' }+ ],+ executeQuery: async () => ({}),+ generateId: prefix => `${prefix}_test`+ };+ const scheduler = new DailyAutomation({}, fakeDb, {+ generateContent: async () => {},+ engagement: {+ syncDueVideos: async videos => {+ captured = videos;+ return { synced: 1, skipped: 0, failed: 0, analyzed: 1 };+ }+ }+ });+ scheduler.logAutomationEvent = async (type, status, data) => { events.push({ type, status, data }); };+ await scheduler.collectAudienceEngagement();+ if (!captured || captured[0].youtubeId !== 'vid_sched_1') throw new Error('The scheduler did not map youtube_id');+ if (captured[0].productionId !== 'prod_1' || captured[0].publishedAt !== '2026-08-22T00:00:00.000Z') {+ throw new Error('The scheduler did not map production/publish fields');+ }+ if (!events.some(event => event.type === 'audience_engagement_sync' && event.status === 'success')) {+ throw new Error('The engagement sweep must log an automation event');+ }+ const noService = new DailyAutomation({}, fakeDb, { generateContent: async () => {} });+ await noService.collectAudienceEngagement(); // must be a silent no-op, not a crash+ }}// Run tests if called directly