Skip to content

telegram: require strict numeric reply_to_message_id parsing - #37251

Closed
shuofengzhang wants to merge 5 commits into
openclaw:mainfrom
shuofengzhang:fix/telegram-replyto-strict-id
Closed

shuofengzhang wants to merge 5 commits into
openclaw:mainfrom
shuofengzhang:fix/telegram-replyto-strict-id

Conversation

@shuofengzhang

Copy link
Copy Markdown
Contributor

What changed

  • Tightened parseTelegramReplyToMessageId so it only accepts fully numeric, positive integer strings.
  • Added trimming and strict validation so values like "123abc", "12.3", "-12", and "0" are ignored instead of being partially parsed.
  • Added focused unit tests in src/telegram/outbound-params.test.ts to cover valid/invalid reply IDs and preserve scoped thread-id behavior.

Why

  • reply_to_message_id must be a valid numeric message id.
  • Using parseInt directly accepted partially numeric strings (e.g. "123abc" -> 123), which can cause downstream Telegram send errors and confusing behavior.
  • Strict parsing makes outbound threading behavior safer and more predictable.

Testing

  • ✅ scripts/clone_and_test.sh openclaw/openclaw
    • Result: pass (16 passed)
  • ✅ npx vitest --run src/telegram/outbound-params.test.ts
    • Result: pass (4 passed)

@greptile-apps

greptile-apps Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR tightens parseTelegramReplyToMessageId in src/telegram/outbound-params.ts by replacing a loose parseInt-based approach with strict validation: a /^\d+$/ regex guard, Number.isSafeInteger check, and > 0 check. This prevents partial numeric strings like "123abc", floats, negatives, zero, and unsafe large integers from being accepted as valid Telegram reply_to_message_id values.

The implementation:

  • Improved the null guard from !replyToId to replyToId == null for precision
  • Added explicit trimming and empty-string checks
  • Introduces parsePositiveIntegerId helper to centralize strict validation logic
  • Leaves parseIntegerId, parseTelegramThreadId, and existing scoped thread-id behavior untouched

Tests comprehensively cover valid IDs, non-numeric strings, decimals, negatives, zero, whitespace, and null/undefined inputs. Existing scoped thread-id behavior (e.g., "-100123456:77") is verified as unchanged.

Confidence Score: 5/5

  • Safe to merge. The change is minimal, well-tested, and strictly improves validation behavior with no risk of regressions.
  • The implementation correctly addresses the stated goal of strict reply ID parsing. All edge cases (non-numeric, floats, negatives, zero, unsafe integers, whitespace) are explicitly tested and behave as intended. The diff is focused and surgical—only parseTelegramReplyToMessageId and tests are changed. Existing APIs and behavior (thread IDs, scoped format) remain untouched. Tests pass (4/4 for this file, 16/16 overall).
  • No files require special attention.

Last reviewed commit: 297249d

@shuofengzhang
shuofengzhang force-pushed the fix/telegram-replyto-strict-id branch from 297249d to 15fe9e1 Compare March 6, 2026 06:36
@shuofengzhang
shuofengzhang force-pushed the fix/telegram-replyto-strict-id branch from 15fe9e1 to 50c9332 Compare March 15, 2026 11:22
@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: S and removed size: XS labels Mar 15, 2026
@shuofengzhang
shuofengzhang force-pushed the fix/telegram-replyto-strict-id branch from 5b354c6 to 2fe52b5 Compare March 15, 2026 15:15
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed channel: whatsapp-web Channel integration: whatsapp-web size: S labels Mar 15, 2026
@shuofengzhang
shuofengzhang force-pushed the fix/telegram-replyto-strict-id branch 3 times, most recently from 637a4db to 27fd093 Compare March 30, 2026 00:12
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix agents Agent runtime and tooling size: S and removed size: XS labels Mar 30, 2026
@shuofengzhang
shuofengzhang force-pushed the fix/telegram-replyto-strict-id branch from 27fd093 to 485e11d Compare March 30, 2026 00:20
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed channel: matrix Channel integration: matrix agents Agent runtime and tooling size: S labels Mar 30, 2026
@shuofengzhang
shuofengzhang force-pushed the fix/telegram-replyto-strict-id branch from 485e11d to 957e50b Compare March 30, 2026 23:36
@openclaw-barnacle openclaw-barnacle Bot added the channel: matrix Channel integration: matrix label Mar 31, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed channel: matrix Channel integration: matrix size: S labels Mar 31, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: telegram Channel integration: telegram size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants