DEV Community

Mohammad Sorouri
Mohammad Sorouri

Posted on

How to Build an AI‑Powered Daily News Digest on Telegram with RSS

How to Build an AI‑Powered Daily News Digest on Telegram using RSS

TL;DR – Pull headlines with feedparser, let an LLM create a concise summary, optionally turn it into audio, and push the result to a Telegram bot. The whole pipeline fits in a single Python script, can be Docker‑ized, and runs on a cheap VPS. For a zero‑maintenance alternative, check out RSSReaderAI and its Telegram bot @RSS_READER_AI_Bot.


Why combine RSS, AI, and Telegram?

  • RSS gives you a machine‑readable stream of fresh articles from any site that supports it.
  • AI (LLMs) can distill dozens of headlines into a 2‑3‑minute read, highlighting the most relevant points.
  • Telegram provides push notifications, rich media (audio, markdown), and a familiar UI for developers and non‑technical users alike.

Together they solve the classic "news overload" problem while keeping the workflow fully programmable.


Architecture Overview

graph LR
    A[RSS Sources] -->|fetch| B[Scheduler (cron)]
    B --> C[FeedParser (Python)]
    C --> D[LLM Summarizer (OpenAI)]
    D --> E[Audio Generator (ElevenLabs)]
    D --> F[Text Digest]
    E --> G[Telegram Bot]
    F --> G
Enter fullscreen mode Exit fullscreen mode

The diagram shows the linear flow from raw feeds to a Telegram message. Replace the LLM or audio provider with any service you prefer.


Step‑by‑Step Implementation

1. Gather feeds with feedparser

import feedparser

def fetch_entries(urls: list[str]) -> list[dict]:
    entries = []
    for url in urls:
        feed = feedparser.parse(url)
        entries.extend(feed.entries[:5])  # limit to recent 5 per feed
    return entries
Enter fullscreen mode Exit fullscreen mode

Add your favourite tech, finance, or niche RSS URLs to the urls list.

2. Summarize with OpenAI (or any LLM)

import os, openai
openai.api_key = os.getenv("OPENAI_API_KEY")

def summarize_articles(entries: list[dict]) -> str:
    # Build a prompt with titles + short descriptions
    prompt = "Summarize the following news items in 3‑5 bullet points, each no longer than 20 words.\n\n"
    for e in entries:
        title = e.get('title', '').replace('\n', ' ')
        summary = e.get('summary', '').replace('\n', ' ')
        prompt += f"- {title}: {summary}\n"
    response = openai.ChatCompletion.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": prompt}],
        temperature=0.5,
        max_tokens=300,
    )
    return response.choices[0].message.content.strip()
Enter fullscreen mode Exit fullscreen mode

The function returns a markdown‑ready bullet list.

3. (Optional) Convert the summary to audio

import requests, base64

def text_to_speech(text: str) -> bytes:
    api_key = os.getenv("ELEVENLABS_API_KEY")
    url = "https://api.elevenlabs.io/v1/text-to-speech/EXAMPLE_VOICE"
    payload = {"text": text, "model_id": "eleven_monolingual_v1"}
    headers = {"xi-api-key": api_key, "Content-Type": "application/json"}
    r = requests.post(url, json=payload, headers=headers)
    r.raise_for_status()
    return r.content  # MP3 bytes
Enter fullscreen mode Exit fullscreen mode

Store the MP3 in a temporary file or upload it directly to Telegram.

4. Send the digest via a Telegram bot

from telegram import Bot
from telegram.constants import ParseMode

BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")  # your private chat or channel ID
bot = Bot(token=BOT_TOKEN)

def send_digest(text: str, audio: bytes | None = None):
    bot.send_message(chat_id=CHAT_ID, text=text, parse_mode=ParseMode.MARKDOWN)
    if audio:
        bot.send_audio(chat_id=CHAT_ID, audio=audio, filename="daily_digest.mp3")
Enter fullscreen mode Exit fullscreen mode

Combine everything in a main() function and schedule it with cron or a cloud scheduler.

5. Deploy & schedule

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY *.py .
CMD ["python", "digest.py"]
Enter fullscreen mode Exit fullscreen mode

Create a crontab entry like 0 7 * * * docker run --rm rss-digest to get a 7 AM digest every weekday.


Tips for Scaling & Maintenance

  • Cache feeds for 10‑15 minutes to avoid hitting rate limits.
  • Error handling: wrap API calls in try/except and send a fallback message if something fails.
  • Dynamic feed list: store URLs in a tiny SQLite DB or a Google Sheet; the script can pull them at runtime.
  • Use RSSReaderAI if you prefer a managed solution: it aggregates, summarizes, and generates audio automatically. Just add the bot @RSS_READER_AI_Bot to your Telegram and let it do the heavy lifting.

🎯 Call to Action

Ready to stop scrolling endless feeds and start listening to a concise AI‑generated briefing? Try the RSSReaderAI platform today, or spin up the script above on your own server. Either way, you’ll get a daily, AI‑curated news digest straight to Telegram – and more time for the code you love.

Top comments (0)