← Back to PRs

#16548: fix(telegram): enhance chat_id validation and diagnostics

by tanujbhaud open 2026-02-14 21:15 View on GitHub →
channel: telegram agents stale size: L
Fixes #15206. Adds specific error messages when attempting to send messages to private users via @username, which is not supported by the Telegram Bot API. Also adds defensive checks for non-numeric chat IDs in the message context builder. Includes a new regression test file. <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR enhances Telegram `chat_id` validation and error diagnostics. The changes add specific error messages when attempting to send messages to private users via `@username` (which Telegram Bot API doesn't support), tighten the username regex to be more accurate (usernames must start with a letter), and add defensive logging for non-numeric chat IDs in the message context builder. Includes comprehensive test coverage for the new validation logic. **Key changes:** - Refactored `wrapChatNotFoundError()` to provide clearer error messages, specifically calling out the `@username` limitation for private users - Tightened `normalizeChatId()` regex to properly distinguish numeric IDs from usernames (usernames must start with a letter, not a digit) - Added diagnostic logging in `buildTelegramMessageContext()` for non-numeric or unsafe integer `chat_id` values - Added comprehensive regression test file `send.chat-id-validation.test.ts` covering various chat ID formats and error scenarios - Moved `sendWithThreadFallback()` to module scope to eliminate duplication across functions - Added new workflow documentation in `.agent/workflows/issue_resolution.md` <h3>Confidence Score: 3/5</h3> - This PR is mostly safe but has a known test issue that was already flagged - The code changes are solid and improve error handling, but the test file is missing required mocks (as noted in previous review threads). The test will likely fail when `sendMessageTelegram` tries to call unmocked functions like `recordChannelActivity`, `loadWebMedia`, or other infra utilities. The core logic changes are good, but the incomplete test setup reduces confidence that the changes are fully validated. - Pay close attention to `src/telegram/send.chat-id-validation.test.ts` - it needs additional mocks before it can pass <sub>Last reviewed commit: 2338147</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs