Data Flow

Architecture: Data Flow

Command flow

sequenceDiagram participant UI as WebSocket Client participant WS as TDLibListChatsConsumer participant MSG as publish_command / JetStream participant OWNER as AccountOwnerWorker participant REG as commands.registry participant SVC as tdlib/services/* participant API as tdlib/api/* participant TG as TDLib / Telegram participant LIVE as send_ws / live publisher UI->>WS: {"action": "<command>", ...} WS->>MSG: publish_command(command, payload) MSG->>OWNER: shard-owned command delivery OWNER->>REG: dispatch_command_payload(userbot, tg, payload) REG->>SVC: handler -> service method SVC->>API: raw TDLib call(s) API->>TG: call_method(...) TG-->>API: raw TDLib result API-->>SVC: {ok, result, error} SVC-->>REG: normalized result REG->>LIVE: ctx.send / ctx.send_response LIVE-->>WS: live event payload WS-->>UI: chat_update frame

open_client flow

sequenceDiagram participant UI as WebSocket Client participant WS as TDLibListChatsConsumer participant OWNER as AccountOwnerWorker participant CACHE as CacheProjectionUpdater/DialogCache participant REPLAY as ReplayService UI->>WS: {"action": "open_client", "userbot_id": 1} WS->>WS: subscribe to rt.* live subject WS->>OWNER: ensure_warm OWNER-->>WS: account_mode (optional) WS->>CACHE: get_snapshot(userbot_id) CACHE-->>WS: profile + chat_list snapshot WS->>REPLAY: replay_account(userbot_id) REPLAY-->>WS: recent events WS-->>UI: snapshot events WS-->>UI: replay events OWNER-->>WS: future live events WS-->>UI: chat_update frames

Update flow

sequenceDiagram participant TG as TDLib participant OWNER as AccountSessionRuntime participant QUEUE as UpdateQueueProcessor participant UPD as UpdateRuntimeService participant NORM as UpdateNormalizer participant CACHE as DialogCache participant LIVE as publish_live_payload_sync participant WS as Gateway TG-->>OWNER: updateNewMessage / updateChatLastMessage / ... OWNER->>QUEUE: enqueue_from_thread(update) QUEUE->>UPD: handle_update(update, userbot) UPD->>NORM: normalize_update(update, userbot) NORM-->>UPD: normalized payload + parsed message + cache hints UPD->>CACHE: add/update snapshot and recent events UPD->>LIVE: publish live payload LIVE-->>WS: rt.* event WS-->>Client: chat_update

Media download flow

sequenceDiagram participant CMD as MediaCommandService participant LOADER as media_loader participant CACHE as DialogCache participant CLOUD as save_to_cloud participant FILE as FileService / FilesApi participant LIVE as publish_live_payload_sync CMD->>LOADER: enqueue_async_file_download(...) LOADER->>CACHE: check cached file path alt cache miss LOADER->>CLOUD: resolve_existing_tg_file(...) end alt cloud miss and file_id available LOADER->>FILE: download_file(...) end LOADER->>CACHE: cache resolved path LOADER->>LIVE: media_ready

Data persistence points

  • DialogCache: cached dialogs, files, snapshots, replay events
  • UserBot: persisted self-profile projection target
  • CustomEmoji: cached emoji asset metadata/path
  • CommandExecution: idempotency / execution registry
  • cloud storage via default_storage / S3-compatible backend for uploaded and downloaded media