-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
When agents send messages from Chatwoot UI, the messages arrive on WhatsApp with visible blank space below the text. This happens because Chatwoot's TipTap editor stores messages with trailing newlines (\n\n\n), and the Evolution API's Chatwoot integration sends them without trimming.
Environment
- Evolution API: v2.3.7
- Chatwoot: v4.10.1
- Channel: WhatsApp (via Baileys)
Steps to Reproduce
- Connect Chatwoot to WhatsApp via Evolution API
- Open a conversation in Chatwoot web UI
- Type a message and send it as an agent
- Check the message on WhatsApp
Expected: Message appears without extra whitespace
Actual: Message has 2-3 blank lines below the text
Root Cause
In chatwoot.service.js, the receiveWebhook method processes outgoing messages in three code paths, none of which trim trailing newlines:
- Text messages + captions — the variable
i(content with markdown conversion) and the rawt.contentare used as-is - Template messages —
t.content.replace(/\\\r\n|\\\n|\n/g, '\n')normalizes newlines but doesn't trim trailing ones
Suggested Fix
Add .replace(/\n+$/, "") at the end of each content processing path:
Path 1 — Text/captions (markdown ternary):
// Before
...,"```$1```"):t.content,
// After
...,"```$1```").replace(/\n+$/,""):t.content?.replace(/\n+$/,""),Path 2 — Template messages:
// Before
text: t.content.replace(/\\\r\n|\\\n|\n/g, '\n')
// After
text: t.content.replace(/\\\r\n|\\\n|\n/g, '\n').replace(/\n+$/, "")This preserves internal newlines (multi-line messages) and only removes trailing blank lines.
Workaround
We are currently patching chatwoot.service.js manually inside the container and reapplying after each upgrade.
Related
- Chatwoot issue: CTRL+ENTER to send message adds a newline as well chatwoot/chatwoot#10141 (TipTap adds trailing newlines)
- Chatwoot PR: fix(input): prevent newline when sending with CTRL+ENTER chatwoot/chatwoot#12943 (partial fix, not merged)