How dvorobiev/bridge-status-bot works
Purpose and Runtime
A Python 3.10+ Telegram bot that reports the live operational state of the Mityaevsky pontoon bridge in Kolomna. It derives bridge position, traffic-light color, and countdown timer from a camera stream using Google Gemini.
The executable entry point is bridge_bot.py, started with python3 bridge_bot.py.
Application Boundary
The repository is intentionally single-process and single-module: Telegram interaction, camera-frame acquisition, AI analysis, and response formatting are expected to be orchestrated in bridge_bot.py.
Core runtime dependencies are declared in requirements.txt; local secrets are supplied via .env based on .env.example.
Telegram Interaction Layer
The bot receives /start and /status commands in private chats and groups, and exposes an inline button for status refresh. This layer handles Telegram updates, command/button routing, and sends the formatted status response.
Primary path:
• bridge_bot.py
External service:
• Telegram Bot API, authenticated by TELEGRAM_TOKEN.
Camera Capture Stage
On a status request, the bot obtains a current image/frame from the bridge camera video stream. ffmpeg is an OS-level required dependency, indicating frame extraction likely occurs through a subprocess rather than a Python-native decoder.
Boundary: camera/video input is transformed into a still image suitable for AI inspection.
Primary path:
• bridge_bot.py
External/runtime dependency:
• ffmpeg installed on the host.
AI Vision Analysis Stage
The captured frame is submitted to Google Gemini, which is responsible for extracting three domain values: bridge state (joined/open versus separated), traffic-light color, and any visible countdown.
The API key is environment-provided, keeping model credentials outside source control.
Primary paths:
• bridge_bot.py
• .env.example
External service:
• Google Gemini API, authenticated by GEMINI_API_KEY.
Status Interpretation and Presentation
The bot converts model output into a concise human-facing result, including semantic bridge status, color/icon-based traffic signal status, optional countdown seconds, and observation time. The response format is designed for immediate operational use in Telegram rather than persistent storage or a web UI.
Primary path:
• bridge_bot.py
Control Flow and Failure Boundaries
The request path is synchronous in intent: Telegram command/callback → retrieve camera frame → Gemini analysis → normalize/format result → Telegram reply. Network and subprocess boundaries are the likely failure points: Telegram delivery, camera availability, ffmpeg execution, HTTP transport, and Gemini response quality/availability.
No database, queue, scheduler, or deployment infrastructure is represented in the repository tree; each status check is expected to be live/on-demand.
Main entry points: bridge_bot.py Bot entry point · .env.example Environment contract · requirements.txt Python dependencies
Components 12
Bot Runtime
Single-process request orchestration in bridge_bot.py.
- Bot entry point · Starts the Telegram bot and coordinates status requests.
bridge_bot.py - Command & callback routing · Handles /start, /status, and inline refresh actions.
bridge_bot.py - Live status workflow · Runs capture, analysis, interpretation, and reply for each request.
bridge_bot.py - Captured frame · Still image passed to vision analysis.
bridge_bot.py - Status interpretation · Normalizes model output into bridge and signal status.
bridge_bot.py - Telegram status reply · Includes semantic status, icons, optional countdown, and observation time.
bridge_bot.py - Environment contract · Documents Telegram and Gemini credential variables.
.env.example - Python dependencies · Declares runtime packages.
requirements.txt
External Boundaries
- Telegram updates · Receives commands and refresh callbacks.
- Bridge camera stream · Live source for the pontoon bridge image.
- ffmpeg · Extracts a still frame from the camera stream.
- Google Gemini API · Extracts bridge position, signal color, and countdown.
Connections 12
- Telegram updates → Bot entry point: delivers updates
- Bot entry point → Command & callback routing: registers handlers
- Command & callback routing → Live status workflow: status request
- Live status workflow → Bridge camera stream: requests live video
- Bridge camera stream → ffmpeg: video stream
- ffmpeg → Captured frame: extracts frame
- Captured frame → Google Gemini API: image inspection
- Google Gemini API → Status interpretation: bridge observations
- Status interpretation → Telegram status reply: formats result
- Telegram status reply → Telegram updates: sends response
- Environment contract → Bot entry point: TELEGRAM_TOKEN, GEMINI_API_KEY
- Python dependencies → Bot entry point: runtime packages