Repository navigation
fix(whatsapp): group composing indicator, echo prevention, and presence subscription - #17326
globalcaos wants to merge 3 commits into
Conversation
Additional Comments (3)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/web/inbound/send-api.ts
Line: 91:91
Comment:
`sendPoll` doesn't track message IDs but can also echo back
```suggestion
if (messageId !== "unknown") {
trackSentMessageId(messageId);
}
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/web/inbound/send-api.test.ts
Line: 13:13
Comment:
mock `presenceSubscribe` to match updated type signature
```suggestion
const presenceSubscribe = vi.fn(async () => {});
const api = createWebSendApi({
sock: { sendMessage, sendPresenceUpdate, presenceSubscribe },
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/web/inbound/send-api.test.ts
Line: 154:157
Comment:
add test case for group composing with `presenceSubscribe` call
```suggestion
it("sends composing presence updates to the recipient JID", async () => {
await api.sendComposingTo("+1555");
expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "[email protected]");
expect(presenceSubscribe).not.toHaveBeenCalled();
});
it("subscribes to presence before composing for group JIDs", async () => {
await api.sendComposingTo("[email protected]");
expect(presenceSubscribe).toHaveBeenCalledWith("[email protected]");
expect(sendPresenceUpdate).toHaveBeenCalledWith("composing", "[email protected]");
});
```
How can I resolve this? If you propose a fix, please make it concise. |
bfc1ccb to
f92900f
Compare
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/web/inbound/send-api.ts
Line: 87:91
Comment:
`sendPoll` also returns messageId but doesn't track it - poll messages could echo back
```suggestion
const messageId =
typeof result === "object" && result && "key" in result
? String((result as { key?: { id?: string } }).key?.id ?? "unknown")
: "unknown";
if (messageId !== "unknown") {
trackSentMessageId(messageId);
}
return { messageId };
```
How can I resolve this? If you propose a fix, please make it concise. |
|
This pull request has been automatically marked as stale due to inactivity. |
…ce subscription
Three reliability fixes for WhatsApp Web (Baileys) integration:
1. **Group composing indicator**: Call presenceSubscribe() before
sendPresenceUpdate('composing') in groups. Without this, the typing
indicator silently fails for group JIDs — a known Baileys requirement.
2. **Sent message ID tracking**: Track IDs of messages sent by the bot
and skip them on inbound. Prevents echo loops where WhatsApp delivers
our own voice notes/media back as new messages.
3. **sent-ids module**: Simple in-memory Set with FIFO cleanup (max 500
entries) to support the echo prevention above.
|
This fix is maintained in our fork: globalcaos/tinkerclaw The WhatsApp group composing indicator, echo prevention, and presence subscription fixes are all active and have been running in production for months. If you're hitting these issues, the fork has the working code. Comment by Jarvis, AI assistant to @globalcaos — Human reviewed and approved |
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 requirespresenceSubscribe(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.upsertevents (especially voice notes and media). Without tracking, these get processed as new user messages, causing echo loops.Fix
Group composing (
send-api.ts)presenceSubscribeto the sock type interfacepresenceSubscribe(jid)beforesendPresenceUpdate("composing")when the target is a group JID (@g.us)Echo prevention (
sent-ids.ts+send-api.ts+monitor.ts)sent-ids.tsmodule: simple in-memorySet<string>with FIFO cleanup (max 500 entries)send-api.ts: track message IDs after successful sends viatrackSentMessageId()monitor.ts: skip inbound messages whose ID matches a recently sent message viaisSentByUs()Monitor passthrough (
monitor.ts)presenceSubscribefrom the Baileys socket to the send APIFiles Changed
src/web/inbound/send-api.tssrc/web/inbound/monitor.tssrc/web/inbound/sent-ids.ts3 files, 47 insertions, 0 deletions.
Testing
pnpm build)Greptile Summary
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.
presenceSubscribebeforesendPresenceUpdatefor group JIDssendPolldoesn't track its message ID, which could cause poll messages to echo backConfidence Score: 4/5
sendPollhas the same echo vulnerability assendMessagehad 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.Last reviewed commit: 218de1b