Skip to content

telegram: per-topic session isolation#173

Open
ybuzko wants to merge 3 commits intomoazbuilds:masterfrom
ybuzko:feat/telegram-per-topic-sessions
Open

telegram: per-topic session isolation#173
ybuzko wants to merge 3 commits intomoazbuilds:masterfrom
ybuzko:feat/telegram-per-topic-sessions

Conversation

@ybuzko
Copy link
Copy Markdown

@ybuzko ybuzko commented May 3, 2026

Summary

  • Adds getTelegramSessionKey() helper that maps each Telegram context to an isolated session key: tg:<chatId>:<threadId> for supergroup topics, tg:<chatId> for general group chat, tg:dm:<userId> for per-user DMs (opt-in), or undefined to fall through to the global session
  • Adds telegram.dmIsolation: "shared" | "perUser" config setting (default "shared" to match existing Discord DM behavior)
  • Scopes /reset, /compact, /status, and /context to the per-topic session when a key is present

Motivation

Without this, all Telegram group topics share a single global session. A conversation in one topic bleeds context into unrelated topics, and /reset nukes every topic at once. This matches the isolation pattern Discord already uses for guild channels.

Test plan

  • Supergroup: send messages in two different topics — confirm each maintains its own context
  • /reset in one topic does not affect another topic's session
  • /status and /context show the correct per-topic session
  • /compact runs on the correct thread session
  • DMs with dmIsolation: "shared" (default) still use the global session
  • DMs with dmIsolation: "perUser" isolate per user ID
  • Plain group chat (no threads) uses tg:<chatId> key correctly

🤖 Generated with Claude Code

ybuzko and others added 3 commits May 3, 2026 08:07
Adds `telegram.dmIsolation: "shared" | "perUser"` setting.
Defaults to "shared" to match Discord DM behaviour (all DMs share the
global session). Set to "perUser" to give each DM sender their own
isolated session.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Routes each supergroup topic (chat+thread) and optionally each DM user
to its own session key ("tg:<chatId>:<threadId>"), so /reset, /compact,
/status, and /context all operate on the correct isolated session instead
of the global one.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant