How lifailon/openrouter-bot works
OpenRouter Bot lets Telegram users chat with OpenRouter or compatible local models, with commands for model selection, history reset, and usage statistics. The main flow is Telegram updates → access and per-user state → streaming chat completion → Telegram response; OpenRouter generation usage is then recorded. Configuration, translations, vision input, model discovery, history, and persisted budgets are distinct supporting capabilities. Source excerpts show the main dispatch and chat flow; several README capabilities are documented but their command or configuration internals were not sampled, so those links are omitted where call ownership is unverified.
Main entry points: main.go Update dispatcher · openrouter.go Streaming chat · usage_tracker.go Access and usage · users_manager.go User registry
Components 16
Bot entry
- Update dispatcher
main.go
Chat handling
- Streaming chat
api/openrouter.go - Model discovery
api/openrouter.go - Vision input
api/openrouter.go
User state
- User registry
user/users_manager.go - Access and usage
user/usage_tracker.go - Usage records
- Conversation history
user/history.go - User data types
user/types.go
Configuration
- Config loading
config/config.go - Config watcher
config/config_manager.go - Translations
lang/lang.go
Other components
- Telegram user
- Telegram Bot API
- OpenAI-compatible API
- Generation usage API
Connections 21
- Telegram user → Telegram Bot API: sends updates
- Telegram Bot API → Update dispatcher: delivers updates
main.go - Update dispatcher → Config loading: loads settings
main.go - Update dispatcher → Translations: loads strings
main.go - Update dispatcher → User registry: gets user
main.go - User registry → Access and usage: creates tracker
user/users_manager.go - Access and usage → Usage records: reads and writes
user/usage_tracker.go - Update dispatcher → Access and usage: checks access
main.go - Update dispatcher → Streaming chat: dispatches chat
main.go - Streaming chat → Conversation history: reads and appends
api/openrouter.go - Streaming chat → Vision input: builds image input
api/openrouter.go - Vision input → Telegram Bot API: downloads image
api/openrouter.go - Streaming chat → OpenAI-compatible API: streams completion
api/openrouter.go - Streaming chat → Telegram Bot API: sends streamed reply
api/openrouter.go - Update dispatcher → Model discovery: requests free models
main.go - Model discovery → Config watcher: loads endpoint config
api/openrouter.go - Model discovery → OpenAI-compatible API: fetches model list
api/openrouter.go - Update dispatcher → Generation usage API: requests generation cost
main.go - Access and usage → Generation usage API: fetches generation
user/usage_tracker.go - Update dispatcher → Translations: formats commands
main.go - Config watcher → Config loading: reloads settings
config/config_manager.go