Skip to content

threadId not saved in deliveryContext for DM topics (Topics in Private Chats) #8891

@Ratzzz33

Description

@Ratzzz33

Bug Description

When receiving messages in Telegram DM topics (Topics in Private Chats, Bot API 9.3+), the threadId is NOT saved in the session's deliveryContext.

Impact

  • All replies (text, files, media) go to General chat instead of the topic
  • Subagent results also go to wrong place
  • Any MEDIA: outputs miss the topic

Root Cause

In Telegram handler, updateLastRoute is called without threadId for DMs:

updateLastRoute: !isGroup ? {
  sessionKey: route.mainSessionKey,
  channel: "telegram",
  to: String(chatId),
  accountId: route.accountId
  // ❌ Missing: threadId: resolvedThreadId
} : void 0,

The resolvedThreadId (from dmThreadId) is available but not passed to updateLastRoute.

Expected Behavior

For DM topics, deliveryContext should contain:

{
  "channel": "telegram",
  "to": "361216541",
  "accountId": "default",
  "threadId": "12345678"
}

Actual Behavior

deliveryContext is missing threadId:

{
  "channel": "telegram",
  "to": "telegram:361216541",
  "accountId": "default"
}

Suggested Fix

Pass threadId to updateLastRoute for DM topics:

updateLastRoute: !isGroup ? {
  sessionKey: route.mainSessionKey,
  channel: "telegram",
  to: String(chatId),
  accountId: route.accountId,
  threadId: dmThreadId  // Add this line
} : void 0,

Version

OpenClaw 2026.2.2-3

Steps to Reproduce

  1. Enable Topics in Private Chats for your bot (has_topics_enabled: true)
  2. Create a topic in DM with the bot
  3. Send a message to the topic
  4. Reply with a file or trigger a subagent
  5. Observe: response goes to General instead of the topic

Workaround

Currently using explicit threadId parameter in message tool calls, but this doesn't work for automatic replies and subagent results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions