Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calorie Bot

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.

Setup

  1. Create a Telegram bot

    • Open Telegram, message @BotFather
    • Send /newbot, follow the prompts, copy the token it gives you
  2. Get an OpenAI API key

  3. 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.

  4. Configure

    cp .env.example .env

    Edit .env with your values:

    TELEGRAM_BOT_TOKEN=123456:ABC...
    OPENAI_API_KEY=sk-...
    DATABASE_URL=dbname=calorie_bot user=YOUR_MAC_USERNAME host=localhost
    
  5. Run

    uv run bot.py

    Leave this running. Open your bot in Telegram and send /start.

Usage

  • 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)

Keeping it running

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.

Notes on accuracy

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.

About

Telegram bot that logs meals from photos, voice, or text, estimates calories and macros with GPT-4o, and tracks daily totals against BMR/TDEE goals.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages