Skip to content

Commit e75c29d

Browse files
danilipariDani Lipari
andauthored
[core] fix: strip escaped newlines from ChatWoot v4.10.1+ messages (#1900)
ChatWoot v4.10.1 escapes newlines by prepending a trailing backslash before each line break in webhook payloads. This caused literal backslash characters to appear in WhatsApp messages. Strip the trailing backslash before newlines in MarkdownToWhatsApp() so line breaks are preserved correctly. Closes #1833 Mentions chatwoot/chatwoot#13348 Co-authored-by: Dani Lipari <dani.lipari@dontouch.ch>
1 parent f8329c2 commit e75c29d

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/apps/chatwoot/messages/to/whatsapp/markdown.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe('MarkdownToWhatsApp', () => {
1515
expect(MarkdownToWhatsApp(input)).toBe(expected);
1616
});
1717

18+
// ChatWoot v4.10.1+ escapes newlines with trailing backslash
19+
it('strips trailing backslash before newlines', () => {
20+
const input = 'Hi \\\ntext message \\\nwith line \\\nbreak';
21+
expect(MarkdownToWhatsApp(input)).toBe('Hi \ntext message \nwith line \nbreak');
22+
});
23+
1824
// Tests for URL protection
1925
it('preserves URLs with multiple underscores', () => {
2026
const input = 'https://example.com/page__name__test';

src/apps/chatwoot/messages/to/whatsapp/markdown.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export function MarkdownToWhatsApp(text: string): string {
44
}
55
return (
66
text
7+
// Remove trailing backslash before newlines (ChatWoot v4.10.1+ escaping)
8+
.replace(/\\\n/g, '\n')
79
// Triple-backtick blocks → WhatsApp monospace blocks (same syntax)
810
.replace(/```([\s\S]*?)```/g, '```$1```')
911
// Italic **first**, but only single‐star or single‐underscore

0 commit comments

Comments
 (0)