safeeyes
Protect your eyes from eye strain using this simple and beautiful, yet extensible break reminder
翻訳待ち
No updates detected yet. GitHub releases will appear here.
Calorie tracking bot in Telegram.
翻訳待ち
Loading the full README.
Read the full README ↗A Telegram bot for conversational calorie tracking with AI-powered food estimation.
Describe what you ate in natural language, and TeleCal estimates calories, protein, fat, fiber and added sugar using AI (OpenAI, Anthropic, or Google Gemini). Each user picks which macros their replies show.
/ with a Request access button that deep-links into the bot/appFEATURE_LOCAL_FOOD_DB.# Clone the repository
git clone https://github.com/yourusername/telecal.git
cd telecal
# Install dependencies
bun install
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
Edit .env with your settings:
# Required
TELEGRAM_BOT_TOKEN=your_bot_token
# Admin users (comma-separated Telegram IDs)
ADMIN_USERS=123456789
# AI Providers (at least one required)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AIza...
# Web server for Mini App
APP_URL=http://localhost:3000
PORT=3000
# Feature flags
FEATURE_CACHING=true
FEATURE_LOCAL_FOOD_DB=false
# Development (with hot reload)
bun run dev
# Production
bun run start
| Command | Description |
|---|---|
/start | Welcome message and command list |
/log | Start logging food |
/foods | Save foods with their label values (paste a table, or /foods add) |
/today | View today's calories and macros |
/week | View past 7 days |
/month | View past 30 days |
/edit | Edit a logged entry |
/delete | Delete a logged entry |
/settings | Change AI provider, calorie and protein goals, which macros to show, reminders |
/pending | View entries awaiting AI processing |
/usage | View your own AI token usage |
/admin | Manage allowed users and access requests, view AI usage and cost, backfill macros (admin only) |
Food descriptions are sent to whichever AI provider the user has selected in
/settings (OpenAI, Anthropic, or Google) to estimate calories and macros.
The one-off /admin backfill-macros command sends the descriptions of items with a macro still missing (logged before that macro existed, or skipped by the model) to the admin's selected provider, not each user's. Its PostHog events carry token counts, cost and latency but no meal text, whatever each user's Meal Text Sharing setting.
TeleCal disables server-side retention where the provider offers the option —
OpenAI calls are made with store: false, so requests are not kept in the
OpenAI organization's logs. Providers may still retain request content
separately for abuse monitoring under their own policies.
Calorie data itself is stored in TeleCal's local SQLite database.
TeleCal uses PostHog Cloud (US region) for error tracking and analytics. Decisions and reasoning are in ADR 0001. PostHog receives:
Users are identified by an HMAC-SHA256 of their Telegram ID, keyed with a
server-side secret (POSTHOG_ID_SECRET). Raw Telegram IDs, usernames and names
are never sent, and no person properties are set. Every event carries an
environment tag (production or development).
Meal text opt-out. /settings → Meal Text Sharing (on by default,
users.analytics_content) keeps a user's text out of PostHog: their
$ai_generation events drop $ai_input, $ai_output_choices and
$ai_error, and their error reports keep the error type and stack frames but
not the message. Token counts, cost and latency are still sent. Errors not
tied to a user (process-level crashes) are sent as they are.
Existing users were told with a one-time message (/admin announce-privacy);
/start and the landing page FAQ link to the same summary.
Deleting a user's data. On request, run /admin posthog-id <telegram_id>
to get the user's PostHog ID, then in PostHog open People, search for that
ID, and delete the person. Deleting a person also deletes their events.
/log to start a sessionWith saved foods, a meal made only of them is logged straight from their labels.
src/web/public/ holds the landing page's images. To regenerate them (macOS, needs Google Chrome):
scripts/screenshots/ as shot-log, shot-today and shot-charts (any image format).bash scripts/build-landing-assets.sh. It renders og.png from scripts/og.html and writes 720 px JPEGs.src/web/public/.# Run all tests
bun test
# Run tests in a specific directory
bun test src/ai
# Run a specific test file
bun test src/db/repositories/users.test.ts
src/
├── index.ts # Entry point
├── config.ts # Environment configuration
├── bot/ # Telegram bot
│ ├── commands/ # Command handlers
│ ├── conversations/# Log flow state machine
│ └── middleware/ # Allowlist access control
├── ai/ # AI service layer
│ ├── service.ts # Provider abstraction
│ └── providers/ # OpenAI, Anthropic, Gemini
├── db/ # SQLite database
│ ├── schema.sql # Database schema
│ └── repositories/ # Data access layer
├── web/ # Landing page and Mini App web server
│ ├── server.ts # Bun HTTP server
│ ├── auth.ts # Telegram auth validation
│ ├── public/ # Landing page images (served at /assets/*)
│ └── views/ # landing.html, app.html
└── jobs/ # Background jobs
├── reminders.ts # Daily notifications
└── retry-pending.ts # Retry failed AI calls
MIT