How ja-pa/tbot works
tbot is a Telegram bot for running configured scripts and delivering device notifications. Its main workflow loads configuration and commands, polls Telegram, authorizes each user (including optional TOTP checks), dispatches a command, runs its script, and sends the result back. Separate notification paths accept local Unix-socket messages or optional HTTP messages and deliver them through the daemon. The repository also includes an OpenWrt administration backend and QR-code support for 2FA setup. Some subsystem links are based on README documentation because their implementation was not excerpted.
Main entry points: main.cpp CLI entry · application.cpp Bot application · notification_service.cpp Notification service · commands.cpp Command registry
Components 17
Bot runtime
- CLI entry
src/main.cpp - Configuration
src/config.cpp - Bot application
src/application.cpp - Command registry
src/commands.cpp - Script runner
src/script_runner.cpp - Telegram client
src/telegram_client.cpp
Access and setup
- TOTP access
src/two_factor.cpp - QR rendering
src/qr_code.cpp
Notifications
- Local send client
src/tbot_send.cpp - Socket protocol
include/tbot/notification_protocol.hpp - HTTP notification
src/notification_http.cpp - Notification service
src/notification_service.cpp - Message queue
src/notification_service.cpp
OpenWrt administration
- Admin CLI
src/openwrt/admin_main.cpp - Admin backend
src/openwrt/admin.cpp
Other components
- Telegram user
- Telegram API
Connections 18
- Telegram user → Telegram API: sends commands
README.md - Telegram API → Telegram client: delivers updates
README.md - CLI entry → Configuration: loads settings
src/main.cpp - CLI entry → Command registry: registers commands
src/main.cpp - CLI entry → Bot application: starts runtime
src/main.cpp - Bot application → Telegram client: polls and replies
src/application.cpp - Bot application → Command registry: dispatches commands
src/application.cpp - Command registry → Script runner: runs scripts
src/commands.cpp - Bot application → TOTP access: checks sessions
src/application.cpp - CLI entry → TOTP access: generates secrets
src/main.cpp - CLI entry → QR rendering: renders setup QR
src/main.cpp - Local send client → Socket protocol: uses framing
src/tbot_send.cpp - Local send client → Notification service: sends over socket
README.md - Bot application → HTTP notification: starts endpoint
src/application.cpp - HTTP notification → Notification service: enqueues messages
- Notification service → Message queue: queues messages
src/notification_service.cpp - Notification service → Telegram client: delivers notifications
- Admin CLI → Admin backend: invokes backend
src/openwrt/admin_main.cpp