fix: delete+resend streaming draft instead of edit with HTML parse_mode switch
Telegram rejects parse_mode changes on existing messages. Old: editMessageText with HTML on a plain-text message → silent fail, raw ** shown. New: deleteMessage + sendFormatted (fresh HTML) → always renders bold/italic correctly.
This commit is contained in:
@@ -279,45 +279,26 @@ export class StreamConsumer {
|
||||
* Falls back to stripped plain text if HTML parse fails.
|
||||
*/
|
||||
async _sendFinalFormatted(text) {
|
||||
const html = markdownToHtml(text);
|
||||
|
||||
// Try HTML edit first (works for short messages)
|
||||
try {
|
||||
if (this._messageId) {
|
||||
await this.ctx.api.editMessageText(this._chatId, this._messageId, html, { parse_mode: 'HTML' });
|
||||
} else {
|
||||
const msg = await this.ctx.api.sendMessage(this.ctx.chat.id, html, { parse_mode: 'HTML' });
|
||||
if (msg?.message_id) {
|
||||
this._messageId = msg.message_id;
|
||||
this._chatId = msg.chat.id;
|
||||
}
|
||||
}
|
||||
this._alreadySent = true;
|
||||
this._finalResponseSent = true;
|
||||
this._lastSentText = html;
|
||||
return;
|
||||
} catch (e) {
|
||||
logger.warn(`Final HTML edit failed (${e.message}), deleting draft and resending`);
|
||||
}
|
||||
|
||||
// Delete the old streaming draft (has raw ** markers)
|
||||
// Delete streaming draft (plain text with raw ** markers)
|
||||
// Editing with parse_mode switch (none→HTML) is unreliable — always delete+resend
|
||||
if (this._messageId) {
|
||||
try {
|
||||
await this.ctx.api.deleteMessage(this._chatId, this._messageId);
|
||||
this._messageId = null;
|
||||
logger.info(`Deleted streaming draft msg ${this._messageId}`);
|
||||
} catch {
|
||||
// Ignore — may already be gone
|
||||
// already gone
|
||||
}
|
||||
this._messageId = null;
|
||||
}
|
||||
|
||||
// Send fresh formatted message(s) via sendFormatted (handles splitting + fallback)
|
||||
// Send fresh formatted HTML
|
||||
try {
|
||||
await sendFormatted(this.ctx, text);
|
||||
this._alreadySent = true;
|
||||
this._finalResponseSent = true;
|
||||
logger.info(`✅ Sent formatted replacement (${text.length} chars)`);
|
||||
} catch (e2) {
|
||||
logger.error('Formatted replacement also failed:', e2.message);
|
||||
logger.info(`Sent formatted final (${text.length} chars)`);
|
||||
} catch (e) {
|
||||
logger.error(`Formatted send failed: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user