-
-
Notifications
You must be signed in to change notification settings - Fork 69.2k
WhatsApp outbound: strip leading whitespace from text messages #8036
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
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:
dist/web/auto-reply/deliver-reply.js— the main auto-reply path (~90% of outbound messages)dist/infra/outbound/deliver.js→sendTextChunks— general outbound delivery for all channelsdist/channels/plugins/outbound/whatsapp.js→sendText+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 survivesnpm update.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Fields
Give feedbackNo fields configured for issues without a type.