From e40681b62fbf563cee29c11e79bc95443f1a8a70 Mon Sep 17 00:00:00 2001 From: Daniil Svetlov Date: Wed, 1 Apr 2026 16:37:45 +0300 Subject: [PATCH 1/5] feat: add multi-account support Support multiple Telegram accounts simultaneously via label-suffixed env vars (TELEGRAM_SESSION_STRING_WORK, _PERSONAL, etc.). Single-account configs remain fully backward-compatible. - Replace global client singleton with clients dict registry - Add @with_account decorator to all 93 tools: read-only tools fan out to all accounts, write tools require explicit account - Add list_accounts tool for account discovery - Concurrent client startup via asyncio.gather - Update session_string_generator.py with optional label prompt - Parameterize resolve_entity/resolve_input_entity Co-Authored-By: Claude Opus 4.6 (1M context) --- .env.example | 10 +- main.py | 948 ++++++++++++------ .../multi-account-support/.openspec.yaml | 2 + .../changes/multi-account-support/design.md | 90 ++ .../changes/multi-account-support/proposal.md | 27 + .../specs/account-aware-tools/spec.md | 52 + .../specs/multi-account/spec.md | 56 ++ .../changes/multi-account-support/tasks.md | 54 + openspec/config.yaml | 20 + session_string_generator.py | 19 +- 10 files changed, 966 insertions(+), 312 deletions(-) create mode 100644 openspec/changes/multi-account-support/.openspec.yaml create mode 100644 openspec/changes/multi-account-support/design.md create mode 100644 openspec/changes/multi-account-support/proposal.md create mode 100644 openspec/changes/multi-account-support/specs/account-aware-tools/spec.md create mode 100644 openspec/changes/multi-account-support/specs/multi-account/spec.md create mode 100644 openspec/changes/multi-account-support/tasks.md create mode 100644 openspec/config.yaml diff --git a/.env.example b/.env.example index 8af8654..5fdfd54 100644 --- a/.env.example +++ b/.env.example @@ -2,8 +2,14 @@ TELEGRAM_API_ID=123456 TELEGRAM_API_HASH=0123456789abcdef0123456789abcdef -# Session Management (Choose ONE) +# --- Single account (backward-compatible) --- # Option 1: File-based session (a .session file will be created) TELEGRAM_SESSION_NAME=telegram_session -# Option 2: String-based session (if you generate one, e.g., using Telethon's string session generator) +# Option 2: String-based session TELEGRAM_SESSION_STRING=1231231232erfdfdffd + +# --- Multiple accounts --- +# Add _