From 0b38f670e498db484f520e141b2207b2e2dce66b Mon Sep 17 00:00:00 2001 From: Clarity Saint Date: Fri, 30 Jan 2026 13:55:43 +0800 Subject: [PATCH] fix(telegram): guard against empty message text in sendTelegramText Add early return guard in sendTelegramText() to prevent calling Telegram API with empty text, which throws: GrammyError: Call to 'sendMessage' failed! (400: Bad Request: message text is empty) Also strengthen the chunk iteration check to skip chunks with empty html. Closes #4409 --- src/telegram/bot/delivery.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/telegram/bot/delivery.ts b/src/telegram/bot/delivery.ts index 669340b20..f8a81fd0f 100644 --- a/src/telegram/bot/delivery.ts +++ b/src/telegram/bot/delivery.ts @@ -105,7 +105,7 @@ export async function deliverReplies(params: { const chunks = chunkText(reply.text || ""); for (let i = 0; i < chunks.length; i += 1) { const chunk = chunks[i]; - if (!chunk) continue; + if (!chunk?.html?.trim()) continue; // Only attach buttons to the first chunk. const shouldAttachButtons = i === 0 && replyMarkup; await sendTelegramText(bot, chatId, chunk.html, runtime, { @@ -501,6 +501,10 @@ async function sendTelegramText( replyMarkup?: ReturnType; }, ): Promise { + if (!text?.trim()) { + logVerbose("sendTelegramText: skipping empty message"); + return undefined; + } const baseParams = buildTelegramSendParams({ replyToMessageId: opts?.replyToMessageId, replyQuoteText: opts?.replyQuoteText,