A Telegram bot that logs your food from photos, voice notes, or typed text, estimates calories with GPT-4o, and lets you query your daily totals.
-
Create a Telegram bot
- Open Telegram, message @BotFather
- Send
/newbot, follow the prompts, copy the token it gives you
-
Get an OpenAI API key
-
Postgres Uses your local Postgres (Homebrew
postgresql@16). One-time setup:psql postgres -c "CREATE DATABASE calorie_bot;"The bot creates its tables automatically on first run.
-
Configure
cp .env.example .env
Edit
.envwith your values:TELEGRAM_BOT_TOKEN=123456:ABC... OPENAI_API_KEY=sk-... DATABASE_URL=dbname=calorie_bot user=YOUR_MAC_USERNAME host=localhost -
Run
uv run bot.py
Leave this running. Open your bot in Telegram and send
/start.
- Send a photo of your meal → bot identifies items + estimates calories
- Send a voice note describing what you ate → transcribed and estimated
- Type a description, e.g.
2 rotis, dal, and a bowl of rice→ estimated - Every estimate shows a breakdown with a ✅ Save / ❌ Discard button before it's logged, so nothing gets recorded without your confirmation
- Entries are auto-tagged morning/lunch/evening by time of day, and repeat foods (same name + same portion) reuse your previously confirmed calorie/macro value instead of a fresh AI guess each time (marked ♻️) — keeps counts consistent
/today— today's log grouped by meal, with calorie + macro totals/date 2026-07-20— log for a specific date/week— totals for the last 7 days/delete <id>— remove a wrongly logged entry (id shown in/today)/setgoal 2000— set a daily calorie goal manually/profile 70 175 28 m moderate lose— weight_kg, height_cm, age, sex, activity (sedentary/light/moderate/active/very_active), goal (lose/maintain/gain) — auto-computes your daily calorie target from BMR/TDEE and sets it as your goal/logweight 70.5— log today's weight/weight— see your weight trend- Proactive check-ins at 9:30am (morning), 2pm (lunch), 8pm (evening) IST asking if you've eaten — skipped automatically for any meal you've already logged that day
/reminders on//reminders off— toggle these check-ins (on by default)
This runs as a foreground process on your Mac. To keep it alive in the background:
nohup uv run bot.py > bot.log 2>&1 &Stop it later with pkill -f "bot.py", or check bot.log for errors.
Calorie estimates are AI-generated best guesses based on what's visible/described — treat them as approximate, not lab-precise. The confirm step exists so you can catch obviously wrong reads before they're saved; if quantity/items are off, discard and resend a corrected text description instead.
Data is stored in a local Postgres database (calorie_bot), never leaves your machine
except for the OpenAI API calls needed to analyze each photo/voice note/text.