How teamultroid/ultroid works
1. What this repo is
Ultroid is a long-running Telegram userbot with an additional assistant/bot sidecar and voice/video-call music features. The core runtime is Python 3.10+ and the main Telegram SDK is Telethon; voice chat/music functionality is built around PyTgCalls.
2. Primary runtime shape
The application is organized as a single service process that boots from pyUltroid/__main__.py and the startup scripts, then initializes Telegram clients, loads config, connects to storage, and dynamically imports feature modules. The root-level startup, Dockerfile, docker-compose.yml, heroku.yml, and okteto-pipeline.yml show that the same codebase is meant to run locally or in container/PaaS environments.
3. Main execution boundary: user client vs assistant client
There are two distinct Telegram-facing surfaces:
- the main userbot client for commands sent through the logged-in user session,
- the assistant bot/client under assistant/, which handles PM interactions, callbacks, inline behavior, and helper workflows.
This split is important architecturally because many features are exposed through the user account, while conversational UX and inline responses are delegated to the assistant.
4. Plugin-driven feature layer
Most application behavior lives in plugins/. This is the main extension boundary: each file is a feature module, not a microservice. The plugin set spans moderation, AFK, anti-flood, notes, filters, media tools, search/download/upload, profile utilities, scheduling, sticker/image/video tools, NSFW filtering, and automation. Support plugins like _help.py, _inline.py, _ultroid.py, _userlogs.py, and _wspr.py provide shared UX and logging behaviors.
5. Assistant subsystem
The assistant/ package contains the assistant-side command and interaction handlers: callbacks, inline stuff, games, PM bot logic, start/help handlers, YTDL support, and a manager/ subpackage for admin/help/AFK/sticker management. This is a distinct command surface from plugins/, but it reuses the same config, database, and utility layers.
6. Persistence and state management
Persistent state is abstracted through pyUltroid/dB/. The repo supports multiple backing stores as indicated by the README: Redis, MongoDB, or SQLDB. Feature-specific DB modules such as afk_db.py, blacklist_db.py, notes_db.py, greetings_db.py, warn_db.py, and others suggest a modular persistence model where each feature owns its own stored state rather than using one monolithic schema.
7. Shared framework and helpers
pyUltroid/fns/ and pyUltroid/_misc/ are the shared utility boundary used by both plugins and assistant modules. These files contain generic helpers for admin checks, execution, info formatting, gDrive, tools, downloads, and wrappers/decorators. pyUltroid/startup/ contains bootstrapping logic such as client setup, database initialization, connection helpers, and runtime utilities.
8. Media and external service integrations
Several plugins are integration-heavy rather than purely local: YouTube/download tooling, Google Drive upload/share, Twitter/Unsplash/weather lookups, QR/image/pdf/video/audio conversion, and web uploads. These features form the repo’s outbound data-flow boundary: Telegram command -> plugin -> external API/service or local processing -> Telegram response.
9. Localization and message content
User-facing strings are externalized under strings/strings/*.yml, with many languages supported. That means command handlers usually route output through a localization layer rather than hardcoding text in the plugins, which matters for diagramming because message formatting is a shared cross-cutting concern.
10. Deployment and bootstrap tooling
The repo is packaged for several deployment modes: local shell startup, Docker, Heroku, Okteto, and Termux. Files like .env.sample, installer.sh, install-termux, resources/session/*, and sessiongen indicate that runtime setup depends on environment variables plus a generated Telegram session string. The architecture therefore assumes environment-driven configuration and external secret injection rather than built-in credential management.
11. Operational flow to show in a diagram
The clearest high-level flow is: environment/session init → database connection → Telethon client startup → dynamic loading of plugins and assistant modules → command/event handling → optional persistence/external API calls → Telegram replies. The assistant client and the main userbot share the same storage and helper layers, but they expose different interaction channels.
12. Key boundaries to draw
For an architecture diagram, the main boxes should be: Telegram clients, plugin/assistant handlers, shared core utilities, persistent storage adapters, and external services/integrations. The important distinction is that Ultroid is not a monolith of one command loop; it is a plugin-based Telegram automation platform with a separate assistant surface and a pluggable storage backend.
Main entry points: plugins Plugins · manager Assistant manager · startup Startup flow · loader.py Loader core
Components 18
Runtime & bootstrap
Process entrypoints and environment-driven startup paths.
- Main entry · Bootstraps the application process and hands off to startup logic.
pyUltroid/__main__.py - Startup flow · Initial runtime setup: clients, config, database, and dynamic loading.
pyUltroid/startup - Env & session · Environment variables, session-string generation, and platform-specific launch helpers.
resources/session/ssgen.py - Deploy targets · Docker, Heroku, Okteto, Termux, and local shell startup environments.
Dockerfile
Telegram surfaces
Main userbot client and assistant sidecar interactions.
- Userbot client · Primary logged-in Telegram user session that executes most commands.
pyUltroid/startup/BaseClient.py - Assistant sidecar · Secondary bot/client surface for PMs, callbacks, inline UX, and helper flows.
assistant - Assistant manager · Admin, help, AFK, sticker, and misc assistant workflows.
assistant/manager - Plugins · Main extension boundary for userbot commands and event handlers.
plugins
Shared core
Common utilities, loaders, localization, and support code.
- Loader core · Dynamic import and runtime wiring for feature modules.
pyUltroid/loader.py - Helpers · Shared admin checks, execution helpers, info formatting, wrappers, and support functions.
pyUltroid/fns - Misc core · Cross-cutting decorators, assistant glue, and runtime helper wrappers.
pyUltroid/_misc - Strings · Localized message catalogs used by handlers and plugins.
strings/strings
Persistence
Backends and feature-scoped state adapters.
- DB core · Database facade and backend selection for persistent state.
pyUltroid/dB - Feature state · Per-feature state modules for AFK, filters, notes, warnings, blacklists, and similar data.
pyUltroid/dB/base.py - Redis/Mongo/SQL · Supported persistence backends for runtime state.
External integrations
Outbound services and media-processing boundaries.
- Telegram API · Telegram transport used by both userbot and assistant clients.
- Media services · YouTube, Google Drive, Twitter, Unsplash, weather, web upload, and other outbound integrations.
- Media tools · Local conversion, compression, QR, PDF, image, audio, video, and archive tooling.
plugins/audiotools.py
Connections 24
- Env & session → Main entry: starts · Deployment setup launches the Python entrypoint.
- Deploy targets → Env & session: provisions · Container and platform targets provide environment and startup wiring.
- Main entry → Startup flow: boots · Entrypoint hands control to startup orchestration.
- Startup flow → Userbot client: creates · Startup initializes the main Telegram user client.
- Startup flow → Assistant sidecar: creates · Startup also initializes the assistant sidecar.
- Startup flow → DB core: connects · Runtime connects to the database abstraction.
- Startup flow → Loader core: loads · Startup dynamically imports feature modules.
- Loader core → Plugins: imports · Loader activates userbot plugins.
- Loader core → Assistant manager: imports · Loader activates assistant-side handlers.
- Plugins → Helpers: uses · Plugins rely on common helper functions.
- Plugins → Misc core: uses · Plugins share decorators and wrapper utilities.
- Assistant manager → Helpers: uses · Assistant handlers reuse shared helpers.
- Assistant manager → Misc core: uses · Assistant handlers reuse assistant glue and wrappers.
- Plugins → Strings: formats · Plugins resolve user-facing strings through localization catalogs.
- Assistant manager → Strings: formats · Assistant flows also use localized messages.
- Plugins → Feature state: persists · Feature handlers store module-specific state.
- Assistant manager → Feature state: persists · Assistant workflows also use feature-scoped storage.
- DB core → Redis/Mongo/SQL: backed by · Core storage can be backed by Redis, MongoDB, or SQLDB.
- Feature state → DB core: built on · Feature stores are implemented through the shared DB layer.
- Userbot client → Telegram API: talks to · Primary userbot communicates with Telegram.
- Assistant sidecar → Telegram API: talks to · Assistant surface communicates with Telegram.
- Plugins → Media services: calls · Integration plugins fetch or upload data to external services.
- Plugins → Media tools: processes · Media-oriented plugins perform local transformations and conversions.
- Assistant manager → Media services: calls · Assistant features can invoke external media and helper services.