How shaulincito/tarea_separada_bot works
Purpose and Runtime
HEROE is a modular Python Telegram bot for monitoring border-post logistics. Operators query inventory and guard shifts through Telegram; a background process proactively alerts a configured chat when stock falls below thresholds. The runtime starts with python main.py.
Core runtime paths:
• main.py
• requirements.txt
• config.example.py
Entry Points and Telegram Interface
main.py is the application orchestrator and Telegram-facing boundary. It initializes the bot using locally supplied credentials, registers reactive commands, starts background monitoring, and keeps the bot receiving updates.
Operator commands:
• /start and /estado: current resource status.
• /guardia: current duty team.
• /ayuda: command guidance.
Paths:
• main.py
• config.example.py
Inventory Data Boundary
database.py owns the inventory-facing data layer. The repository describes this as simulated logistics data, including inventory access and PDF reading/segmentation capability. It supplies the inventory state consumed by command handlers and scheduled checks, isolating data representation from Telegram interaction.
Paths:
• database.py
• main.py
Proactive Alerting Stage
scheduler.py runs scheduled work on a secondary thread. Its primary job is to periodically inspect inventory—documented as every 30 seconds—and identify items whose quantity is below their configured minimum threshold. Detected shortages are sent as proactive Telegram alerts to the configured monitoring chat.
Control flow: scheduler thread → inventory query → threshold evaluation → Telegram message to monitoring chat.
Paths:
• scheduler.py
• database.py
• main.py
Guard-Shift Capability
guardia.py is an independent domain module for determining the active guard rotation from the host computer’s current time. It maps three daily eight-hour windows to Equipo Alfa, Bravo, or Charlie. main.py delegates /guardia handling to this module rather than embedding schedule logic in the bot orchestrator.
Paths:
• guardia.py
• main.py
Configuration and Security Boundary
Telegram API credentials and the alert destination chat ID are expected in a local config.py, which is intentionally absent from the repository and excluded by .gitignore. config.example.py defines the distributable configuration shape without real secrets.
External service boundary: Telegram Bot API, accessed from the Python bot runtime using the configured BotFather token.
Paths:
• config.example.py
• .gitignore
• main.py
Primary Execution Flow
At startup, main.py loads configuration, connects the Telegram bot, registers command handlers, and launches the scheduler. Telegram updates invoke inventory or guard-shift workflows synchronously through the relevant module. Independently, the scheduler evaluates stock levels and emits alerts, allowing monitoring to continue without operator commands.
Main entry points: main.py Application orchestrator · scheduler.py Stock scheduler · database.py Inventory data · config.example.py Configuration template
Components 12
Python bot runtime
- Application orchestrator · Starts polling, registers commands, and launches monitoring.
main.py - Command handlers · Handles status, guard duty, and help requests.
main.py - Stock scheduler · Checks inventory every 30 seconds.
scheduler.py - Local configuration · Provides bot token and alert chat ID; excluded from source control.
- Configuration template · Defines the distributable configuration shape.
config.example.py - Secret exclusion · Keeps local config out of the repository.
.gitignore
Domain modules
- Inventory data · Provides simulated inventory and document-reading capability.
database.py - Threshold evaluation · Identifies stock below configured minimums.
scheduler.py - Guard rotation · Maps eight-hour windows to Alfa, Bravo, or Charlie.
guardia.py
External boundary
- Telegram Bot API
- Operators
- Monitoring chat
Connections 15
- Configuration template → Local configuration: copied and populated as
- Secret exclusion → Local configuration: excludes
- Local configuration → Application orchestrator: credentials and chat ID
- Application orchestrator → Command handlers: registers
- Application orchestrator → Stock scheduler: starts
- Application orchestrator → Telegram Bot API: connects with bot token
- Operators → Telegram Bot API: send commands
- Telegram Bot API → Command handlers: delivers updates
- Command handlers → Inventory data: status queries
- Command handlers → Guard rotation: /guardia
- Stock scheduler → Inventory data: periodic inventory query
- Stock scheduler → Threshold evaluation: evaluates
- Inventory data → Threshold evaluation: inventory quantities
- Threshold evaluation → Telegram Bot API: shortage alert
- Telegram Bot API → Monitoring chat: proactive message