Skip to content

Commit e45533d

Browse files
joelnishanthmcaxtr
andauthored
fix(whatsapp): drop fromMe echoes in self-chat DMs using outbound ID tracking (#54570)
Merged via squash. Prepared head SHA: dad53ca Co-authored-by: joelnishanth <[email protected]> Co-authored-by: mcaxtr <[email protected]> Reviewed-by: @mcaxtr
1 parent 6fd9d2f commit e45533d

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Docs: https://docs.openclaw.ai
3535
- Agents/status: use provider-aware context window lookup for fresh Anthropic 4.6 model overrides so `/status` shows the correct 1.0m window instead of an underreported shared-cache minimum. (#54796) Thanks @neeravmakwana.
3636
- CLI/message send: write manual `openclaw message send` deliveries into the resolved agent session transcript again by always threading the default CLI agent through outbound mirroring. (#54187) Thanks @KevInTheCloud5617.
3737
- CLI/onboarding: show the Kimi Code API key option again in the Moonshot setup menu so the interactive picker includes all Kimi setup paths together. Fixes #54412 Thanks @sparkyrider
38+
- WhatsApp: fix infinite echo loop in self-chat DM mode where the bot's own outbound replies were re-processed as new inbound user messages. (#54570) Thanks @joelnishanth
3839

3940
## 2026.3.24
4041

‎extensions/whatsapp/src/inbound/monitor.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ export async function monitorWebInbox(options: {
218218
}
219219

220220
const group = isGroupJid(remoteJid);
221+
// Drop echoes of messages the gateway itself sent (tracked by sendTrackedMessage).
222+
// Applies to both groups and DMs/self-chat — without this, self-chat mode
223+
// re-processes the bot's own replies as new inbound user messages.
221224
if (
222-
group &&
223225
Boolean(msg.key?.fromMe) &&
224226
id &&
225227
isRecentOutboundMessage({
@@ -228,7 +230,7 @@ export async function monitorWebInbox(options: {
228230
messageId: id,
229231
})
230232
) {
231-
logVerbose(`Skipping recent outbound WhatsApp group echo ${id} for ${remoteJid}`);
233+
logVerbose(`Skipping recent outbound WhatsApp echo ${id} for ${remoteJid}`);
232234
return null;
233235
}
234236
if (id) {

‎extensions/whatsapp/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,45 @@ describe("web monitor inbox", () => {
298298
await listener.close();
299299
});
300300

301+
it("filters self-chat DM fromMe echoes when the gateway sent the matching message id", async () => {
302+
mockLoadConfig.mockReturnValue({
303+
channels: {
304+
whatsapp: {
305+
selfChatMode: true,
306+
allowFrom: ["+123"],
307+
},
308+
},
309+
messages: DEFAULT_MESSAGES_CFG,
310+
});
311+
312+
const onMessage = vi.fn();
313+
const { listener, sock } = await startInboxMonitor(onMessage);
314+
315+
sock.sendMessage.mockResolvedValueOnce({ key: { id: "bot-dm-echo-1" } });
316+
await listener.sendMessage("[email protected]", "self-chat reply");
317+
318+
sock.ev.emit("messages.upsert", {
319+
type: "notify",
320+
messages: [
321+
{
322+
key: {
323+
id: "bot-dm-echo-1",
324+
fromMe: true,
325+
remoteJid: "[email protected]",
326+
},
327+
message: { conversation: "self-chat reply" },
328+
messageTimestamp: nowSeconds(),
329+
pushName: "Owner",
330+
},
331+
],
332+
});
333+
await settleInboundWork();
334+
335+
expect(onMessage).not.toHaveBeenCalled();
336+
337+
await listener.close();
338+
});
339+
301340
it("handles append messages by marking them read but skipping auto-reply", async () => {
302341
const { onMessage, listener, sock } = await openInboxMonitor();
303342
const staleTs = Math.floor(Date.now() / 1000) - 300;

0 commit comments

Comments
 (0)