A Telegram bot that provides real-time weather. integrated with OpenClaw
1.5K
A Telegram bot that provides real-time weather information powered by the OpenWeather OneCall 3.0 API. It supports current conditions, multi-day forecasts, hourly forecasts, and weather alerts โ all accessible via Telegram commands or a CLI tool.
The project is built with Python 3.12, aiogram 3.x, and can be easily integrated with OpenClaw for agent automation or LLM pipelines
weather-bot/
โโโ cli/
โ โโโ weather_cli.py # CLI entrypoint
โโโ config/
โ โโโ config.yaml # App configuration (city, units, defaults)
โโโ logs/ # Log output directory
โโโ tests/
โ โโโ test_weather.py # Unit + integration tests (fully mocked)
โ โโโ helpers/
โ โโโ telegram_sender.py # Test helpers
โโโ weather/
โ โโโ bot/
โ โ โโโ main.py # Bot entrypoint (aiogram)
โ โ โโโ handlers.py # Telegram command handlers
โ โโโ core/
โ โ โโโ config.py # Settings loader (YAML + env vars)
โ โ โโโ logging.py # Logger setup
โ โโโ skills/
โ โโโ weather/
โ โโโ client.py # Async OpenWeather API client
โ โโโ formatters.py # Response formatters
โ โโโ schema.py # Tool-call schema handler
โ โโโ skill.py # WeatherSkill core logic
โโโ .env.sample # Environment variable template
โโโ docker-compose.yml
โโโ Dockerfile
โโโ requirements.txt
# 1. Clone the repository
git clone https://github.com/afreisinger/weather-bot.git
cd weather-bot
# 2. Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
Copy the sample file and fill in your credentials:
cp .env.sample .env
| Variable | Description |
|---|---|
TELEGRAM_TOKEN | Your Telegram Bot token |
OPENWEATHER_API_KEY | Your OpenWeather API key |
CONFIG_PATH | (Optional) Custom config file path |
config/config.yamlweather:
default_city: "Buenos Aires"
units: "metric" # metric | imperial | standard
forecast_days: 3 # Default days for /forecast (1โ8)
forecast_hours: 12 # Default hours for /forecast_hourly (1โ48)
export TELEGRAM_TOKEN=your_token
export OPENWEATHER_API_KEY=your_key
python -m weather.bot.main
# Build
docker build -t weather-bot .
# Run
docker run --env-file .env -v $(pwd)/config:/app/config weather-bot
docker compose up --build
The
docker-compose.ymlmounts./configand./logsas volumes and automatically restarts the container on failure.
Query weather directly from your terminal without running the bot:
# Current weather
python -m cli.weather_cli current "London"
# 5-day forecast
python -m cli.weather_cli forecast "Cรณrdoba" --days 5
# Enable debug logging
python -m cli.weather_cli -v current "Tokyo"
| Command | Description |
|---|---|
/weather | Current weather for the default city |
/weather <city> | Current weather for a specific city |
/forecast | 3-day forecast for the default city |
/forecast <city> | 3-day forecast for a specific city |
/forecast <city> <days> | Custom-day forecast (1โ8 days) |
/forecast_hourly | 12-hour forecast for the default city |
/forecast_hourly <city> | 12-hour forecast for a specific city |
/forecast_hourly <city> <hours> | Custom hourly forecast (1โ48 hours) |
/alerts | Active weather alerts for the default city |
/alerts <city> | Active weather alerts for a specific city |
/help | Show all available commands |
Tests are fully mocked โ no real network calls or API keys are required.
# Install dev dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest tests/ -v
# Run with coverage report
pytest tests/ -v --cov=weather --cov-report=term-missing
Telegram User
โ
โผ
[aiogram Handlers] โโโ weather/bot/handlers.py
โ
โผ
[WeatherSkill] โโโ weather/skills/weather/skill.py
โ
โโโโบ [Geocoding API] โโ
โโโโบ [OneCall 3.0 API] โโคโโ weather/skills/weather/client.py
โ (retry, cache, validation)
โผ
[Formatters] โโโ weather/skills/weather/formatters.py
โ
โผ
Formatted string response
WeatherSkill is transport-agnostic โ it can be used by the Telegram bot, the CLI, or any other interface.client.py handles all HTTP communication with in-memory caching and exponential backoff retries.config.py merges config.yaml defaults with environment variable overrides.MIT License. See LICENSEโ for details.
Content type
Image
Digest
sha256:0faa3e639โฆ
Size
53.4 MB
Last updated
6 months ago
docker pull afreisinger/weather-bot