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.
|
* Falls back to stripped plain text if HTML parse fails.
|
||||||
*/
|
*/
|
||||||
async _sendFinalFormatted(text) {
|
async _sendFinalFormatted(text) {
|
||||||
const html = markdownToHtml(text);
|
// Delete streaming draft (plain text with raw ** markers)
|
||||||
|
// Editing with parse_mode switch (none→HTML) is unreliable — always delete+resend
|
||||||
// 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)
|
|
||||||
if (this._messageId) {
|
if (this._messageId) {
|
||||||
try {
|
try {
|
||||||
await this.ctx.api.deleteMessage(this._chatId, this._messageId);
|
await this.ctx.api.deleteMessage(this._chatId, this._messageId);
|
||||||
this._messageId = null;
|
logger.info(`Deleted streaming draft msg ${this._messageId}`);
|
||||||
} catch {
|
} 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 {
|
try {
|
||||||
await sendFormatted(this.ctx, text);
|
await sendFormatted(this.ctx, text);
|
||||||
this._alreadySent = true;
|
this._alreadySent = true;
|
||||||
this._finalResponseSent = true;
|
this._finalResponseSent = true;
|
||||||
logger.info(`✅ Sent formatted replacement (${text.length} chars)`);
|
logger.info(`Sent formatted final (${text.length} chars)`);
|
||||||
} catch (e2) {
|
} catch (e) {
|
||||||
logger.error('Formatted replacement also failed:', e2.message);
|
logger.error(`Formatted send failed: ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user