#8052: fix(whatsapp): strip leading whitespace from outbound messages
channel: whatsapp-web
stale
Cluster:
WhatsApp Enhancements and Fixes
Fixes #8036.
## The Problem
LLM responses frequently start with newlines, causing empty space at the top of WhatsApp messages. This looks broken or poorly formatted on mobile devices.
## The Fix
Added `.trimStart()` to the text payload in three key delivery paths:
1. `src/web/auto-reply/deliver-reply.ts`: The main auto-reply path.
2. `src/infra/outbound/deliver.ts`: General outbound delivery logic (ensures chunks are also trimmed).
3. `src/channels/plugins/outbound/whatsapp.ts`: Programmatic sending (e.g., via tools).
## Verification
- Verified that trailing whitespace is preserved (harmless on WhatsApp).
- Verified that empty strings (or strings becoming empty after trim) are handled safely.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR addresses leading blank space in WhatsApp deliveries (often caused by LLMs starting responses with newlines) by applying `trimStart()` in multiple outbound paths:
- WhatsApp outbound plugin: trims `text` before calling `sendMessageWhatsApp`.
- Core outbound delivery (`deliverOutboundPayloads`): trims the overall text and each chunk before sending, and skips sending if trimming produces an empty string.
- Web auto-reply delivery: trims each text chunk before replying and skips empty results.
It also includes small, unrelated changes in cron timer/job comments and `runCommandWithTimeout` spawn logic (stdin-inherit fallback).
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge; the trimming changes are localized, with one likely missed WhatsApp caption path.
- The main behavior change (leading-whitespace stripping) is straightforward and guarded against empty sends in core delivery. The only notable issue found is that media captions in the web auto-reply path are not trimmed, so the user-visible bug can still occur for media replies. Other touched areas (cron comments, spawn fallback) don’t show obvious functional regressions from the diff shown.
- src/web/auto-reply/deliver-reply.ts (media caption path), and verify cron/spawn changes are intended for this PR’s scope.
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#7395: fix(whatsapp): strip markdown bold/italic from URLs before sending
by lailoo · 2026-02-02
83.3%
#10196: fix(whatsapp): sanitize raw mention IDs in outbound messages
by koala73 · 2026-02-06
81.2%
#19303: Fix WhatsApp internal error leakage + cron.run timeout defaults
by koala73 · 2026-02-17
80.9%
#12325: fix: trim leading/trailing whitespace from outbound messages
by jordanstern · 2026-02-09
80.6%
#15786: fix: strip device suffix from selfJid in WhatsApp mention matching
by kenken64 · 2026-02-13
79.4%
#9606: fix: pass fileName to WhatsApp document messages
by AytuncYildizli · 2026-02-05
79.4%
#13431: feat(whatsapp): add built-in Markdown to WhatsApp format transform
by asklee-klawd · 2026-02-10
78.8%
#16785: fix(whatsapp): preserve document filenames in outbound Baileys mode
by SahilSahu731 · 2026-02-15
77.5%
#7458: fix: pass filename through to WhatsApp document sends (#7446)
by gavinbmoore · 2026-02-02
77.1%
#12700: fix(tts): deliver WhatsApp voice as opus bubble instead of MP3 (#12...
by lailoo · 2026-02-09
77.0%