Skip to content

fix(telegram): preserve private topic session keys#804

Open
pjpjq wants to merge 1 commit intochenhg5:mainfrom
pjpjq:codex/telegram-private-topic-sessions
Open

fix(telegram): preserve private topic session keys#804
pjpjq wants to merge 1 commit intochenhg5:mainfrom
pjpjq:codex/telegram-private-topic-sessions

Conversation

@pjpjq
Copy link
Copy Markdown

@pjpjq pjpjq commented Apr 28, 2026

Summary

  • Preserve Telegram message_thread_id whenever Telegram provides it, instead of only when chat.is_forum is true.
  • This lets private chat topics and group forum topics map to distinct Telegram session keys.
  • Update the Telegram regression test and docs for topic-based sessions.

Related discussion

Reproduction

Environment tested locally:

  • Version before patch: cc-connect v1.3.2
  • OS: macOS arm64
  • Install method: npm global package
  • Agent/platform: Codex + Telegram

Steps:

  1. Start cc-connect with a Telegram bot.
  2. Open a Telegram private chat topic with that bot.
  3. Send messages in different topics.

Before this change, private chat topic messages were handled with the same session key because the code only used MessageThreadID when Chat.IsForum was true.

Expected behavior

Messages from different Telegram topics should use different session keys when Telegram includes message_thread_id, so each topic has an independent conversation context.

Actual behavior before this PR

Private chat topics could be collapsed into the base private chat session key, for example:

telegram:680002712

After applying this change locally, a private topic message used a topic-aware session key, for example:

telegram:680002712:34923

Breaking changes

None expected. Messages without message_thread_id still use the existing non-topic session key formats.

Validation

Passed:

pnpm --dir web install --frozen-lockfile
pnpm --dir web build
go test ./platform/telegram
go build -tags 'no_web' ./cmd/cc-connect

Also verified against a real local Telegram bot: a private chat topic message created/used telegram:680002712:34923 instead of the base telegram:680002712 session.

Attempted full validation as requested by CONTRIBUTING:

go test ./...

On my local macOS machine this still fails in packages unrelated to this patch:

  • agent/codex: TestGetModelAndReasoningEffort_FromRuntimeConfigWhenUnset failed once in the full suite, but passes when run directly.
  • core: existing macOS path expectation failures involving /var/... vs /private/var/..., plus reply footer path truncation expectations.

The Telegram package touched by this PR passes.

@pjpjq pjpjq force-pushed the codex/telegram-private-topic-sessions branch from 22b5bf4 to cbffb6d Compare April 28, 2026 13:01
@pjpjq pjpjq force-pushed the codex/telegram-private-topic-sessions branch from cbffb6d to b01e195 Compare April 28, 2026 13:04
@pjpjq pjpjq changed the title fix(telegram): 支持私聊 topic 独立会话 fix(telegram): preserve private topic session keys Apr 28, 2026
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

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

Review Summary

Clean fix for private chat topic session isolation. Previously message_thread_id was only used when chat.is_forum was true, ignoring private chat topics.


Good:

  1. Minimal change: Removes the if msg.Chat.IsForum condition, directly using msg.MessageThreadID (defaults to 0 when not present).

  2. Applied to both paths: handleMessage and handleCallbackQuery both updated consistently.

  3. Test updated: TestHandleMessageNonForumIgnoresThreadID renamed to TestHandleMessagePrivateTopicUsesThreadID, now expects telegram:100:55:7 session key with thread ID preserved.

  4. Docs updated: New section 6.3 explains topic session behavior for forum and private chat topics.

  5. Zero default is safe: When MessageThreadID is 0 (no topic), session key remains unchanged (telegram:100:7).


LGTM. CI green.

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