3.2 KiB
3.2 KiB
id, title, status, assignee, created_date, updated_date, labels, dependencies
| id | title | status | assignee | created_date | updated_date | labels | dependencies | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| task-81 | Build Telegram bot usage logging and audit system | To Do | 2025-07-31 | 2025-07-31 |
|
Description
Create a comprehensive logging system to track all Telegram bot interactions, including user info, processed files, performance metrics, and responses, with an admin interface for auditing usage
Acceptance Criteria
- New TelegramBotLog model records all bot interactions
- Model stores telegram user ID and name
- Model stores processed files as BlobFile associations
- Model tracks performance metrics (fingerprint computation time and search time)
- Model stores response data serialized as JSON
- Admin-only controller provides access to audit logs
- Views display searchable and filterable audit data
- Bot integration automatically logs all requests
- Performance impact of logging is minimal
- Data retention and cleanup policies are implemented
Implementation Plan
- Design and create TelegramBotLog model with fields for telegram_user_id, telegram_username, telegram_first_name, telegram_last_name, request_timestamp, fingerprint_computation_time, search_computation_time, search_results_count, response_data (JSON), and associations to BlobFile for processed images
- Create database migration for telegram_bot_logs table with proper indexes for performance (telegram_user_id, request_timestamp, search_results_count)
- Set up BlobFile association in TelegramBotLog model to store the processed image files
- Create TelegramBotLogsController with admin-only authorization (similar to GlobalStatesController pattern)
- Implement index action with filtering and pagination (by user, date range, performance metrics)
- Create view templates for listing and viewing individual audit logs with search and filter functionality
- Add logging integration to TelegramBotTask - instrument fingerprint computation time and search time
- Update TelegramBotTask to save processed images as BlobFiles and create audit log records for each request
- Add data cleanup/retention policy (e.g., delete logs older than 6 months, configurable via GlobalState)
- Add routes for admin audit interface following existing patterns
- Style views consistently with existing admin interfaces
- Test integration end-to-end with bot interactions and verify minimal performance impact
Implementation Notes
Task has been broken down into 5 manageable sub-tasks that can be completed independently:
- task-81.1: Create TelegramBotLog model and database migration (database foundation)
- task-81.2: Integrate logging into TelegramBotTask with performance metrics (bot integration)
- task-81.3: Create TelegramBotLogsController with admin authorization (controller layer)
- task-81.4: Build admin views for Telegram bot audit log interface (UI layer)
- task-81.5: Add routes and implement data retention policies (configuration and cleanup)
Each sub-task is independent and can be worked on separately, allowing for incremental progress and easier testing. The sub-tasks should be completed in order as they build upon each other.