feat(telegram): auto-rename DM topics on first message#51502
feat(telegram): auto-rename DM topics on first message#51502obviyus merged 5 commits intoopenclaw:mainfrom
Conversation
0c93bd7 to
57c63ab
Compare
Greptile SummaryThis PR adds an auto-rename feature for Telegram DM forum topics on first message in a session, using an LLM to generate a short descriptive label. The implementation is clean: config resolution is separated into a lightweight, independently-testable file ( All four previously-flagged concerns have been resolved in this revision:
Remaining minor observation:
Confidence Score: 5/5
Last reviewed commit: "fix(telegram): addre..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57c63ab7f6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
This comment was marked as outdated.
This comment was marked as outdated.
48c0228 to
3c873fb
Compare
|
@greptile-apps review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c873fb6fe
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
3c873fb to
68842cd
Compare
|
@greptile review |
|
@aisle-research-bot review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68842cd80b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Follow-up fixes pushed:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3faa2b373a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
fix(telegram): use bot.api for topic rename to avoid SecretRef resolution
- Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel
f8d1036 to
2cab5c4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2cab5c4dc7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const result = await completeSimple( | ||
| resolved.model, |
There was a problem hiding this comment.
Register custom model transports before calling completeSimple
In agents whose default model uses a nonstandard transport, this helper bypasses the setup we already need elsewhere before calling pi-ai. src/tts/tts-core.ts:476-489 registers Ollama with ensureCustomApiRegistered(...), and src/agents/pi-embedded-runner/run/attempt.ts:2200-2219 swaps in custom transports for Ollama and Anthropic Vertex. Calling completeSimple directly here means first-message topic renames will consistently fail for those model configs even though normal replies still work.
Useful? React with 👍 / 👎.
| const entry = resolveSessionStoreEntry({ store, sessionKey }).existing; | ||
| isFirstTurnInSession = !entry?.systemSent; |
There was a problem hiding this comment.
Base the rename guard on topic history instead of session state
This treats “first message” as “first turn in the current session”, but Telegram topics can be rebound onto a different session key: extensions/telegram/src/conversation-route.ts:120-138 rewrites route.sessionKey from a channel binding, and extensions/telegram/src/bot-message-context.ts:229-241 then derives the DM-topic session key from that route. In those bound-topic setups, rebinding the same topic to a fresh session makes the next post satisfy !entry?.systemSent, so an existing topic gets renamed again even though it is no longer the topic’s first message.
Useful? React with 👍 / 👎.
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]>
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]>
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]>
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 466debb)
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 466debb)
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 466debb)
* refactor: share telegram network test helpers (cherry picked from commit 05a1b0c) * fix: bypass telegram runtime proxy during health checks (cherry picked from commit 1b31ede) * refactor: share telegram voice send path (cherry picked from commit 1d99401) * refactor: share telegram named account dm fixtures (cherry picked from commit 2cd1a4b) * test: share telegram sticky fetch helpers (cherry picked from commit 34a5523) * test(telegram): cover caption and forum service helpers (cherry picked from commit 377be13) * test: refine telegram token coverage (cherry picked from commit 3e8d9bc) * refactor: share telegram reply chunk threading (cherry picked from commit 5197171) * fix: align telegram probe test mock (cherry picked from commit 5f78057) * refactor: share telegram native command auth harness (cherry picked from commit 60dc46a) * test: share telegram monitor startup helpers (cherry picked from commit 66aabf5) * test(telegram): cover normalization and status issues (cherry picked from commit 833d0df) * refactor: share lane delivery test flows (cherry picked from commit 9780e99) * refactor: share telegram channel test harnesses (cherry picked from commit 9ecd189) * refactor: share telegram outbound send options (cherry picked from commit a57c590) * test: share lane delivery final helpers (cherry picked from commit ba1d7b2) * refactor: share telegram payload send flow (cherry picked from commit bc1cc2e) * test(telegram): cover dm access and allowed updates (cherry picked from commit bd8ca6d) * test: share telegram draft stream helpers (cherry picked from commit d78b7b3) * fix: widen telegram reply progress typing (cherry picked from commit d886ca6) * fix(telegram): prevent duplicate messages with slow LLM providers (openclaw#41932) Merged via squash. Prepared head SHA: 2f50c51 Co-authored-by: hougangdev <[email protected]> Co-authored-by: obviyus <[email protected]> Reviewed-by: @obviyus (cherry picked from commit e37e1ed) * refactor: share telegram dispatch failure harness (cherry picked from commit f201bad) * test: share telegram account helpers (cherry picked from commit fbdea7f) * Telegram: split setup adapter helpers (cherry picked from commit 0672156) * refactor(telegram): share plugin base config (cherry picked from commit 3cc1c7b) * feat(telegram): auto-rename DM topics on first message (openclaw#51502) * feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 466debb) * fix(security): harden explicit-proxy SSRF pinning (cherry picked from commit 55ad5d7) * fix: stabilize full gate (cherry picked from commit 5fb7a13) * Telegram: consolidate message tool discovery (cherry picked from commit 60104de) * Telegram: preserve inbound debounce order (cherry picked from commit 9a34a60) * feat(telegram): add topic-edit action (cherry picked from commit a516141) * refactor: move telegram onboarding to setup wizard (cherry picked from commit a4047bf) * fix: harden gateway SIGTERM shutdown (openclaw#51242) (thanks @juliabush) * fix: increase shutdown timeout to avoid SIGTERM hang * fix(telegram): abort polling fetch on shutdown to prevent SIGTERM hang * fix(gateway): enforce hard exit on shutdown timeout for SIGTERM * fix: tighten gateway shutdown watchdog * fix: harden gateway SIGTERM shutdown (openclaw#51242) (thanks @juliabush) --------- Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit e94ebfa) * fix: adapt cherry-picks for fork TS strictness - Remove duplicate renameForumTopicTelegram function in send.ts - Restore tts.test.ts to fork version (upstream version has gutted pi-ai deps) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore fork versions of test files overwritten by upstream - monitor.test.ts: upstream version references tagTelegramNetworkError not in fork - send.test.ts: upstream version references missing test helpers and unexported functions Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: remove withPinnedLookup call not available in fork Use direct proxyTls spread instead of upstream's withPinnedLookup helper which was removed during fork restructuring. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: resolve type errors from cherry-pick adaptations - Add missing GetReplyOptions/MsgContext imports to bot test - Fix warn parameter typing in draft-stream test Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore bot test files to fork versions Upstream versions have deeply entangled barrel import paths that don't exist in the fork's restructured module layout. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: align test helpers with refactored exports - Rename createNativeCommandTestParams -> createNativeCommandsHarness - Widen matchPluginCommand mock return type for test flexibility Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore bot-native-commands.test.ts to fork version Upstream harness refactoring changed return types incompatible with the test's existing assertions. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore all bot-native-commands test files to fork versions Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore all native-command test infrastructure to fork versions The upstream refactoring of test helpers is incompatible with the fork's existing test patterns. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore bot-message-dispatch.test.ts to fork version Upstream version uses telegramDeps injection pattern not in fork. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore test files with upstream-incompatible patterns Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore media fetch network test to fork version Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore remoteclaw-root test to fork version Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore outbound test files to fork versions Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: resolve remaining type errors from cherry-pick adaptations - Restore test files overwritten by upstream full-gate commit - Fix OpenClawConfig -> RemoteClawConfig in extension files - Fix barrel import paths in extension test files Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: remove incompatible upstream files and relocate test files - Remove setup/shared files that depend on upstream barrel exports - Move extension test files to src/telegram/ where their modules live - Restore channel.ts to fork version Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: final type error cleanup from cherry-pick batch - Restore types.plugin.ts to fork version (setup-wizard removed) - Remove normalize/status-issues tests (modules at extension paths) - Fix readonly array spread in allowed-updates test - Add explicit types for dm-access test callback parameters Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore test-parallel.mjs to fork version Upstream version references vitest.channel-paths.mjs which doesn't exist in the fork. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore test files causing CI failures to fork versions Upstream test changes reference infrastructure patterns (gateway injection, plugin runtime seams) not available in the fork. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore outbound/telegram.ts to fork version The upstream sendTelegramPayloadMessages refactor may have side effects on channel registration in tests. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore message-channel.ts to fork version Upstream's symbol-based registry lookup breaks channel resolution in test isolation without the full gateway injection infrastructure. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: Wayne <[email protected]> Co-authored-by: Taras Lukavyi <[email protected]> Co-authored-by: Gustavo Madeira Santana <[email protected]> Co-authored-by: Onur Solmaz <[email protected]> Co-authored-by: Julia Bush <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]>
* feat(telegram): auto-rename DM topics on first message fix(telegram): use bot.api for topic rename to avoid SecretRef resolution * fix(telegram): address security + test review feedback - Fix test assertion: DEFAULT_PROMPT_SUBSTRING matches 'very short' - Use RawBody instead of Body (no envelope metadata to LLM) - Truncate user message to 500 chars for LLM prompt - Remove user-derived content from verbose logs - Remove redundant threadSpec.id null check - Fix AutoTopicLabelParams type to match generateTopicLabel * fix(telegram): use effective dm auto-topic config * fix(telegram): detect direct auto-topic overrides * fix: auto-rename Telegram DM topics on first message (openclaw#51502) (thanks @Lukavyi) --------- Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 466debb)
Summary
Auto-rename Telegram DM forum topics on first message in a session using LLM. Adds
autoTopicLabelconfig option (default: enabled) with optional custom prompt support.Closes #51485
Behavior Changes
autoTopicLabelconfig field onTelegramAccountConfigandTelegramDirectConfigautoTopicLabel: true/false) and object form ({ enabled: true, prompt: "..." }) for custom promptsbot.api.editForumTopicdirectly (avoids SecretRef resolution issues withrenameForumTopicTelegram)RawBody(not formatted envelopeBody) to avoid sending metadata to LLMConfig Examples
Tests
Secret word: lobster-biscuit
Sign-Off