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 channels
dist/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 survives npm update.
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 pathSuggested Fix
Add a single line in each path, before the text is sent:
This strips only leading whitespace — trailing whitespace is left intact (harmless on WhatsApp).
Specific locations
dist/web/auto-reply/deliver-reply.jsmsg.reply()dist/infra/outbound/deliver.jssendTextChunks, before sendingdist/channels/plugins/outbound/whatsapp.jssendText+sendMediaNotes
src/) so it survivesnpm update.