This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
UTeM Student Assistant Bot - A Telegram bot helping UTeM students manage academic schedules, assignments, tasks, and TODOs with AI-powered features including image recognition, voice transcription, and smart suggestions (Google Gemini).
# Run the bot
python -m src.main
# Run tests
pytest tests/ -v
# Run specific test file
pytest tests/test_semester_logic.py -v
# Install dependencies
pip install -r requirements.txtsrc/main.py- Main entry point; initializes database, registers handlers, starts schedulersrc/config.py- Settings & environment loading
Bot Layer (src/bot/)
handlers.py- Telegram command handlers and message routing by intent. Handles text, photos, and voice. Debug commands:/setdate,/settime,/triggerconversations.py- Multi-step conversation flows (onboarding, assignment confirmation) and response formatterskeyboards.py- Inline keyboard layouts (main menu, settings, voice options). Settings keyboard shows date/time override status
AI Layer (src/ai/)
gemini_client.py- Google Gemini API wrapper (singleton viaget_gemini_client())intent_parser.py- NLP intent classification withIntentenum. Regex patterns checked first (lab tests, week queries, class queries), then Gemini for complex messagesimage_parser.py- Detects image types (calendar, timetable, assignment) and extracts structured data
Database Layer (src/database/)
models.py- SQLite schema (user_config, events, schedule, assignments, tasks, todos, voice_notes, etc.)operations.py-DatabaseOperationsclass with CRUD methods.get_subject_aliases()builds name→code mappings from schedule
Scheduler (src/scheduler/)
notifications.py- APScheduler-based. Notification schedule:- 10:00 PM: Tomorrow's classes briefing
- 8:00 PM: Off-day alert
- 12:00 AM: Midnight TODO review
- Every 30 min: Assignment/Task/TODO/Exam reminder checks
Utils (src/utils/)
semester_logic.py- Week calculation (14-week semester with mid-break),get_today(),get_now()translations.py- Multi-language support (English/Malay) viaget_text(key, lang)
- Timezone: All times use
Asia/Kuala_Lumpur(MY_TZ) - Authorization: All handlers wrapped with
authorized()decorator inregister_handlers(). UsesALLOWED_USER_IDfrom config - Test Overrides:
get_today()andget_now()support_test_date_override/_test_time_override. Settings menu shows override status with reset buttons - Semester Structure: 14 weeks (Week 1-6, mid-break, Week 7-14, inter-semester break)
- Subject Aliases:
get_subject_aliases()maps subject names/abbreviations to codes (e.g., "os" → "BITI1213", "sp" → "Statistics and Probability"). Skips filler words (and, or, of) when building abbreviations - Lab Test/Exam: When adding exams via NLP, system looks up schedule to find actual day/time for the subject's class type (LAB/LEC)
- Callback Handling: All inline button callbacks go through
callback_query_handler()in handlers.py
All reminders are checked every 30 minutes. Each level triggers only once per item.
Assignment Reminders (7 levels):
| Level | Hours Before | Message |
|---|---|---|
| 1 | 72h (3 days) | "due in 3 days" |
| 2 | 48h (2 days) | "due in 2 days" |
| 3 | 24h (1 day) | "due TOMORROW" |
| 4 | 8h | "8 hours left" |
| 5 | 3h | "3 hours left" |
| 6 | 1h | "1 hour remaining" |
| 7 | 0h | "NOW DUE" |
Exam Reminders (4 levels):
| Level | Hours Before | Message |
|---|---|---|
| 1 | 168h (1 week) | "Exam in 1 WEEK" |
| 2 | 72h (3 days) | "Exam in 3 DAYS" |
| 3 | 24h (1 day) | "Exam TOMORROW" |
| 4 | 3h | "Exam in 3 HOURS" |
Task Reminders (2 levels):
- 1 day before (at 8 PM): "Task Tomorrow"
- 2 hours before (if time set): "Task in 2 hours"
TODO Reminders (1 level):
- 1 hour before (if time set): "TODO Reminder"
- User sends voice message →
handle_voice_message()transcribes via Gemini - User selects processing type (summary, minutes, tasks, study notes, transcript)
- Processed content saved to
voice_notestable /notescommand lists and manages saved notes
TELEGRAM_TOKEN=<bot token from @BotFather>
GEMINI_API_KEY=<Google Gemini API key>
DATABASE_PATH=data/bot.db (optional, defaults to data/bot.db)
ALLOWED_USER_ID=561393547 (optional, restricts bot to single user)
/setdate YYYY-MM-DD- Override current date/settime HH:MM- Override current time/trigger <type>- Trigger notifications: briefing, offday, midnight, assignments, tasks, todos, exams, semester- Settings menu shows current date/time with override warnings and reset buttons
- Database: Add table/columns in
models.py, CRUD inoperations.py - Bot: Add handler in
handlers.py, wrap withauthorized()inregister_handlers() - UI: Add callbacks in
callback_query_handler(), keyboards inkeyboards.py - NLP: Add regex patterns in
intent_parser.py(before Gemini fallback for common patterns) - i18n: Add translations in
translations.py
Use productivity-bot.service for systemd deployment:
# Edit service file with your username
sed -i 's/your_username/'"$USER"'/g' productivity-bot.service
# Install and start
sudo cp productivity-bot.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable productivity-bot
sudo systemctl start productivity-bot
# View logs
sudo journalctl -u productivity-bot -f