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

Metadata

Release files for hnbot 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hnbot 0.1.0
File Size Uploaded
hnbot-0.1.0.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hnbot 0.1.0
File Interpreter ABI Platform
hnbot-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.9 kB

Release files / hnbot-0.1.0.tar.gz

Download URL hnbot-0.1.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
365325947f915d035741d5a692316b1989825c9c18915613596379a3f6ce64fe
BLAKE2b-256 checksum
How to use checksums
dd918679c03f6b26ab6a06cf2b1a401f9c70bfeba58133ca3efaf685e4bea91f
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / hnbot-0.1.0-py3-none-any.whl

Download URL hnbot-0.1.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8037dc8ace6674e56166df015ed4c543508c4ba12397ba0a7a547fb0b4f19e3
BLAKE2b-256 checksum
How to use checksums
065b7cb7bafd2881a9d215c8518081bd9b3ba687c0cbbd9fd2a6b7df52ab370b
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page