Skip to content

feat: add multi-account support#88

Merged
chigwell merged 7 commits intochigwell:mainfrom
dsvetlov:feat/multi-account-support
Apr 23, 2026
Merged

feat: add multi-account support#88
chigwell merged 7 commits intochigwell:mainfrom
dsvetlov:feat/multi-account-support

Conversation

@dsvetlov
Copy link
Copy Markdown

@dsvetlov dsvetlov commented Apr 1, 2026

Summary

  • Support multiple Telegram accounts simultaneously via label-suffixed env vars (TELEGRAM_SESSION_STRING_WORK, _PERSONAL, etc.)
  • Single-account configs remain fully backward-compatible — zero changes needed
  • Read-only tools fan out to all accounts when account is omitted; write tools require explicit account
  • New list_accounts tool for account discovery
  • All 93 tools gain @with_account decorator and account parameter
  • Concurrent client startup via asyncio.gather
  • Updated session string generator with optional label prompt

Test plan

  • Single-account mode: existing .env with one TELEGRAM_SESSION_STRING works identically to before
  • Multi-account mode: two labeled sessions, verify list_accounts returns both
  • Read-only fan-out: get_chats() without account returns results from all accounts with [label] prefix
  • Write guard: send_message() without account in multi-mode returns error listing available accounts
  • Write with account: send_message(account="work", ...) sends from correct account
  • Session generator: label prompt works, outputs correct env var name

🤖 Generated with Claude Code

Daniil Svetlov and others added 4 commits April 1, 2026 16:37
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) <noreply@anthropic.com>
- Add multi-account configuration section (.env with label suffixes)
- Add Multi-Account section to features list
- Update code examples to show @with_account decorator and get_client()
- Add multi-account usage examples
- Update Docker run instructions for multi-account env vars
- Mention session generator label prompt

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Keep upstream's extension-stripping logic in download_media, adapted to
use multi-account cl variable instead of global client.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dsvetlov
Copy link
Copy Markdown
Author

Hey @chigwell — friendly ping on this one.

Not an April Fools joke, for the record :) I've been running this branch off my fork since April 1st with two Telegram accounts (work + personal) and everything has been working great — no bugs surfaced so far.

Happy to address anything on your end: code style, test coverage, API design, naming — whatever would help get this merged. And if you feel multi-account support just doesn't fit the direction you want mcp-telegram to go, that's a totally valid answer too — just let me know and I'll keep maintaining it on the fork.

Thanks!

Copy link
Copy Markdown
Owner

@chigwell chigwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dsvetlov,
Thank you for your contribution. Could you please resolve the pull request conflicts? Also, could you remove the openspec folder from this PR? Thank you.

Daniil Svetlov and others added 3 commits April 24, 2026 00:15
These were local spec-driven planning artifacts and should not be
committed. Removing per maintainer feedback.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dsvetlov
Copy link
Copy Markdown
Author

@chigwell done — both asks addressed:

  1. Removed openspec/ (commit 58f225d) — those were local spec-driven planning artifacts that shouldn't have been committed.
  2. Resolved conflicts with main (commit b8fdcfe + black formatting in d295d6c) — merged in all the upstream changes since April 1st.

The merge required a bit more than a straight conflict resolution because several things landed on main that interact with multi-account:

  • ensure_connected() / _force_reconnect() (from fix: robust ensure_connected() — verify with ping, force reconnect on stale TCP #98) now accept an explicit client parameter and fall back to the single-account client when called without one. _last_conn_verified is now keyed per-client.
  • _main() cleanup on shutdown now disconnects all configured clients via asyncio.gather.
  • 16 new tool functions from upstream (send_scheduled_message, get_scheduled_messages, delete_scheduled_message, edit_chat_about, set_default_chat_permissions, toggle_slow_mode, edit_admin_rights, delete_chat_history, delete_messages_bulk, unpin_all_messages, get_full_user, get_full_chat, send_contact, get_common_chats, get_message_read_by, get_message_link) got wrapped with @with_account + the account parameter so they work in both single- and multi-account modes.
  • list_chats merged both additions cleanly — it now has both account (from this PR) and with_about (from feat: add with_about to list_chats for dispatch disambiguation #106).

All three CI checks pass ✅. Let me know if you want anything else tweaked.

@chigwell chigwell self-requested a review April 23, 2026 22:12
@dsvetlov
Copy link
Copy Markdown
Author

@chigwell gentle ping — both items are addressed and CI is green. Could you take another look when you have a minute? Thanks!

@chigwell chigwell merged commit aaa14c9 into chigwell:main Apr 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants