fix(telegram): guard against empty text in editMessageText#938
Conversation
Whitespace-only content (e.g. '\n\n') passed JavaScript truthy checks but was rejected by Telegram API as empty text. - ActionExecutor: use trim() to detect whitespace-only text and fall back to '...' placeholder - TelegramPlugin: skip editMessageText call when text is empty or whitespace-only
There was a problem hiding this comment.
Code Review
MEDIUM Issues
1. Potential runtime error if formatTextForPlatform() ever returns a non-string
File: src/channels/gateway/ActionExecutor.ts:157-160
const rawText = formatTextForPlatform(message.content.content || '', platform);
const text = rawText.trim() ? rawText : '...';Problem: rawText.trim() assumes formatTextForPlatform() always returns a string. Today it does, but this is a fragile contract: if any future platform formatter accidentally returns null/undefined (or a non-string), this will throw at runtime during streaming and break message delivery.
Fix: Make the guard resilient by normalizing to string before trimming.
const rawText = formatTextForPlatform(message.content.content || '', platform) ?? '';
const normalized = String(rawText);
const text = normalized.trim() ? normalized : '...';(If you want to keep types tighter, ensure formatTextForPlatform cannot return anything but string and keep the ?? ''.)
Summary
| Level | Count |
|---|---|
| CRITICAL | 0 |
| HIGH | 0 |
| MEDIUM | 1 |
🤖 This review was generated by AI and may contain inaccuracies. Please focus on issues you agree with and feel free to disregard any that seem incorrect. Thank you for your contribution!
Summary
GrammyError: Call to 'editMessageText' failed! (400: Bad Request: text must be non-empty)when streaming AI responses via Telegram channel'\n\n') passed JavaScript truthy checks but was rejected by Telegram API as empty texttrim()check inActionExecutor.convertTMessageToOutgoing()to replace whitespace-only text with'...'placeholderTelegramPlugin.editMessage()to skip the API call when text is empty or whitespace-onlyTest plan
text must be non-emptyerrors