Integrations

Relevant files:

Architecture: Integrations

Telegram TDLib

  • Transport entry: backend/tg_client/dialogs/tdlib/base.py
  • Raw wrappers: backend/tg_client/dialogs/tdlib/api/*
  • Runtime usage:
  • command execution through service calls
  • update callbacks attached in owner_worker.py

Messaging (NATS / JetStream)

Relevant files:

  • backend/tg_client/messaging/api.py
  • backend/tg_client/messaging/envelopes.py
  • backend/tg_client/messaging/subjects.py
  • backend/tg_client/messaging/topology.py
  • backend/tg_client/messaging/config.py

Actual integration points visible in code:

  • commands are published as CommandEnvelope
  • owner workers consume shard-based command streams
  • live events are published both as durable event envelopes and transient live subjects
  • WebSocket consumer subscribes to targeted rt.* live subjects

Ownership / lease backend

Visible from code:

  • publish_command() resolves expected_owner_epoch
  • owner runtime checks lease/epoch before handling commands
  • configuration points live in backend/tg_client/messaging/config.py
  • owner runtime obtains coordinator through tg_client.ownership.registry

This docs set covers the integration boundary but not the entire ownership backend implementation in detail.

Cache / projection backend

  • DialogCache uses Django cache
  • CacheProjectionUpdater stores snapshots/recent events
  • ReplayService replays recent events from cache-backed snapshot data

Needs verification based on code: the exact cache backend (Redis / memory / something else) is defined by Django settings, not by dialogs itself.

Cloud storage

Relevant files:

  • backend/tg_client/dialogs/services/save_to_cloud.py
  • backend/tg_client/dialogs/services/media_loader.py
  • backend/tg_client/dialogs/services/file_generation.py

Observed behavior:

  • uses default_storage and explicit boto3 client helpers
  • can auto-create the bucket when missing
  • provides presigned GET/PUT URLs
  • stores Telegram media by stable keys derived from remote unique ids or file ids

Database / ORM

Dialogs runtime depends on Django ORM models from backend/tg_client/models.py:

  • UserBot
  • CustomEmoji
  • CommandExecution

The subsystem does not define a repository layer; services/runtime access ORM-backed helpers directly.