This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Telegram bot written in Go that aggregates posts from rationalist blogs (LessWrong.ru, Slate Star Codex, Astral Codex Ten, LessWrong.com). The bot allows users to read random posts or view top posts from these sources.
make run- Run the application locally (requires .env file)make test- Run unit tests with race detectionmake test-integration- Run integration tests (requires .env.test file)make test-coverage- Run tests with coverage reportmake lint- Run golangci-lintmake build- Build the binarymake clean- Clean build artifacts
make go-mod-tidy- Tidy go modulesmake go-mod-download- Download go modules
docker-compose up- Run bot with Redis in containersmake docker-build- Build Docker imagemake docker-run- Run Docker container
Main Entry Point (main.go): Initializes storage (Redis with memory fallback), creates bot instance, and starts message processing loop.
Bot Package (bot/): Contains core bot logic with dependency injection pattern:
bot.go- Main bot struct with Telegram API integrationrandom.go- Random post fetching logictop.go- Top posts functionalitysource.go- Source switching between different blog siteshttp.go- HTTP client wrapperutils.go- Utility functions
Models (models/): Data structures for posts and sources.
Storage (storage/): Pluggable storage interface with Redis and in-memory implementations.
Config (config/): Environment-based configuration parsing.
The codebase uses dependency injection with the Options pattern for testability. The bot supports both polling and webhook modes for Telegram updates. Storage is abstracted behind an interface allowing fallback from Redis to memory cache.
The project includes both unit tests and integration tests. Integration tests use the -tags=integration build flag and require a separate .env.test file. Test data is stored in bot/testdata/ with JSON responses and expected markdown outputs.
Key variables in .env:
TOKEN- Telegram bot token (required)REDIS_URL- Redis connection string (optional, falls back to memory)WEBHOOK- Enable webhook mode vs pollingDEBUG- Enable debug logging
Integration tests require .env.test with test-specific values.