- Build the image (uses uv for dependency management):
docker build -t tt-bot . - Create a
.envfile based on.env.exampleand fill in the required settings.- Always set:
BOT_TOKEN - If you will use a local Telegram Bot API server (recommended with Docker Compose below): keep
TG_SERVER=http://telegram-bot-api:8081and addTELEGRAM_API_IDandTELEGRAM_API_HASHto your.env. - If you will use the public Telegram API endpoint without the local server: set
TG_SERVER=https://api.telegram.organd you do not needTELEGRAM_API_ID/HASH.
- Always set:
- Run the container with the environment file:
Note: When running a single container like this, ensure
docker run --rm --env-file .env tt-bot
TG_SERVERis reachable from the container. If you keptTG_SERVER=http://telegram-bot-api:8081, you must also run atelegram-bot-apicontainer and place both on the same network, or switchTG_SERVERtohttps://api.telegram.org.
Docker Compose brings up three services by default:
bot– this project’s Telegram bottelegram-bot-api– a local Telegram Bot API server (faster and avoids public rate limits)db– optional PostgreSQL database used by the bot (enabled by default in the compose file)
Before starting, copy .env.example to .env and set at least these variables:
- BOT_TOKEN
- TELEGRAM_API_ID and TELEGRAM_API_HASH (required for the
telegram-bot-apiservice) - Optionally adjust
DB_URLif you don’t want to use the compose-managed Postgres
To run everything:
docker compose upOnly the bot service will start if you specify it explicitly:
docker compose up botIf you start only bot, ensure TG_SERVER points to a reachable endpoint (either also start telegram-bot-api or set TG_SERVER=https://api.telegram.org).
Notes:
- By default the local Bot API listens on port 8081 inside the compose network and isn’t exposed to your host. The bot talks to it via
TG_SERVER=http://telegram-bot-api:8081. If you want to access it from your host for debugging, add aports:mapping to thetelegram-bot-apiservice (e.g.- "8081:8081"). - The Compose file also defines a PostgreSQL service. You can override its default credentials by setting
POSTGRES_USER,POSTGRES_PASSWORD, andPOSTGRES_DBin your.envor shell environment.
This project uses uv for dependency management. To run locally without Docker:
curl -LsSf https://astral.sh/uv/install.sh | sh
# Ensure ~/.local/bin is on your PATH, then:
uv sync
uv run python main.pyTips for local runs:
- Create a
.envfrom.env.exampleand setBOT_TOKEN. - If you are not running a local Telegram Bot API server, set
TG_SERVER=https://api.telegram.org. - If you are running the compose stack for the local Bot API and DB concurrently, you can keep
TG_SERVER=http://telegram-bot-api:8081andDB_URL=postgresql+asyncpg://postgres:postgres@db/ttbot-db.
Database initialization: the app will auto-create tables on startup using SQLAlchemy; no manual migrations are needed for first run.