diff --git a/src/apps/chatwoot/messages/to/whatsapp/markdown.test.ts b/src/apps/chatwoot/messages/to/whatsapp/markdown.test.ts index e8acf5f9..bb9e632d 100644 --- a/src/apps/chatwoot/messages/to/whatsapp/markdown.test.ts +++ b/src/apps/chatwoot/messages/to/whatsapp/markdown.test.ts @@ -15,6 +15,12 @@ describe('MarkdownToWhatsApp', () => { expect(MarkdownToWhatsApp(input)).toBe(expected); }); + // ChatWoot v4.10.1+ escapes newlines with trailing backslash + it('strips trailing backslash before newlines', () => { + const input = 'Hi \\\ntext message \\\nwith line \\\nbreak'; + expect(MarkdownToWhatsApp(input)).toBe('Hi \ntext message \nwith line \nbreak'); + }); + // Tests for URL protection it('preserves URLs with multiple underscores', () => { const input = 'https://example.com/page__name__test'; diff --git a/src/apps/chatwoot/messages/to/whatsapp/markdown.ts b/src/apps/chatwoot/messages/to/whatsapp/markdown.ts index bed57fa1..40c3e860 100644 --- a/src/apps/chatwoot/messages/to/whatsapp/markdown.ts +++ b/src/apps/chatwoot/messages/to/whatsapp/markdown.ts @@ -4,6 +4,8 @@ export function MarkdownToWhatsApp(text: string): string { } return ( text + // Remove trailing backslash before newlines (ChatWoot v4.10.1+ escaping) + .replace(/\\\n/g, '\n') // Triple-backtick blocks → WhatsApp monospace blocks (same syntax) .replace(/```([\s\S]*?)```/g, '```$1```') // Italic **first**, but only single‐star or single‐underscore