Skip to content

Comments

fix(telegram): guard against empty text in editMessageText#938

Merged
IceyLiu merged 1 commit intomainfrom
zynx/fix/telegram-empty-text-edit
Feb 22, 2026
Merged

fix(telegram): guard against empty text in editMessageText#938
IceyLiu merged 1 commit intomainfrom
zynx/fix/telegram-empty-text-edit

Conversation

@piorpua
Copy link
Contributor

@piorpua piorpua commented Feb 22, 2026

Summary

  • Fix GrammyError: Call to 'editMessageText' failed! (400: Bad Request: text must be non-empty) when streaming AI responses via Telegram channel
  • Whitespace-only content (e.g. '\n\n') passed JavaScript truthy checks but was rejected by Telegram API as empty text
  • Add trim() check in ActionExecutor.convertTMessageToOutgoing() to replace whitespace-only text with '...' placeholder
  • Add guard in TelegramPlugin.editMessage() to skip the API call when text is empty or whitespace-only

Test plan

  • Start dev environment and connect a Telegram channel
  • Send a message that triggers AI streaming response
  • Verify console no longer shows text must be non-empty errors
  • Verify messages display correctly with streaming updates working as expected
  • Verify non-Telegram channels are unaffected

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
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@IceyLiu IceyLiu merged commit b83d671 into main Feb 22, 2026
13 checks passed
@piorpua piorpua deleted the zynx/fix/telegram-empty-text-edit branch February 22, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants