Skip to content

fix(telegram): route channel direct messages replies to their topic - #120916

Merged
steipete merged 1 commit into
mainfrom
steipete/optimistic-einstein-9bbb9c
Aug 9, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/optimistic-einstein-9bbb9c

Conversation

@steipete

@steipete steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where users replying in a Telegram channel Direct Messages topic could receive previews, final messages, or media on the base or wrong topic because the distinct destination kind was lost.

Why This Change Was Made

This establishes the Direct Messages topic from authoritative inbound fields, encodes it through one Telegram-owned thread-parameter boundary, preserves it through durable :direct-topic:<id> targets, keeps message-id edits topic-free, and rejects unsupported poll and typing operations before transport. Bot-private and forum topics continue using message_thread_id.

User Impact

Previews, final text, rich content, media, native-command and callback replies, and late or durable replies now remain in the originating channel Direct Messages topic.

Evidence

  • Focused regression command: node scripts/run-vitest.mjs extensions/telegram/src/bot/helpers.test.ts extensions/telegram/src/thread-spec.test.ts extensions/telegram/src/bot-message-context.dm-threads.test.ts extensions/telegram/src/draft-stream.test.ts extensions/telegram/src/reply-parameters.test.ts extensions/telegram/src/targets.test.ts extensions/telegram/src/transport-payload.test.ts extensions/telegram/src/bot-native-commands.test.ts extensions/telegram/src/send.test.ts
    • Pre-rebase result: 9 files, 518 tests passed.
    • Post-rebase result: 9 files, 516 tests passed; all tests discovered on the newer base passed.
  • Production and extension-test tsgo typechecks passed.
  • Focused oxlint, oxfmt --check, and git diff --check passed.
  • A real local grammY HTTP transport recorder captured the expected JSON sends, multipart document sends, rich sends, callback sends, and topic-free edits.
  • Final Codex autoreview reported no accepted or actionable findings.
  • Proof gap: no authenticated live Telegram account probe was run; the local grammY recorder is transport proof, not live-channel proof.

AI-assisted: yes; implementation and final diff reviewed by Peter.

Replies, previews, and media in channel Direct Messages topics now remain in their originating topic. Bot-private and forum topic routing remains unchanged.
@steipete
steipete marked this pull request as ready for review August 9, 2026 05:20
@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram size: L maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete

steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head d14c08542bc2d990dd1ea3e27671ca82f33b8c7a:

  • Focused Telegram regression proof:
    • Command: node scripts/run-vitest.mjs extensions/telegram/src/bot/helpers.test.ts extensions/telegram/src/thread-spec.test.ts extensions/telegram/src/bot-message-context.dm-threads.test.ts extensions/telegram/src/draft-stream.test.ts extensions/telegram/src/reply-parameters.test.ts extensions/telegram/src/targets.test.ts extensions/telegram/src/transport-payload.test.ts extensions/telegram/src/bot-native-commands.test.ts extensions/telegram/src/send.test.ts
    • Pre-rebase result: 9 files, 518 tests passed.
    • Post-rebase result: 9 files, 516 tests passed in 152.22 seconds; every test discovered on the rebased head passed.
  • Whitespace proof:
    • Command: git diff --check origin/main...HEAD
    • Result: passed with no output against the rebase-time base.
  • Structured review:
    • Command: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
    • Result: exit 0, TruffleHog clean, one complete review pass, no accepted or actionable findings.
  • Additional inherited proof: production and extension-test tsgo typechecks, focused oxlint, and oxfmt --check passed. The handoff did not include those commands' exact spellings.
  • Raw transport proof: a real local grammY HTTP recorder captured the expected direct_messages_topic_id routing for JSON sends, multipart document sends, rich sends, callback sends, and durable targets, while confirming message-id edits remain topic-free. This is synthetic local transport proof, not a live Telegram probe.
  • Exact-head pull-request CI: run 31296471782 (https://github.com/openclaw/openclaw/actions/runs/31296471782) attached to the full head SHA above; node scripts/watch-pr-ci.mjs 120916 d14c08542bc2d990dd1ea3e27671ca82f33b8c7a terminated GREEN.
  • Separate Testbox run: none before prepare; the native prepare gate will provision or reuse the required exact-head hosted proof.
  • ClawSweeper: no review comment had been published after exact-head CI at the time of this proof comment; native landing tooling remains authoritative and will fail closed if the required gate is unavailable.
  • Explicit gap: no authenticated live Telegram account probe was run.

Root cause: inbound channel Direct Messages topics were being collapsed into the bot-private/forum thread shape, so later delivery no longer knew which Telegram parameter owned the destination. The Telegram plugin now records the authoritative topic kind once and carries it through a canonical thread-parameter boundary and durable target encoding; unsupported channel-DM poll/typing operations fail before transport. Production delta is +205/-110 (net +95) across 19 files; tests are +525/-113 across 7 files. Bot-private and forum sibling routing remains on message_thread_id.

@steipete
steipete merged commit d7133e7 into main Aug 9, 2026
168 of 173 checks passed
@steipete
steipete deleted the steipete/optimistic-einstein-9bbb9c branch August 9, 2026 05:53
steipete added a commit that referenced this pull request Aug 9, 2026
Follows #120916 by removing duplicate outbound preparation and transport harness code while preserving channel Direct Messages, forum, and bot-private routing.
@ayaangazali

Copy link
Copy Markdown
Contributor

Heads up: two Telegram dispatch tests have been failing on main since this merged, and I think the production change is right while the tests are stale.

Reproduced on current main (34b8a6515d7), clean checkout, no local diff:

× queues final Telegram replies through outbound delivery when available
  AssertionError: expected 'telegram:123' to deeply equal '123'
  extensions/telegram/src/bot-message-dispatch.delivery-basics.test.ts:78

× does not recover forum thread context from a different group session key
  AssertionError: expected 'telegram:-100555' to deeply equal '-100555'
  extensions/telegram/src/bot-message-dispatch.context-recovery.test.ts:587

Both trace to extensions/telegram/src/bot-message-dispatch-delivery.ts:269, where to: String(context.chatId) became context.ctxPayload.OriginatingTo ?? context.ctxPayload.To ?? \telegram:${context.chatId}``. The two tests still assert the old bare chat id.

The second one is the convincing case for the new behavior being correct. Its own fixture sets OriginatingTo: "telegram:-100555" and To: "telegram:-100555" (context-recovery.test.ts:561,563) and then asserts to: "-100555", so it was pinning the exact target-discarding behavior this PR set out to fix. telegram:<chatId> is also the canonical form the inbound path produces: buildTelegramInboundOriginTarget returns telegram:${chatId} (extensions/telegram/src/bot/helpers.ts:521) and bot-message-context.body.ts:228 always populates originatingTo from it, so the third fallback in the new expression now matches the shape the first two carry. The first failing test only reaches that fallback because its synthetic ctxPayload sets neither field, which real inbound never does.

So the fix looks like updating the two expectations to telegram:123 and telegram:-100555 rather than touching runtime. I have not opened a PR for it since it is your change from yesterday and a test-only diff, but happy to send one if that is useful.

One reason it slipped quietly: the push run for the merge commit shows no failing checks because the extension lanes were skipped by change classification, so nothing surfaced this on main itself.

Found while validating an unrelated Telegram PR against main; not blocking anything of mine.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
Replies, previews, and media in channel Direct Messages topics now remain in their originating topic. Bot-private and forum topic routing remains unchanged.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
Follows openclaw#120916 by removing duplicate outbound preparation and transport harness code while preserving channel Direct Messages, forum, and bot-private routing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants