Skip to content

WhatsApp outbound: strip leading whitespace from text messages #8036

@kbecking

Description

@kbecking

Problem

LLM responses frequently start with newlines or whitespace characters. On WhatsApp, this results in ugly empty space at the top of message bubbles — making the conversation look broken or poorly formatted.

Root Cause

There is no trimStart() (or equivalent) anywhere in the outbound delivery pipeline. Whatever the model returns is sent verbatim, including any leading \n, \r\n, or spaces.

Affected Delivery Paths

Three separate code paths send text to WhatsApp, and all three are affected:

  1. dist/web/auto-reply/deliver-reply.js — the main auto-reply path (~90% of outbound messages)
  2. dist/infra/outbound/deliver.jssendTextChunks — general outbound delivery for all channels
  3. dist/channels/plugins/outbound/whatsapp.jssendText + sendMedia (caption) — the message tool / programmatic send path

Suggested Fix

Add a single line in each path, before the text is sent:

text = text.replace(/^\s+/, "");
// or: text = text.trimStart();

This strips only leading whitespace — trailing whitespace is left intact (harmless on WhatsApp).

Specific locations

File Function / area Where to add
dist/web/auto-reply/deliver-reply.js Before msg.reply() ~line 14
dist/infra/outbound/deliver.js Inside sendTextChunks, before sending ~line 124
dist/channels/plugins/outbound/whatsapp.js sendText + sendMedia ~lines 55, 65

Notes

  • We have been running this as a manual patch on our installation successfully — no side effects observed.
  • The fix is trivial (4 one-line additions) but has a big impact on message presentation quality.
  • Ideally this would be applied in the source (src/) so it survives npm update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions