Skip to content

Chatwoot integration: outgoing messages have trailing newlines on WhatsApp #2415

@devopspcnet

Description

@devopspcnet

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

  1. Connect Chatwoot to WhatsApp via Evolution API
  2. Open a conversation in Chatwoot web UI
  3. Type a message and send it as an agent
  4. 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:

  1. Text messages + captions — the variable i (content with markdown conversion) and the raw t.content are used as-is
  2. Template messagest.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions