A Telegram fitness tracking and coaching bot that helps users monitor their training, sleep, stress levels, and overall well-being.
ISLOB Bot is a comprehensive fitness tracking solution that interacts with users through Telegram. The bot collects data about users' training sessions, sleep patterns, stress levels, and general well-being through regular check-ins and quizzes. It provides personalized statistics, visualizations, and insights to help users optimize their fitness journey.
- π Morning Quizzes: Daily check-ins to track sleep quality, weight, and overall feelings
- πͺ Training Tracking: Log training sessions with details on duration, intensity, and discomfort
- π Post-Training Feedback: Collect data on stress and soreness after workouts
- π Automated Notifications: Customizable reminders for morning check-ins and training sessions
- π Statistics Visualization: Visual representation of sleep patterns, stress levels, and training intensity
- π§ AI-Powered Insights: Utilizes OpenAI's GPT models to analyze fitness data and provide personalized recommendations
- π Backend: Python with SQLAlchemy ORM
- ποΈ Database: PostgreSQL
- π€ Bot Framework: python-telegram-bot
- π Data Visualization: Matplotlib, Seaborn, Pandas
- π§ AI Integration: OpenAI API (GPT models)
- β±οΈ Scheduling: APScheduler
- π Database Migrations: Alembic
- Python 3.8+
- PostgreSQL
- Telegram Bot Token (from BotFather)
- OpenAI API Key
-
Clone the repository:
git clone https://github.com/YukihiroSM/islobbot.git cd islobbot -
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt -
Create a
.envfile in the project root with the following variables:TOKEN=your_telegram_bot_token DATABASE_URL=postgresql://username:password@localhost/islobbot ADMIN_CHAT_IDS=["your_telegram_chat_id"] OPENAI_API_KEY=your_openai_api_key OPENAI_ASSISTANT_ID=your_openai_assistant_id -
Initialize the database:
python init_db.py -
Run the bot:
python main.py
The database consists of several main tables:
- π€ Users: Stores user information and preferences
- π NotificationPreference: Manages notification settings for each user
- ποΈββοΈ Training: Records training sessions with details
- π MorningQuiz: Stores daily check-in data
The bot implements several conversation flows:
- π― Purpose: Onboards new users and collects initial information
- π Flow:
- Starts with the
/startcommand - Collects the user's full name
- Asks for preferred morning notification time
- Sets up morning notification preferences
- Directs user to the main menu
- Starts with the
- π― Purpose: Daily check-in for sleep, weight, and well-being
- π Flow:
- Triggered by a scheduled morning notification
- Asks how the user feels (1-10 scale)
- Collects sleep duration (hours:minutes)
- Records user's current weight
- Asks if the user plans to train today
- If yes, collects expected training time
- Creates training notifications if needed
- Saves all data to the database
- π― Purpose: Initiates a training session
- π Flow:
- Triggered when user selects "Start Training"
- Asks for pre-training feeling (1-10 scale)
- Records training start time
- Sends training PDF document (personalized or default)
- Updates notification statuses
- Provides "End Training" button
- π― Purpose: Completes a training session and collects feedback
- π Flow:
- Triggered when user selects "End Training"
- Asks for training hardness rating (1-10 scale)
- Asks if user experienced any pain/discomfort
- If yes, notifies admin users about the issue
- Records training duration and end time
- Updates notification statuses
- Displays motivational message
- Returns to main menu
- π― Purpose: Follow-up on stress and soreness levels after training
- π Flow:
- Triggered by scheduled notification the day after training
- Asks for stress level (1-10 scale)
- Asks if user is experiencing muscle soreness
- Records responses in the database
- Returns to main menu
- π― Purpose: Allows admins to assign training PDF documents to users
- π Flow:
- Triggered when admin selects "Training PDF"
- Displays list of users
- Admin selects a user
- Admin uploads PDF document
- System assigns PDF to selected user
- Notifies user about new training document
- Returns to main menu
The statistics system generates visualizations with the following characteristics:
- π Sleep data is displayed as a bar chart
- π Stress, hardness, and feelings are displayed as line plots
- π All plots use day.month (DD.MM) format for x-axis labels
The statistics system collects and analyzes several types of user data:
- π΄ Sleep Duration: Tracked daily through morning quizzes
- π Feelings/Well-being: Self-reported ratings on a 1-10 scale
- πͺ Training Hardness: User-reported difficulty of each workout
- π Stress Levels: Post-training stress measurements
- π΄ Muscle Soreness: Tracked after training sessions (marked with X on hardness plots)
The system generates a comprehensive visualization with four main components arranged in a 2x2 grid:
- π΄ Sleep Chart (Bottom Left): Bar chart displaying sleep duration in hours for each day
- π Stress Chart (Top Left): Line plot showing stress levels over time
- πͺ Training Hardness Chart (Top Right): Line plot with special X markers for sessions that caused muscle soreness
- π Feelings Chart (Bottom Right): Line plot tracking overall well-being
All charts use a consistent date format (DD.MM) on the x-axis for easy readability, and the system employs a clean, whitegrid theme with pastel colors for improved visual aesthetics.
Statistics can be generated for different time periods:
- π Weekly: Data from the past 7 days
- π Monthly: Data from the past 28 days
The statistics system leverages OpenAI's Assistant API to analyze the collected data and provide personalized insights about:
- ποΈββοΈ Training patterns and their effectiveness
- π΄ Sleep quality and its impact on performance
- π Stress levels and recovery patterns
- π Overall fitness progress and trends
These AI-generated insights are presented alongside the statistical visualizations to provide users with a comprehensive understanding of their fitness journey.
The visualization system is built using:
- πΌ Pandas: For data manipulation and analysis
- π Matplotlib: For creating the visualization framework and grid layout
- π¨ Seaborn: For enhanced visual aesthetics with a pastel color palette
- π§ OpenAI API: For AI-powered analysis of fitness data
The system follows a consistent visual style with a clean, whitegrid theme and pastel colors for improved readability and user experience. The implementation specifically uses bar charts for sleep data visualization while maintaining line plots for other metrics, as per the project's design preferences.
The system leverages an existing OpenAI Assistant for analyzing fitness metrics. This integration requires:
-
π€ Assistant Setup: An OpenAI Assistant must be configured specifically for fitness data analysis with the following capabilities:
- Understanding training patterns and their impact on user well-being
- Analyzing sleep quality and its correlation with training performance
- Monitoring stress levels and suggesting recovery strategies
- Tracking overall progress and providing motivational feedback
-
βοΈ Environment Configuration: The Assistant ID must be configured in the
.envfile:OPENAI_ASSISTANT_ID=your_openai_assistant_id -
π Data Processing Overview: The system collects user data from morning quizzes and training sessions, which is then used to generate personalized insights and recommendations.
- π― Personalized Insights: The AI analyzes individual patterns that might not be obvious from charts alone
- π Holistic Analysis: Considers the relationship between different metrics (sleep, stress, training intensity)
- π‘ Actionable Recommendations: Provides specific suggestions to improve training outcomes
- π Motivational Support: Offers encouragement based on progress and achievements
To use this feature, you must configure an OpenAI Assistant and set the OPENAI_ASSISTANT_ID in your .env file.
The project includes Docker configuration for easy deployment:
- Build and run with Docker Compose:
docker-compose up -d
This will start the bot and PostgreSQL database in containers.
The project uses Alembic for database migrations:
# Create a new migration
alembic revision --autogenerate -m "description"
# Apply migrations
alembic upgrade head
The project follows PEP 8 style guidelines. You can format your code using Black:
black .