Files
redux-scraper/backlog/tasks/task-81 - Build-Telegram-bot-usage-logging-and-audit-system.md
2025-07-31 03:52:04 +00:00

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
logging
audit
telegram
admin
models
performance

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

  1. 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
  2. Create database migration for telegram_bot_logs table with proper indexes for performance (telegram_user_id, request_timestamp, search_results_count)
  3. Set up BlobFile association in TelegramBotLog model to store the processed image files
  4. Create TelegramBotLogsController with admin-only authorization (similar to GlobalStatesController pattern)
  5. Implement index action with filtering and pagination (by user, date range, performance metrics)
  6. Create view templates for listing and viewing individual audit logs with search and filter functionality
  7. Add logging integration to TelegramBotTask - instrument fingerprint computation time and search time
  8. Update TelegramBotTask to save processed images as BlobFiles and create audit log records for each request
  9. Add data cleanup/retention policy (e.g., delete logs older than 6 months, configurable via GlobalState)
  10. Add routes for admin audit interface following existing patterns
  11. Style views consistently with existing admin interfaces
  12. 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.