Skip to main content

Hacker News Bot

A Telegram bot that monitors Hacker News for trending articles, generates AI-powered summaries of the discussions, and delivers them straight to your Telegram chat.

Features

  • RSS feed monitoring — fetches top stories from hnrss.org filtered by minimum points
  • AI-powered summaries — uses OpenAI to distill HN comment threads into concise, structured articles
  • Telegraph publishing — creates readable long-form pages on Telegraph
  • Telegram notifications — sends formatted messages with links to the original article, HN discussion, and the generated summary
  • Redis deduplication — tracks processed entries to avoid sending duplicate notifications
  • Batch or service execution — process one feed batch for cron, or continuously poll for new entries
  • Concurrent processing — handles multiple articles in parallel with configurable concurrency limits
  • Retry with backoff — automatically retries transient HTTP failures

How It Works

hnrss.org RSS feed
        │
        ▼
  Filter by points
        │
        ▼
  Fetch HN comments ──► HTML → Markdown
        │
        ▼
  OpenAI summarisation
        │
        ▼
  Publish to Telegraph
        │
        ▼
  Notify via Telegram

Quick Start

Prerequisites

Install & Run

# Clone the repository
git clone https://github.com/narumiruna/hnbot.git
cd hnbot

# Install dependencies
uv sync

# Configure environment variables
cp .env.example .env
# Edit .env and fill in the required values

# Process one feed batch
uv run hnbot

# Or keep polling for new entries
uv run hnbot serve

hnbot and hnbot main process one feed batch and exit. hnbot serve immediately processes the current feed, then polls again after each completed batch. Redis prevents successfully processed entries from being sent again.

The service uses FEED_POLL_INTERVAL_SECONDS by default. Override it for one invocation with uv run hnbot serve --poll-interval 5; the interval must be at least one second.

Install from PyPI

pip install hnbot

Docker

Docker Compose is the recommended service setup. It builds hnbot, runs hnbot serve, and keeps Redis deduplication data in a named volume:

cp .env.example .env
# Edit .env and fill in the required values

docker compose up --build -d
docker compose logs -f hnbot

Stop the services without deleting Redis data:

docker compose down

To build or run the hnbot image without Compose, configure REDIS_HOST to a Redis server reachable from the container:

docker build -t hnbot .
docker run --env-file .env hnbot

# Run the image as a continuous service
docker run --env-file .env hnbot serve

Configuration

All settings are loaded from environment variables (or a .env file). See .env.example for the full template.

Required

Variable Description
OPENAI_API_KEY OpenAI API key
BOT_TOKEN Telegram bot token
CHAT_ID Telegram chat ID to receive notifications

Optional

Variable Default Description
OPENAI_BASE_URL (OpenAI default) Custom OpenAI-compatible API endpoint
OPENAI_MODEL gpt-5-mini LLM model to use for summarisation
ARTICLE_LANG Traditional Chinese (台灣正體中文) Output language for generated articles
LOGFIRE_TOKEN Logfire token for observability
REDIS_HOST localhost Redis host
REDIS_PORT 6379 Redis port
REDIS_DB 0 Redis database number
FEED_POINTS 100 Minimum HN points threshold for feed entries
HTTP_TIMEOUT_SECONDS 10.0 HTTP request timeout (seconds)
HTTP_USER_AGENT hnbot/0.0.0 HTTP User-Agent header
COMMENTS_FETCH_CONCURRENCY 1 Max parallel comment fetches
COMMENTS_FETCH_MIN_INTERVAL_SECONDS 2.0 Minimum delay between HN comment request starts
COMMENTS_FETCH_429_COOLDOWN_SECONDS 30.0 Global cooldown after an HN 429 response without Retry-After
ARTICLE_PIPELINE_CONCURRENCY 3 Max parallel article generation tasks
CHUNK_SIZE 200000 Max characters per chunk for LLM processing
BATCH_SLEEP_SECONDS 0.5 Delay before processing a batch
FEED_POLL_INTERVAL_SECONDS 30.0 Delay between completed batches in service mode (minimum 1.0)

Development

# Install all dependencies (including dev)
uv sync

# Run the full development gate (format → lint → type-check → test)
just all

# Or run individual steps
just format   # ruff format
just lint     # ruff check --fix
just type     # ty check
just test     # pytest with coverage

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hnbot-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hnbot-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file hnbot-0.1.0.tar.gz.

File metadata

  • Download URL: hnbot-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hnbot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 365325947f915d035741d5a692316b1989825c9c18915613596379a3f6ce64fe
MD5 fd3ca58a4067981e7c25bd3a16b3d3b5
BLAKE2b-256 dd918679c03f6b26ab6a06cf2b1a401f9c70bfeba58133ca3efaf685e4bea91f

See more details on using hashes here.

File details

Details for the file hnbot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hnbot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hnbot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8037dc8ace6674e56166df015ed4c543508c4ba12397ba0a7a547fb0b4f19e3
MD5 f9e2b0599fa92a88a133ceb125673325
BLAKE2b-256 065b7cb7bafd2881a9d215c8518081bd9b3ba687c0cbbd9fd2a6b7df52ab370b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page