Skip to content

Latest commit

Β 

History

History
91 lines (75 loc) Β· 3.46 KB

File metadata and controls

91 lines (75 loc) Β· 3.46 KB

Calbot 🍽️

A personal Telegram calorie tracker powered by Claude AI. Send a text description or a photo of your food β€” the bot estimates calories and macronutrients (protein, fat, carbs) and logs them. Ask it what you've eaten today or over the last week.

Features

  • Text & photo input β€” describe your meal or snap a photo; nutrition labels are also supported
  • Calories + macros β€” estimates kcal, protein, fat, and carbohydrates per meal
  • Claude vision β€” photo analysis via Claude Haiku
  • Clarifying questions β€” when Claude needs more info it asks; /cancel to abort
  • Persistent log β€” SQLite, survives restarts
  • /today β€” today's meals with calorie and macro totals; shows progress vs daily targets when a profile is set
  • /history β€” 7-day summary grouped by date with goal icons (βœ… on track, ⚠️ over, ❌ under)
  • /undo β€” remove the last logged meal
  • /settings β€” toggle visible nutrients, enable/disable daily reminders, choose language
  • /profile β€” guided setup for weight, height, age, sex, activity level, and goal; computes daily calorie & macro targets via Mifflin-St Jeor
  • Multi-language β€” full i18n for English, German, and Russian (UI, keyboard, Claude responses)
  • Daily reminders β€” opt-in nudge at 20:00 CET with a Claude-generated message in your language
  • Allowlist β€” only authorised Telegram user IDs can interact
  • Systemd service β€” auto-restarts on crash, survives reboots
  • CI/CD β€” pytest runs on every push; deploys to production only if tests pass

Tech stack

Layer Choice
Bot framework python-telegram-bot 22
AI Anthropic Claude Haiku (claude-haiku-4-5-20251001)
Database SQLite via aiosqlite
Runtime Python 3.11+, polling mode
Hosting Ubuntu 22, systemd
CI/CD GitHub Actions

Project structure

calbot/
β”œβ”€β”€ main.py                  # entry point β€” wiring, allowlist, keyboard, daily reminders
β”œβ”€β”€ handlers/
β”‚   β”œβ”€β”€ food.py              # Telegram handlers (text, photo, today, history, cancel, undo, settings)
β”‚   └── profile.py           # /profile ConversationHandler (guided setup for daily targets)
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ claude.py            # Claude API + conversation state + daily nudge generation
β”‚   β”œβ”€β”€ nutrition.py         # Mifflin-St Jeor daily target calculations
β”‚   └── database.py          # SQLite CRUD (meals, settings, profiles)
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ i18n.py              # translations (EN/DE/RU) and language helpers
β”‚   β”œβ”€β”€ helpers.py           # shared utilities (language resolution, etc.)
β”‚   └── photos.py            # photo download β†’ base64
β”œβ”€β”€ tests/                   # 153 pytest tests, fully mocked
└── calbot.service           # systemd unit file

Setup

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Create a .env file:

BOT_TOKEN=<from @BotFather>
ANTHROPIC_API_KEY=<from console.anthropic.com>
ALLOWED_USER_IDS=<comma-separated Telegram user IDs>
LOG_LEVEL=INFO

Run:

python main.py

Run tests:

pip install -r requirements-dev.txt
pytest

Deployment

Copy calbot.service to /etc/systemd/system/, create .env at /opt/calbot/.env, then:

systemctl daemon-reload
systemctl enable --now calbot
journalctl -u calbot -f

See CLAUDE.md for full deployment and CI/CD setup instructions.