#14443: fix(telegram): skip General topic thread ID for all chat types (#14383)
channel: telegram
size: XS
Cluster:
Messaging Platform Improvements
## Summary
Fixes #14383
## Problem
When a Telegram Premium user enables Topics in a private bot chat, incoming messages include `message_thread_id: 1`. OpenClaw stores this thread context with `scope: "dm"`. On proactive sends (cron announcements, etc.), it passes `message_thread_id: 1` back to the Telegram API, which rejects it with:
```
GrammyError: Call to 'sendMessage' failed! (400: Bad Request: message thread not found)
```
### Root Cause
`buildTelegramThreadParams` in `src/telegram/bot/helpers.ts` only skipped thread ID 1 (General topic) when `scope === "forum"`:
```typescript
if (normalized === TELEGRAM_GENERAL_TOPIC_ID && thread.scope === "forum") {
return undefined;
}
```
Private chat topics (Bot API 9.3+, Dec 2025) use `scope: "dm"`, so thread ID 1 was not skipped for DM chats.
## Fix
Remove the `&& thread.scope === "forum"` condition so thread ID 1 is skipped for **all** chat types. Telegram rejects `message_thread_id=1` regardless of whether the chat is a forum supergroup or a private chat with Topics enabled.
**Before:**
```typescript
if (normalized === TELEGRAM_GENERAL_TOPIC_ID && thread.scope === "forum") {
```
**After:**
```typescript
if (normalized === TELEGRAM_GENERAL_TOPIC_ID) {
```
## Effect on User Experience
**Before fix:**
Proactive sends (cron jobs, announcements) to Telegram Premium users with Topics enabled in private bot chats fail with `400: Bad Request: message thread not found`.
**After fix:**
Proactive sends succeed by omitting `message_thread_id` when the thread ID is 1 (General topic), matching the behavior already in place for forum supergroups.
## Testing
- ✅ 39 tests pass (`pnpm vitest run src/telegram/bot/helpers.test.ts src/telegram/bot/delivery.test.ts src/telegram/draft-stream.test.ts`)
- ✅ Lint passes (`pnpm oxlint` on changed files)
- Updated 3 test files to match new behavior
- Added regression tests for non-General DM thread IDs (id=42, id=77) to ensure they still pass through
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts Telegram thread parameter construction so that `message_thread_id=1` (the “General” topic) is omitted for *all* chat types, not just forum supergroups. This addresses a failure mode where private bot chats with Topics enabled (Premium) include `message_thread_id: 1` on inbound messages, and OpenClaw would echo that back on proactive sends, causing Telegram to reject the request.
Tests were updated/added across delivery and draft stream paths to assert that DM threads with id=1 now omit `message_thread_id`, while non-General DM thread IDs still pass through.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is narrowly scoped to `buildTelegramThreadParams` behavior for `message_thread_id=1`, and corresponding tests were updated/added to lock in the new behavior across delivery and draft-stream code paths. No other thread-handling helpers were modified.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
90.0%
#7261: fix(telegram): preserve DM topic thread id for outbound media
by ViffyGwaanl · 2026-02-02
88.7%
#19050: fix(telegram): skip message_thread_id for private chats to prevent ...
by Limitless2023 · 2026-02-17
88.5%
#17952: fix(telegram): support message_thread_id for DM topics
by timbrinded · 2026-02-16
88.1%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
87.8%
#17968: fix(telegram): restore DM topic thread ids with send-path fallback
by Leonccaa · 2026-02-16
86.2%
#6192: Telegram: fix DM Topics thread routing
by ViffyGwaanl · 2026-02-01
86.1%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
86.1%
#17432: fix(telegram): skip message_thread_id for private chats in sticker/...
by clawinho · 2026-02-15
84.2%
#8985: fix(telegram): preserve forum topic context for pairing auto-replies
by lailoo · 2026-02-04
82.9%