#11340: Telegram: skip empty message text instead of throwing (#11238)
channel: telegram
stale
Cluster:
Telegram Message Handling Fixes
## Fix
The Telegram adapter throws an error when `sendMessageTelegram` receives empty or whitespace-only text, which Telegram rejects with `400: Bad Request: message text is empty`. This causes silent failures across multiple codepaths (final reply, heartbeat, agent delivery) with **94 occurrences** reported over ~19 hours.
**Root cause:** `sendMessageTelegram` threw `Error("Message must be non-empty for Telegram sends")` for empty text. Callers (heartbeat responses, interrupted inference results, auth profile cooldown) sometimes produce empty text legitimately, and the throw propagated as an unhandled error.
## Changes
- `src/telegram/send.ts`: Replace `throw` with a warning log + safe no-op return (`{ messageId: "skipped", chatId }`) for empty/whitespace text
- `src/telegram/send.returns-undefined-empty-input.test.ts`: Add 2 regression tests (empty string, whitespace-only)
- `CHANGELOG.md`: Add entry
## Verification
- `pnpm build` passes
- All 33 telegram send tests pass (`npx vitest run src/telegram/send.returns-undefined-empty-input.test.ts`)
- New tests confirm empty and whitespace-only text returns `{ messageId: "skipped", chatId }` without calling `api.sendMessage`
Fixes #11238
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates the Telegram adapter’s `sendMessageTelegram` to treat empty or whitespace-only message text as a safe no-op: it logs a diagnostic warning and returns `{ messageId: "skipped", chatId }` rather than throwing. Regression tests were added to ensure empty/whitespace text does not call `api.sendMessage`, and the changelog documents the fix.
Overall this aligns Telegram behavior with other channel senders that treat empty content as “skipped”, preventing unhandled exceptions from bubbling through higher-level delivery paths.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is narrowly scoped (empty/whitespace text handling), adds targeted regression tests, and follows an existing pattern by other channel senders (returning a "skipped" result instead of throwing). No other logic paths were altered.
- No files require special attention
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#7218: fix(telegram): skip empty text messages in threaded mode
by ArsalanShakil · 2026-02-02
87.2%
#17769: fix(telegram): preserve reply text in threaded mode dispatch
by Glucksberg · 2026-02-16
83.1%
#17629: fix(telegram): fall back to plain text when HTML formatter produces...
by Glucksberg · 2026-02-16
82.3%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
80.4%
#19375: telegram: align tool-error summaries
by NorthyIE · 2026-02-17
79.9%
#19800: fix(telegram): add INFO-level logging at inbound message drop paths
by katalabut · 2026-02-18
78.9%
#16548: fix(telegram): enhance chat_id validation and diagnostics
by tanujbhaud · 2026-02-14
78.5%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
78.5%
#17953: fix(telegram): prevent silent message loss and duplicate messages i...
by zuyan9 · 2026-02-16
78.5%
#6463: fix(telegram): improve timeout handling and prevent channel exits
by ai-fanatic · 2026-02-01
78.0%