@ -92,6 +92,12 @@ function markDelivered(progress: DeliveryProgress): void {
progress . deliveredCount += 1 ;
}
function filterEmptyTelegramTextChunks < T extends { text : string } > ( chunks : readonly T [ ] ) : T [ ] {
// Telegram rejects whitespace-only text payloads; drop them before sendMessage so
// hook-mutated or model-emitted empty replies become a no-op instead of a 400.
return chunks . filter ( ( chunk ) = > chunk . text . trim ( ) . length > 0 ) ;
}
async function deliverTextReply ( params : {
bot : Bot ;
chatId : string ;
@ -108,8 +114,9 @@ async function deliverTextReply(params: {
progress : DeliveryProgress ;
} ) : Promise < number | undefined > {
let firstDeliveredMessageId : number | undefined ;
const chunks = filterEmptyTelegramTextChunks ( params . chunkText ( params . replyText ) ) ;
await sendChunkedTelegramReplyText ( {
chunks : params.chunkText ( params . replyText ) ,
chunks ,
progress : params.progress ,
replyToId : params.replyToId ,
replyToMode : params.replyToMode ,
@ -155,8 +162,9 @@ async function sendPendingFollowUpText(params: {
replyToMode : ReplyToMode ;
progress : DeliveryProgress ;
} ) : Promise < void > {
const chunks = filterEmptyTelegramTextChunks ( params . chunkText ( params . text ) ) ;
await sendChunkedTelegramReplyText ( {
chunks : params.chunkText ( params . text ) ,
chunks ,
progress : params.progress ,
replyToId : params.replyToId ,
replyToMode : params.replyToMode ,
@ -204,7 +212,7 @@ async function sendTelegramVoiceFallbackText(opts: {
replyQuoteText? : string ;
} ) : Promise < number | undefined > {
let firstDeliveredMessageId : number | undefined ;
const chunks = opts. chunkText ( opts . text ) ;
const chunks = filterEmptyTelegramTextChunks( opts. chunkText ( opts . text ) ) ;
let appliedReplyTo = false ;
for ( let i = 0 ; i < chunks . length ; i += 1 ) {
const chunk = chunks [ i ] ;