Here's the design for the clean automation flow for brand monitoring, including time-window logic, report location, an implementation checklist, and cron job adjustments: **Automation Flow Design** The brand monitoring automation will consist of three distinct phases: Daily Collection, Weekly Report Generation, and Final Announcement. All intermediate steps will run silently in the background. 1. **Daily Collection Job (Silent Background)** * **Purpose:** Continuously scrape RSS feeds and social media mentions. * **Frequency:** Runs daily (e.g., once every 24 hours, or more frequently like M-W-F as per existing skill). * **Time-window Logic:** The `collect_rss.py` and `collect_social.py` scripts will use a dynamic lookback window (e.g., 2-3 days prior to the current run) to ensure no articles are missed, accommodating potential delays or infrequent source updates. * **Process:** * Execute `collect_rss.py` to fetch news from configured sources. * Execute `collect_social.py` to gather social media mentions (using Google News RSS `site:` workaround). * Run `pipeline.py` to normalize, deduplicate, score relevance and sentiment, and apply initial filtering. * **Output:** All processed articles/mentions are stored silently in the local operational SQLite database and potentially synced to a Google Sheet for stakeholder viewing. **No messages are sent to Telegram at this stage.** 2. **Weekly Report Generation Job (Silent Background)** * **Purpose:** Compile all collected data for the past week into a structured report. * **Frequency:** Runs once a week (e.g., every Friday morning). * **Time-window Logic:** Queries the local database to retrieve all relevant, processed articles/mentions from the *entire preceding week* (e.g., Monday 00:00 UTC to Friday 23:59 UTC, or as defined for the reporting week). * **Process:** * A dedicated script queries the database for the weekly data. * Aggregates, summarizes, and formats the data according to the specified report structure (Air date, Highlight, Direct Article Link, Sentiment, no dashes). * **Output:** A markdown report file written to `/opt/ai-os/products/ceo/brand-monitoring/reports/-fulbright-weekly.md` (e.g., `2026-07-19-fulbright-weekly.md`). 3. **Final Announcement Job (Telegram & Report File)** * **Purpose:** Announce the weekly digest to the Telegram thread. * **Frequency:** Runs immediately after the Weekly Report Generation Job successfully completes. * **Process:** * Execute `alert_dispatcher.py`, which is modified to read the *newly generated weekly report file*. * Constructs a single, comprehensive digest message based on the report's content, prioritizing Negative -> Neutral -> Positive sentiment. * Dispatches this message to Telegram thread #3688. This is the **only** message sent to the Telegram thread for the automated brand monitoring workflow. * **Output:** One Telegram message to thread #3688 containing the weekly digest. **Implementation Checklist** * **Modify `collect_rss.py` & `collect_social.py`:** Implement dynamic lookback window logic. * **Modify `pipeline.py`:** Ensure it stores processed data without sending immediate Telegram notifications. * **Create Weekly Report Generation Script:** Develop a script to query the database for weekly data and generate a markdown report file at `/opt/ai-os/products/ceo/brand-monitoring/reports/`. * **Modify `alert_dispatcher.py`:** Update its logic to read the weekly report file and dispatch a single, consolidated message to Telegram thread #3688. * **Verify Report Format:** Ensure the generated markdown report and Telegram digest adhere to the specified format (Air date, Highlight, Direct Article Link, Sentiment, no dashes). **Cron/Job Adjustments** Assuming cron jobs are managed via shell scripts (e.g., `/root/.hermes/scripts/`): 1. **Daily Collection Cron Job (e.g., `brand_daily_collection.sh`):** * **Command:** `python3 /opt/ai-os/products/ceo/brand-monitoring/shared/workflows/collect_rss.py && python3 /opt/ai-os/products/ceo/brand-monitoring/shared/workflows/collect_social.py && python3 /opt/ai-os/products/ceo/brand-monitoring/shared/workflows/pipeline.py > /var/log/brand_daily_collection.log 2>&1` * **Cron Schedule:** `0 4 * * *` (Runs daily at 4 AM UTC, adjust to desired local daily time and convert to UTC). 2. **Weekly Report & Announcement Cron Job (e.g., `brand_weekly_report_and_announce.sh`):** * **Command:** `python3 /opt/ai-os/products/ceo/brand-monitoring/shared/workflows/generate_weekly_report.py && python3 /opt/ai-os/products/ceo/brand-monitoring/shared/workflows/alert_dispatcher.py --report-path /opt/ai-os/products/ceo/brand-monitoring/reports/$(date +\%Y-\%m-\%d)-fulbright-weekly.md > /var/log/brand_weekly_report.log 2>&1` * *(Note: `generate_weekly_report.py` is a placeholder for the script that would generate the weekly report. The date command is illustrative for passing the correct filename).* * **Cron Schedule:** `0 5 * * 5` (Runs every Friday at 5 AM UTC, adjust to run after the last daily collection for the week and convert to UTC. This is slightly after the daily job, allowing it to complete its last run for the week). **Summary of Accomplishments:** * Designed a three-stage automated brand monitoring workflow for daily collection, weekly report generation, and final Telegram announcement. * Defined time-window logic for each stage, emphasizing dynamic lookbacks for daily collection and full-week aggregation for reports. * Specified that the weekly report file will be written to `/opt/ai-os/products/ceo/brand-monitoring/reports/` with a dated filename. * Ensured that only the final weekly digest is sent to Telegram thread #3688, maintaining a silent background operation for all intermediate steps. * Provided a clear implementation checklist and example cron job configurations.