← Back to PRs

#17326: fix(whatsapp): group composing indicator, echo prevention, and presence subscription

by globalcaos open 2026-02-15 17:03 View on GitHub →
channel: whatsapp-web stale size: XS
## Problem Three independent but related WhatsApp reliability issues discovered while running a 24/7 OpenClaw agent on WhatsApp: ### 1. Typing indicator silently fails in groups `sendPresenceUpdate("composing", groupJid)` does nothing in groups because Baileys requires `presenceSubscribe(jid)` first for group JIDs. This is a known Baileys behavior — without subscribing, presence updates are silently dropped. ### 2. Bot re-ingests its own voice notes / media WhatsApp sometimes delivers the bot's own sent messages back as inbound `messages.upsert` events (especially voice notes and media). Without tracking, these get processed as new user messages, causing echo loops. ## Fix ### Group composing (`send-api.ts`) - Add `presenceSubscribe` to the sock type interface - Call `presenceSubscribe(jid)` before `sendPresenceUpdate("composing")` when the target is a group JID (`@g.us`) - Non-fatal: if subscribe fails, composing is still attempted ### Echo prevention (`sent-ids.ts` + `send-api.ts` + `monitor.ts`) - New `sent-ids.ts` module: simple in-memory `Set<string>` with FIFO cleanup (max 500 entries) - `send-api.ts`: track message IDs after successful sends via `trackSentMessageId()` - `monitor.ts`: skip inbound messages whose ID matches a recently sent message via `isSentByUs()` ### Monitor passthrough (`monitor.ts`) - Expose `presenceSubscribe` from the Baileys socket to the send API ## Files Changed | File | Change | |------|--------| | `src/web/inbound/send-api.ts` | Add presenceSubscribe to sock type, track sent IDs, subscribe before composing in groups | | `src/web/inbound/monitor.ts` | Pass presenceSubscribe to send API, skip self-sent messages on inbound | | `src/web/inbound/sent-ids.ts` | **New** — sent message ID tracking with bounded FIFO cleanup | **3 files, 47 insertions, 0 deletions.** ## Testing - Build passes (`pnpm build`) - Manual testing: 24/7 WhatsApp agent with voice notes in groups — no more echo loops, typing indicator now visible in groups <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds group typing indicator support and echo prevention for WhatsApp messages. The implementation correctly subscribes to presence before sending composing indicators in groups, and tracks sent message IDs to filter out echo loops. - Fixed typing indicator in groups by calling `presenceSubscribe` before `sendPresenceUpdate` for group JIDs - Added in-memory tracking of sent message IDs with bounded FIFO cleanup (max 500 entries) - Filters out self-sent messages in the inbound handler to prevent echo loops - One issue found: `sendPoll` doesn't track its message ID, which could cause poll messages to echo back <h3>Confidence Score: 4/5</h3> - Safe to merge after addressing the sendPoll message ID tracking gap - The implementation correctly solves the stated problems with sound architectural choices. The typing indicator fix is straightforward and properly handles failure. The echo prevention mechanism uses an appropriate bounded in-memory Set with FIFO cleanup. However, `sendPoll` has the same echo vulnerability as `sendMessage` had before this fix - it returns a messageId but doesn't track it, which could cause poll messages to be re-ingested. This is a logical gap in the implementation that should be addressed to fully prevent echo loops. - src/web/inbound/send-api.ts requires attention for the sendPoll message ID tracking issue <sub>Last reviewed commit: 218de1b</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs