← Back to PRs

#22331: Fix Telegram reaction emoji normalization

by AIflow-Labs open 2026-02-21 01:53 View on GitHub →
channel: telegram size: S
## What changed - Normalize Telegram reaction emoji inputs by trimming and NFC-normalizing before sending. - Centralize reaction payload building in `src/telegram/send.ts` and reuse it for regular reactions and ack-reaction flows. - Keep ack-reaction behavior unchanged while avoiding invalid payloads for whitespace-padded emoji values. ## Why this fixes the issue `REACTION_INVALID` can be triggered when configured or computed reaction strings include leading/trailing whitespace (for example `" 👍 "`), which Telegram rejects as malformed. This fix ensures payloads are sanitized and empty/invalid input becomes a no-op. ## Tests run - `pnpm vitest run --config vitest.unit.config.ts src/telegram/send.test.ts src/telegram/bot.create-telegram-bot.test.ts src/telegram/*.test.ts` ## Edge cases - Empty/whitespace-only reaction values now produce an empty reaction payload. - Remove-reaction flows still pass an empty array intentionally. - Ack reaction is sent only when a non-empty, sanitized emoji value is available. ## Notes No unresolved blockers found for these changes. <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR centralizes Telegram reaction emoji normalization by introducing `normalizeTelegramReaction()` and `buildTelegramReactionPayload()` helper functions. The normalization applies both trimming and NFC Unicode normalization before sending reactions to Telegram's API, preventing errors from whitespace-padded or differently-composed emoji strings. **Key changes:** - Centralized reaction payload building in `buildTelegramReactionPayload()` function - Added NFC Unicode normalization to handle emoji composition variations - Applied normalization to ack reactions, remove reactions, and regular reactions - Added test coverage for whitespace normalization The implementation is defensive and handles edge cases (empty strings, whitespace-only values) by returning empty arrays, which Telegram interprets as reaction removal. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The changes are well-tested with 453 passing tests, including new test cases specifically for whitespace normalization. The refactoring centralizes logic into reusable functions without changing behavior, and the NFC normalization follows established patterns already used elsewhere in the codebase (chat.ts). The implementation is defensive, handling edge cases appropriately. - No files require special attention <sub>Last reviewed commit: 92bb311</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs