openclaw - ✅(Solved) Fix Feature: Auto-rename Telegram DM topics based on conversation content [1 pull requests, 1 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#51485Fetched 2026-04-08 01:10:36
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
closed ×1cross-referenced ×1locked ×1

Automatically rename Telegram DM forum topics when the first message arrives in a new topic/session. Currently users must either manually rename topics or instruct the agent to do it via SOUL.md/system prompt - which is unreliable since the model may ignore the instruction.

Root Cause

Automatically rename Telegram DM forum topics when the first message arrives in a new topic/session. Currently users must either manually rename topics or instruct the agent to do it via SOUL.md/system prompt - which is unreliable since the model may ignore the instruction.

Fix Action

Fixed

PR fix notes

PR #51502: feat(telegram): auto-rename DM topics on first message

Description (problem / solution / changelog)

Summary

<img width="613" height="863" alt="CleanShot 2026-03-21 at 11 06 17" src="https://github.com/user-attachments/assets/2f147a96-089f-4d49-bc41-6c5417235c1d" />

Auto-rename Telegram DM forum topics on first message in a session using LLM. Adds autoTopicLabel config option (default: enabled) with optional custom prompt support.

Closes #51485

Behavior Changes

  • New autoTopicLabel config field on TelegramAccountConfig and TelegramDirectConfig
  • Default: enabled for all instances - new topics get descriptive LLM-generated names automatically
  • On first message in a DM topic session, makes a lightweight LLM call to generate a short topic name (2-4 words, no emoji, max 25 chars)
  • Supports boolean shorthand (autoTopicLabel: true/false) and object form ({ enabled: true, prompt: "..." }) for custom prompts
  • Fire-and-forget: does not block reply delivery
  • Per-DM config takes priority over account-level config
  • Uses bot.api.editForumTopic directly (avoids SecretRef resolution issues with renameForumTopicTelegram)
  • Uses RawBody (not formatted envelope Body) to avoid sending metadata to LLM
  • Input truncated to 500 chars to bound LLM token cost
  • No user-derived content in verbose logs (PII-safe)

Config Examples

// Enabled by default (no config needed)

// Disable for specific DM:
{ "direct": { "123456": { "autoTopicLabel": false } } }

// Custom prompt:
{ "autoTopicLabel": { "enabled": true, "prompt": "Name this topic in Ukrainian, max 40 chars" } }

Tests

  • 12 unit tests for config resolution (boolean shorthand, object form, per-DM override, account fallback, edge cases)

Secret word: lobster-biscuit

Sign-Off

  • Models used: claude-opus-4-6
  • Submitter effort: Medium
  • AI disclosure: Implementation by AI agent (Claude Opus), reviewed and tested by human

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • extensions/telegram/src/bot-message-context.ts (modified, +1/-0)
  • extensions/telegram/src/bot-message-dispatch.test.ts (modified, +45/-0)
  • extensions/telegram/src/bot-message-dispatch.ts (modified, +65/-0)
  • src/auto-reply/reply/auto-topic-label-config.ts (added, +36/-0)
  • src/auto-reply/reply/auto-topic-label.test.ts (added, +159/-0)
  • src/auto-reply/reply/auto-topic-label.ts (added, +99/-0)
  • src/config/schema.help.ts (modified, +6/-0)
  • src/config/schema.labels.ts (modified, +3/-0)
  • src/config/types.telegram.ts (modified, +13/-0)
  • src/config/zod-schema.providers-core.ts (modified, +14/-0)
  • src/plugin-sdk/reply-runtime.ts (modified, +5/-0)

Code Example

{
  "telegram": {
    "direct": {
      "63448508": {
        "autoTopicLabel": true
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Summary

Automatically rename Telegram DM forum topics when the first message arrives in a new topic/session. Currently users must either manually rename topics or instruct the agent to do it via SOUL.md/system prompt - which is unreliable since the model may ignore the instruction.

Problem

When using Telegram DM topics (forum mode in 1:1 bot chats), new topics get generic names like "Topic #123". Users have to:

  1. Manually rename each topic, OR
  2. Add instructions to SOUL.md/MEMORY.md telling the agent to rename - but this is model-dependent and unreliable (the agent frequently forgets)

This is a gateway-level concern, not something that should depend on model compliance.

Proposed Solution

Add an autoTopicLabel config option to TelegramDirectConfig and/or TelegramAccountConfig:

{
  "telegram": {
    "direct": {
      "63448508": {
        "autoTopicLabel": true
      }
    }
  }
}

Behavior

When autoTopicLabel: true and a message arrives in a DM topic:

  1. Detect if this is the first turn in the session (isFirstTurnInSession already exists in get-reply-run.ts)
  2. After the agent reply is sent, generate a short topic label from the user message (first ~30-50 chars, or a lightweight LLM summary)
  3. Call renameTopic() (API already exists and works)

Implementation Notes

  • isFirstTurnInSession detection already exists in src/auto-reply/reply/get-reply-run.ts:235
  • renameTopic API is fully functional via extensions/telegram/runtime-api.ts
  • editForumTopic action permission exists in TelegramActionConfig
  • Could use a simple heuristic (truncated first message) or a lightweight model call for better labels
  • Should respect actions.editForumTopic permission
  • Should be opt-in (default: false)

Alternatives Considered

  • Agent-level instruction (SOUL.md): Unreliable - model frequently ignores the instruction
  • Internal hook on message:sent: Would work but adds complexity; a config flag is cleaner
  • Manual /set_topic_name command: PR #46983 adds this, but does not solve the auto-rename case

Related

  • PR #46983 - /set_topic_name command (manual rename)
  • Issue #28168 - Session sidebar human-readable titles (similar concept for Control UI)
  • Issue #47812 - Smart session switch reminder (topic change detection)

extent analysis

Fix Plan

To implement the automatic renaming of Telegram DM forum topics, follow these steps:

  1. Add autoTopicLabel config option:

    • Update TelegramDirectConfig and/or TelegramAccountConfig to include the autoTopicLabel option.
    • Set autoTopicLabel to true for the desired Telegram accounts or direct configurations.
  2. Implement topic renaming logic:

    • In get-reply-run.ts, check if autoTopicLabel is true and if the current message is the first turn in the session using isFirstTurnInSession.
    • If both conditions are met, generate a short topic label from the user message.
    • Use a simple heuristic (e.g., truncated first message) or a lightweight LLM summary for better labels.
  3. Call renameTopic() API:

    • After generating the topic label, call the renameTopic() API to update the topic name.
    • Ensure the actions.editForumTopic permission is respected.

Example Code:

// get-reply-run.ts
if (config.autoTopicLabel && isFirstTurnInSession) {
  const topicLabel = generateTopicLabel(userMessage); // Implement generateTopicLabel function
  if (hasPermission('actions.editForumTopic')) {
    renameTopic(topicLabel); // Call renameTopic API
  }
}

// generateTopicLabel function
function generateTopicLabel(message: string): string {
  // Simple heuristic: truncate first 30-50 characters
  return message.substring(0, 50);
  // Alternatively, use a lightweight LLM summary
  // return llmSummarize(message);
}

Verification

To verify the fix, follow these steps:

  1. Set autoTopicLabel to true for a Telegram account or direct configuration.
  2. Start a new conversation in a DM topic.
  3. Send a message to the topic.
  4. Verify that the topic name is automatically updated with a short label generated from the user message.

Extra Tips

  • Ensure the renameTopic() API is properly implemented and functional.
  • Test the autoTopicLabel feature with different user messages and topic names.
  • Consider implementing a fallback mechanism in case the renameTopic() API call fails.

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 Feature: Auto-rename Telegram DM topics based on conversation content [1 pull requests, 1 participants]