An intelligent Telegram bot for nutrition and calorie tracking using artificial intelligence and FatSecret database.
- Automatic Analysis: Describe your meal in natural language, and the bot will automatically recognize ingredients
- Meal Type Support: Breakfast, lunch, dinner, snacks
- Accurate Calculation: Calories, proteins, fats, carbohydrates, and micronutrients
- FatSecret Database: Using a large food database for accurate data
- Daily Statistics: Detailed nutrient analysis for today
- Weekly Statistics: Nutrition overview for current and previous week
- Goal Progress: Visual indicator of daily calorie goal achievement
- Macronutrient Analysis: Calorie distribution by proteins, fats, and carbohydrates
- Today's Meals: Quick access to today's meals
- Recent Records: View and edit the last 100 meals
- Type Change: Ability to change meal type
- Description Editing: Update meal description
- Record Deletion: Safe meal deletion with confirmation
- Calorie Goals: Setting and tracking daily calorie goals
- Progress Bar: Visual representation of goal progress
- Flexible Settings: Ability to change or delete goals
The bot uses OpenAI for:
- Product Recognition: Natural food description analysis
- Quantity Determination: Automatic portion weight determination
- Data Structuring: Converting descriptions into structured data for search
- Node.js (version 18+)
- PostgreSQL database
- Telegram Bot Token
- OpenAI API key
- FatSecret API keys
- Clone the repository
git clone <repository-url>
cd EatCount-Bot- Install dependencies
npm install- Configure environment variables Copy the example environment file and configure it:
cp .env.example .envThen edit the .env file with your actual values.
Note: You can find all required environment variables in the .env.example file.
- Set up the database
# Generate Prisma client
npx prisma generate
# Database migration
npx prisma migrate dev --name init- Run the bot
# Development mode
npm run dev
# Production mode
npm run build
npm start| Command | Description |
|---|---|
/start |
Initial greeting and registration |
/meal |
Quick meal addition |
- π΄ Add Meal - Choose type and describe food
- π Statistics - View daily/weekly statistics
- π Edit - Manage meal records
- βοΈ Settings - Set calorie goals
- π Advanced Statistics on Website - Go to web app
-
Adding a meal:
- Press "π΄ Add Meal"
- Choose type (breakfast/lunch/dinner/snack)
- Describe what you ate: "2 eggs, toast with butter, orange juice"
- Get detailed analysis of calories and nutrients
-
Viewing statistics:
- Press "π Statistics"
- Choose period (today/this week/last week)
- View detailed statistics with goal progress
-
Editing records:
- Press "π Edit"
- Choose today's or recent meals
- Change description, type, or delete record
EatCount-Bot/
βββ src/
β βββ handlers/
β β βββ commands/ # Bot command handlers
β β βββ callbacks/ # Inline button handlers
β β βββ messages/ # Text message handlers
β βββ menus/ # UI menus and keyboards
β βββ lib/ # Core services (DB, OpenAI, FatSecret, Logger)
β βββ helpers/ # Helper functions
β βββ middlewares/ # Session middleware
βββ prisma/ # Database schema and migrations
βββ logs/ # Application log files
- Grammy: Modern framework for Telegram bots
- Prisma: ORM for database operations
- OpenAI: Artificial intelligence for text processing
- FatSecret API: Food database
- Winston: Logging system
- TypeScript: Typed development
- PostgreSQL: Relational database
The bot maintains detailed logging:
- Errors: Detailed error information
- Statistics: Feature usage analysis
The project supports containerization via Docker:
# Build image
docker build -t eatcount-bot .
# Run container
docker run -d --env-file .env eatcount-botnpm run dev- Development mode with hot reloadnpm run build- TypeScript project buildnpm start- Run production version
Dmytro Hopko