openclaw - ✅(Solved) Fix fix(telegram): missing buildToolContext causes message tool, cron, and sessions_send to lose thread context [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#49388Fetched 2026-04-08 00:55:39
View on GitHub
Comments
2
Participants
3
Timeline
4
Reactions
0
Timeline (top)
commented ×2cross-referenced ×1referenced ×1

Telegram is the only major channel plugin that lacks a buildToolContext implementation in its threading config. This means the message tool, cron delivery, and sessions_send announce cannot resolve message_thread_id — all outbound messages land in the parent chat instead of the correct topic thread.

Root Cause

In extensions/telegram/src/channel.ts, the threading object defines resolveReplyToMode and resolveAutoThreadId but does not define buildToolContext. The core agent runner (src/auto-reply/reply/agent-runner-utils.ts:48) checks for threading?.buildToolContext and skips tool context construction when it is missing.

Without tool context, resolveAutoThreadId receives toolContext: undefined, so resolveTelegramAutoThreadId has no currentThreadTs to work with and returns undefined. The Telegram API call proceeds without message_thread_id.

Every other channel that supports threading (Matrix, Slack, MS Teams, BlueBubbles) implements buildToolContext. Telegram was the only one missing it.

Fix Action

Fix

Add buildToolContext to the Telegram threading config, following the same pattern as other channels:

buildToolContext: ({ context, hasRepliedRef }) => ({
  currentChannelId: context.To?.trim() || undefined,
  currentThreadTs:
    context.MessageThreadId != null ? String(context.MessageThreadId) : undefined,
  hasRepliedRef,
}),

This is a 6-line addition to extensions/telegram/src/channel.ts.

PR fix notes

PR #49389: fix(telegram): add buildToolContext to resolve message_thread_id for DM topics

Description (problem / solution / changelog)

What

Adds the missing buildToolContext implementation to the Telegram channel plugin's threading config. This is a 6-line addition that follows the exact same pattern already used by Matrix, Slack, MS Teams, and BlueBubbles.

Why

Telegram was the only major channel without buildToolContext. Without it, the core agent runner skips tool context construction entirely (agent-runner-utils.ts:48), which means:

  • The message tool cannot resolve message_thread_id
  • Cron delivery loses thread context
  • sessions_send announce drops threadId

All outbound messages land in the parent DM chat instead of the correct topic thread.

Change

  threading: {
    resolveReplyToMode: ({ cfg }) => cfg.channels?.telegram?.replyToMode ?? "off",
+   buildToolContext: ({ context, hasRepliedRef }) => ({
+     currentChannelId: context.To?.trim() || undefined,
+     currentThreadTs:
+       context.MessageThreadId != null ? String(context.MessageThreadId) : undefined,
+     hasRepliedRef,
+   }),
    resolveAutoThreadId: ({ to, toolContext, replyToId }) =>
      replyToId ? undefined : resolveTelegramAutoThreadId({ to, toolContext }),
  },

Testing

Verified on live Telegram DM with topics enabled:

  • ✅ Message tool sends to correct topic thread
  • ✅ Cron delivery routes to originating thread
  • ✅ sessions_send announce respects thread context
  • ✅ Sticker/reaction actions inherit thread context
  • ✅ No regression on non-threaded DMs or group chats

Closes

Fixes #49388, fixes #14762, fixes #27560, fixes #28523

Related: #44270, #47515, #43402

Changed files

  • extensions/telegram/src/channel.ts (modified, +7/-1)
  • scripts/tsdown-build.mjs (modified, +2/-3)
  • src/agents/sandbox/browser.ts (modified, +1/-0)
  • src/browser/chrome.ts (modified, +10/-1)
  • src/browser/config.ts (modified, +3/-0)
  • src/config/types.browser.ts (modified, +2/-0)

Code Example

buildToolContext: ({ context, hasRepliedRef }) => ({
  currentChannelId: context.To?.trim() || undefined,
  currentThreadTs:
    context.MessageThreadId != null ? String(context.MessageThreadId) : undefined,
  hasRepliedRef,
}),
RAW_BUFFERClick to expand / collapse

Summary

Telegram is the only major channel plugin that lacks a buildToolContext implementation in its threading config. This means the message tool, cron delivery, and sessions_send announce cannot resolve message_thread_id — all outbound messages land in the parent chat instead of the correct topic thread.

Root Cause

In extensions/telegram/src/channel.ts, the threading object defines resolveReplyToMode and resolveAutoThreadId but does not define buildToolContext. The core agent runner (src/auto-reply/reply/agent-runner-utils.ts:48) checks for threading?.buildToolContext and skips tool context construction when it is missing.

Without tool context, resolveAutoThreadId receives toolContext: undefined, so resolveTelegramAutoThreadId has no currentThreadTs to work with and returns undefined. The Telegram API call proceeds without message_thread_id.

Every other channel that supports threading (Matrix, Slack, MS Teams, BlueBubbles) implements buildToolContext. Telegram was the only one missing it.

Fix

Add buildToolContext to the Telegram threading config, following the same pattern as other channels:

buildToolContext: ({ context, hasRepliedRef }) => ({
  currentChannelId: context.To?.trim() || undefined,
  currentThreadTs:
    context.MessageThreadId != null ? String(context.MessageThreadId) : undefined,
  hasRepliedRef,
}),

This is a 6-line addition to extensions/telegram/src/channel.ts.

Impact

This single missing hook is the root cause of multiple open issues:

Directly fixes:

  • #14762 — message tool and cron delivery don't route to forum topics
  • #27560 — message_thread_id not passed for forum topic delivery
  • #28523 — sticker action doesn't inherit message_thread_id in DM with topics

Related (same root cause, different entry points):

  • #44270 — cron tool drops thread context when inferring delivery target
  • #47515 — sessions_send announce delivery drops threadId

Partially addresses:

  • #43402 — feature request to pass TELEGRAM_MESSAGE_THREAD_ID to Skills (buildToolContext populates the tool context that skills can access)

Verified

Tested on a live Telegram DM with topics enabled. Before fix: all message tool / cron / sessions_send replies landed in the parent chat. After fix: replies correctly route to the originating topic thread.

extent analysis

Fix Plan

To resolve the issue, you need to add a buildToolContext implementation to the Telegram channel's threading config.

Here are the steps:

  • Open extensions/telegram/src/channel.ts
  • Locate the threading object
  • Add the following code to the threading object:
buildToolContext: ({ context, hasRepliedRef }) => ({
  currentChannelId: context.To?.trim() || undefined,
  currentThreadTs:
    context.MessageThreadId != null ? String(context.MessageThreadId) : undefined,
  hasRepliedRef,
}),

This code constructs a toolContext object with currentChannelId, currentThreadTs, and hasRepliedRef properties.

Verification

To verify the fix, test the following scenarios:

  • Send a message using the message tool and verify it lands in the correct topic thread
  • Test cron delivery and verify it routes to the correct topic thread
  • Test sessions_send announce delivery and verify it includes the correct message_thread_id

Extra Tips

  • Make sure to test the fix on a live Telegram DM with topics enabled to ensure it works as expected
  • Review other channel implementations (e.g., Matrix, Slack, MS Teams, BlueBubbles) to ensure consistency in buildToolContext implementation
  • Consider adding additional logging or debugging statements to verify the toolContext object is being constructed correctly

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix fix(telegram): missing buildToolContext causes message tool, cron, and sessions_send to lose thread context [1 pull requests, 2 comments, 3 participants]