fix(telegram): validate replyToMessageId before sending to Telegram API#56587
Conversation
Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Greptile SummaryThis PR centralises
The implementation looks correct and complete. No critical issues found. Confidence Score: 5/5Safe to merge — the fix is narrowly scoped, all four send paths are covered, and 139 tests pass. All findings are P2 or lower. The core validation logic is correct, the regex /^-?\d+$/ rejects every described invalid input, the normalizer is applied consistently across all sinks, and the regression test directly reproduces the bug. No breaking contract changes for callers of the exported functions. No files require special attention.
|
| Filename | Overview |
|---|---|
| extensions/telegram/src/outbound-params.ts | Introduces normalizeTelegramReplyToMessageId(unknown) as the single source of truth for reply-ID validation; delegates the legacy parseTelegramReplyToMessageId to it. |
| extensions/telegram/src/bot/helpers.ts | resolveTelegramReplyId is now a one-liner delegating to normalizeTelegramReplyToMessageId; removes the old Number(raw) path that could return floats. |
| extensions/telegram/src/bot/delivery.send.ts | buildTelegramSendParams validates replyToMessageId through the normalizer before placing it into API params. |
| extensions/telegram/src/draft-stream.ts | createTelegramDraftStream now validates replyToMessageId through the normalizer; rest of streaming logic unchanged. |
| extensions/telegram/src/send.ts | buildTelegramThreadReplyParams now calls normalizeTelegramReplyToMessageId instead of the bare Math.trunc guard, covering the NaN/non-numeric bypass. |
| extensions/telegram/src/send.test.ts | New regression test covers session-meta-id, 123abc, and NaN for both sendMessageTelegram and sendStickerTelegram paths. |
Reviews (1): Last reviewed commit: "fix(telegram): validate replyToMessageId..." | Re-trigger Greptile
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
…PI (openclaw#56587) Add shared normalizeTelegramReplyToMessageId() that rejects non-numeric, NaN, and mixed-content strings before they reach the Telegram Bot API. Apply at all four API sinks: direct send, bot delivery, draft stream, and bot helpers. Prevents GrammyError 400 when non-numeric values from session metadata slip through typed boundaries. Fixes openclaw#37222
Add missing changelog entries for PRs openclaw#56500, openclaw#56540, openclaw#56555, openclaw#56567, openclaw#56573, openclaw#56587, openclaw#56595, openclaw#56612, openclaw#56620.
Summary
normalizeTelegramReplyToMessageId()normalizer inoutbound-params.ts"123abc"), whitespaceRoot Cause
Telegram's Bot API expects
reply_to_message_idto be a numeric integer. Multiple call sites passed the value through without validation, trusting typed boundaries. When runtime values like session metadata IDs ("session-meta-id") reached the API, Grammy rejected the send.Change Type
Testing
139 tests pass across 3 test files. New regression test covers:
"session-meta-id") → omitted"123abc") → omittedFixes #37222