Sehat: Health Tracking Telegram Bot
Project Overview: Sehat (meaning “health” in Hindi/Urdu) is a production-ready Telegram bot for personal health and fitness tracking. Built as a complete rewrite from Go to Python, it features conversational workflows for logging daily metrics, automated reminders, and comprehensive data persistence with SQLAlchemy.
Objectives
- Create a frictionless health tracking experience through messaging
- Eliminate the need for dedicated health tracking apps
- Provide quick data entry and retrieval through natural commands
- Enable long-term health trend analysis
Features
-
User Onboarding:
- Collects date of birth for personalization
- Weight unit preference configuration (kg/lbs)
- Goal weight setting for tracking progress
- Persistent user profile storage
-
Daily Metrics Tracking:
- Weight measurements
- Steps achievement (5k+ goal)
- Sleep quality (8h+ goal)
- Diet adherence tracking
- Cardio activity logging
- Weightlifting session tracking
-
Automated Reminders:
- Daily prompts at 7:10 AM Eastern Time
- Personalized greeting messages
- Gentle nudges to maintain consistency
- Timezone-aware scheduling
-
Weekly Summaries:
- Aggregated statistics for each metric
- Days achieved per goal tracking
- Progress visualization
- Historical trend analysis
-
Production-Ready Deployment:
- Systemd service integration
- Automatic restart on failure
- Git hook-based auto-deployment
- Rotating log files with comprehensive logging
Technology Stack
- Language: Python 3.12+
- Bot Framework: python-telegram-bot (v22.5+)
- ORM: SQLAlchemy with declarative models
- Database: SQLite for persistent storage
- Deployment: systemd service on Linux
- Package Management: uv for fast dependency resolution
- Configuration: Environment variables via dotenv
- Code Quality: Black formatter, type hints, pre-commit hooks
Architecture
The bot follows a clean, modular architecture:
- Conversation Handlers: Separate handlers for onboarding, daily tracking, and weekly summaries
- Database Layer: SQLAlchemy models for User, Daily, and Weekly tables
- Base Handler Pattern: Extensible base class for consistent handler implementation
- Job Queue: Scheduled tasks for automated daily reminders
- Logging: Dual logging to both file and stdout for debugging
Commands
/start- Begin onboarding and create user profile/daily- Log daily health metrics/weekly- View weekly summary report
Design Philosophy
- Minimal Friction: Log metrics in seconds without leaving Telegram
- Privacy First: Self-hosted with local SQLite storage
- Production Ready: Automated deployment, monitoring, and error handling
- Maintainable: Type hints, code formatting, and modular architecture
Key Improvements from Go Version
This Python rewrite introduces several enhancements:
- Conversation State Management: Leverages python-telegram-bot’s built-in conversation handlers
- ORM Integration: SQLAlchemy provides type-safe database operations
- Automated Deployment: Git hooks and systemd integration for seamless updates
- Better Logging: Structured logging with rotation and multiple outputs
- Code Quality Tools: Pre-commit hooks, formatters, and type checking
- Simplified Maintenance: More Pythonic code patterns and better documentation