fix(telegram): escape horizontal rules in MarkdownV2 output (#586)

Co-authored-by: Letta Code <noreply@letta.com>
This commit is contained in:
Cameron
2026-03-12 22:43:20 -07:00
committed by GitHub
parent acfb90e2e5
commit 35cff5098f

View File

@@ -17,7 +17,11 @@ export async function markdownToTelegramV2(markdown: string): Promise<string> {
// Dynamic import to handle ESM module // Dynamic import to handle ESM module
const telegramifyMarkdown = (await import('telegramify-markdown')).default; const telegramifyMarkdown = (await import('telegramify-markdown')).default;
// Use 'keep' strategy for broad markdown support, including blockquotes. // Use 'keep' strategy for broad markdown support, including blockquotes.
return telegramifyMarkdown(markdown, 'keep'); let result = telegramifyMarkdown(markdown, 'keep');
// telegramify-markdown passes horizontal rules (---) through unescaped.
// '-' is reserved in MarkdownV2 and must be escaped.
result = result.replace(/^-{3,}$/gm, '\\-\\-\\-');
return result;
} catch (e) { } catch (e) {
log.error('Markdown conversion failed, using escape fallback:', e); log.error('Markdown conversion failed, using escape fallback:', e);
// Fallback: escape special characters manually (loses formatting) // Fallback: escape special characters manually (loses formatting)