Skip to content

Commit 34d862d

Browse files
authored
fix(whatsapp): restore ack emoji identity fallback (#86697)
1 parent f322732 commit 34d862d

8 files changed

Lines changed: 290 additions & 2 deletions

File tree

‎docs/channels/whatsapp.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ Ack reactions are gated by `reactionLevel` — they are suppressed when `reactio
522522
Behavior notes:
523523

524524
- sent immediately after inbound is accepted (pre-reply)
525+
- if `ackReaction` is present without `emoji`, WhatsApp uses the routed agent's identity emoji, falling back to "👀"; omit `ackReaction` or set `emoji: ""` to send no ack reaction
525526
- failures are logged but do not block normal reply delivery
526527
- group mode `mentions` reacts on mention-triggered turns; group activation `always` acts as bypass for this check
527528
- WhatsApp uses `channels.whatsapp.ackReaction` (legacy `messages.ackReaction` is not used here)
@@ -548,6 +549,7 @@ Set `messages.statusReactions.enabled: true` to let WhatsApp replace the ack rea
548549
Behavior notes:
549550

550551
- `channels.whatsapp.ackReaction` still controls whether status reactions are eligible for direct messages and groups.
552+
- The queued status reaction uses the same effective ack emoji as plain ack reactions.
551553
- WhatsApp has one bot reaction slot per message, so lifecycle updates replace the current reaction in place.
552554
- `messages.removeAckAfterReply: true` clears the final status reaction after the configured done/error hold.
553555
- Tool emoji categories include `tool`, `coding`, `web`, `deploy`, `build`, and `concierge`.

‎extensions/whatsapp/src/auto-reply.test-harness.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ vi.mock("openclaw/plugin-sdk/agent-runtime", () => ({
107107
isEmbeddedPiRunStreaming: vi.fn().mockReturnValue(false),
108108
queueEmbeddedPiMessage: vi.fn().mockReturnValue(false),
109109
resolveEmbeddedSessionLane: (key: string) => `session:${key.trim() || "main"}`,
110+
resolveAgentIdentity: (
111+
cfg: { agents?: { list?: Array<{ id: string; identity?: unknown }> } },
112+
agentId: string,
113+
) =>
114+
cfg.agents?.list?.find(
115+
(entry) => entry.id.trim().toLowerCase() === agentId.trim().toLowerCase(),
116+
)?.identity,
110117
resolveIdentityNamePrefix: (cfg: { messages?: { responsePrefix?: string } }, _agentId: string) =>
111118
cfg.messages?.responsePrefix,
112119
resolveMessagePrefix: (cfg: { messages?: { messagePrefix?: string } }) =>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
2+
import { describe, expect, it } from "vitest";
3+
import { resolveWhatsAppAckEmoji } from "./ack-emoji.js";
4+
5+
function createConfig(
6+
ackReaction?: NonNullable<
7+
NonNullable<NonNullable<OpenClawConfig["channels"]>["whatsapp"]>["ackReaction"]
8+
>,
9+
): OpenClawConfig {
10+
const cfg: OpenClawConfig = {
11+
agents: {
12+
list: [{ id: "agent", identity: { emoji: "🔥" } }],
13+
},
14+
channels: {
15+
whatsapp: {},
16+
},
17+
} as OpenClawConfig;
18+
if (ackReaction !== undefined) {
19+
cfg.channels!.whatsapp!.ackReaction = ackReaction;
20+
}
21+
return cfg;
22+
}
23+
24+
describe("resolveWhatsAppAckEmoji", () => {
25+
it("keeps missing ackReaction config disabled", () => {
26+
expect(
27+
resolveWhatsAppAckEmoji({
28+
cfg: createConfig(),
29+
agentId: "agent",
30+
ackConfig: undefined,
31+
}),
32+
).toBe("");
33+
});
34+
35+
it("uses the configured WhatsApp emoji when present", () => {
36+
const cfg = createConfig({ emoji: " 👀 ", direct: true, group: "mentions" });
37+
38+
expect(
39+
resolveWhatsAppAckEmoji({
40+
cfg,
41+
agentId: "agent",
42+
ackConfig: cfg.channels?.whatsapp?.ackReaction,
43+
}),
44+
).toBe("👀");
45+
});
46+
47+
it("keeps an explicit empty emoji disabled", () => {
48+
const cfg = createConfig({ emoji: " ", direct: true, group: "mentions" });
49+
50+
expect(
51+
resolveWhatsAppAckEmoji({
52+
cfg,
53+
agentId: "agent",
54+
ackConfig: cfg.channels?.whatsapp?.ackReaction,
55+
}),
56+
).toBe("");
57+
});
58+
59+
it("falls back to the routed agent identity emoji when the ack object has no emoji", () => {
60+
const cfg = createConfig({ direct: true, group: "mentions" });
61+
62+
expect(
63+
resolveWhatsAppAckEmoji({
64+
cfg,
65+
agentId: "agent",
66+
ackConfig: cfg.channels?.whatsapp?.ackReaction,
67+
}),
68+
).toBe("🔥");
69+
});
70+
71+
it("uses normalized agent ids for the identity fallback", () => {
72+
const cfg: OpenClawConfig = {
73+
agents: {
74+
list: [{ id: "Agent", identity: { emoji: "🔥" } }],
75+
},
76+
channels: {
77+
whatsapp: {
78+
ackReaction: { direct: true, group: "mentions" },
79+
},
80+
},
81+
} as OpenClawConfig;
82+
83+
expect(
84+
resolveWhatsAppAckEmoji({
85+
cfg,
86+
agentId: "agent",
87+
ackConfig: cfg.channels?.whatsapp?.ackReaction,
88+
}),
89+
).toBe("🔥");
90+
});
91+
92+
it("uses the default ack emoji when configured without an emoji or agent identity", () => {
93+
const cfg: OpenClawConfig = {
94+
channels: {
95+
whatsapp: {
96+
ackReaction: { direct: true, group: "mentions" },
97+
},
98+
},
99+
} as OpenClawConfig;
100+
101+
expect(
102+
resolveWhatsAppAckEmoji({
103+
cfg,
104+
agentId: "agent",
105+
ackConfig: cfg.channels?.whatsapp?.ackReaction,
106+
}),
107+
).toBe("👀");
108+
});
109+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { resolveAgentIdentity } from "openclaw/plugin-sdk/agent-runtime";
2+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
3+
4+
const DEFAULT_WHATSAPP_ACK_REACTION = "👀";
5+
6+
type WhatsAppAckReactionConfig = NonNullable<
7+
NonNullable<NonNullable<OpenClawConfig["channels"]>["whatsapp"]>["ackReaction"]
8+
>;
9+
10+
export function resolveWhatsAppAckEmoji(params: {
11+
cfg: OpenClawConfig;
12+
agentId: string;
13+
ackConfig: WhatsAppAckReactionConfig | undefined;
14+
}): string {
15+
if (!params.ackConfig) {
16+
return "";
17+
}
18+
if (params.ackConfig.emoji !== undefined) {
19+
return params.ackConfig.emoji.trim();
20+
}
21+
return resolveAgentIdentityEmoji(params.cfg, params.agentId) ?? DEFAULT_WHATSAPP_ACK_REACTION;
22+
}
23+
24+
function resolveAgentIdentityEmoji(cfg: OpenClawConfig, agentId: string): string | undefined {
25+
const emoji = resolveAgentIdentity(cfg, agentId)?.emoji?.trim();
26+
return emoji || undefined;
27+
}

‎extensions/whatsapp/src/auto-reply/monitor/ack-reaction.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,39 @@ describe("maybeSendAckReaction", () => {
136136
expectAckReactionSent("work", cfg);
137137
});
138138

139+
it("uses the agent identity emoji when WhatsApp ackReaction has no emoji", async () => {
140+
const cfg = {
141+
agents: {
142+
list: [{ id: "agent", identity: { emoji: "🔥" } }],
143+
},
144+
channels: {
145+
whatsapp: {
146+
reactionLevel: "ack",
147+
ackReaction: {
148+
direct: true,
149+
group: "mentions",
150+
},
151+
},
152+
},
153+
} as OpenClawConfig;
154+
155+
const ackReaction = await runAckReaction({ cfg });
156+
157+
expect(ackReaction?.ackReactionValue).toBe("🔥");
158+
await expect(ackReaction?.ackReactionPromise).resolves.toBe(true);
159+
expect(hoisted.sendReactionWhatsApp).toHaveBeenCalledWith(
160+
161+
"msg-1",
162+
"🔥",
163+
{
164+
verbose: false,
165+
fromMe: false,
166+
accountId: "default",
167+
cfg,
168+
},
169+
);
170+
});
171+
139172
it("returns a handle that removes the ack with an empty reaction", async () => {
140173
const cfg = createConfig("ack");
141174
const ackReaction = await runAckReaction({ cfg });

‎extensions/whatsapp/src/auto-reply/monitor/ack-reaction.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { resolveWhatsAppReactionLevel } from "../../reaction-level.js";
1010
import { sendReactionWhatsApp } from "../../send.js";
1111
import { formatError } from "../../session.js";
1212
import type { WebInboundMsg } from "../types.js";
13+
import { resolveWhatsAppAckEmoji } from "./ack-emoji.js";
1314
import { resolveGroupActivationFor } from "./group-activation.js";
1415

1516
export async function maybeSendAckReaction(params: {
@@ -38,7 +39,11 @@ export async function maybeSendAckReaction(params: {
3839
}
3940

4041
const ackConfig = params.cfg.channels?.whatsapp?.ackReaction;
41-
const emoji = (ackConfig?.emoji ?? "").trim();
42+
const emoji = resolveWhatsAppAckEmoji({
43+
cfg: params.cfg,
44+
agentId: params.agentId,
45+
ackConfig,
46+
});
4247
const directEnabled = ackConfig?.direct ?? true;
4348
const groupMode = ackConfig?.group ?? "mentions";
4449
const conversationIdForCheck = params.msg.conversationId ?? params.msg.from;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
import type { WhatsAppSendResult } from "../../inbound/send-result.js";
4+
import type { WebInboundMessage } from "../../inbound/types.js";
5+
import { createWhatsAppStatusReactionController } from "./status-reaction.js";
6+
7+
const hoisted = vi.hoisted(() => ({
8+
sendReactionWhatsApp: vi.fn(async () => undefined),
9+
}));
10+
11+
vi.mock("../../send.js", () => ({
12+
sendReactionWhatsApp: hoisted.sendReactionWhatsApp,
13+
}));
14+
15+
function acceptedSendResult(kind: "media" | "text", id: string): WhatsAppSendResult {
16+
return {
17+
kind,
18+
messageId: id,
19+
keys: [{ id }],
20+
providerAccepted: true,
21+
};
22+
}
23+
24+
function createMessage(overrides: Partial<WebInboundMessage> = {}): WebInboundMessage {
25+
return {
26+
id: "msg-1",
27+
from: "15551234567",
28+
conversationId: "15551234567",
29+
to: "15559876543",
30+
accountId: "default",
31+
body: "hello",
32+
chatType: "direct",
33+
chatId: "[email protected]",
34+
sendComposing: async () => {},
35+
reply: async () => acceptedSendResult("text", "r1"),
36+
sendMedia: async () => acceptedSendResult("media", "m1"),
37+
...overrides,
38+
};
39+
}
40+
41+
describe("createWhatsAppStatusReactionController", () => {
42+
beforeEach(() => {
43+
vi.clearAllMocks();
44+
});
45+
46+
it("uses the agent identity emoji when WhatsApp ackReaction has no emoji", async () => {
47+
const cfg = {
48+
agents: {
49+
list: [{ id: "agent", identity: { emoji: "🔥" } }],
50+
},
51+
messages: {
52+
statusReactions: {
53+
enabled: true,
54+
timing: {
55+
debounceMs: 1_000_000,
56+
stallSoftMs: 1_000_000,
57+
stallHardMs: 1_000_000,
58+
doneHoldMs: 0,
59+
errorHoldMs: 0,
60+
},
61+
},
62+
},
63+
channels: {
64+
whatsapp: {
65+
reactionLevel: "ack",
66+
ackReaction: {
67+
direct: true,
68+
group: "mentions",
69+
},
70+
},
71+
},
72+
} as OpenClawConfig;
73+
74+
const controller = await createWhatsAppStatusReactionController({
75+
cfg,
76+
msg: createMessage(),
77+
agentId: "agent",
78+
sessionKey: "whatsapp:default:15551234567",
79+
conversationId: "15551234567",
80+
verbose: false,
81+
accountId: "default",
82+
});
83+
84+
void controller?.setQueued();
85+
await vi.waitFor(() => {
86+
expect(hoisted.sendReactionWhatsApp).toHaveBeenCalledWith(
87+
88+
"msg-1",
89+
"🔥",
90+
{
91+
verbose: false,
92+
fromMe: false,
93+
accountId: "default",
94+
cfg,
95+
},
96+
);
97+
});
98+
await controller?.clear();
99+
});
100+
});

‎extensions/whatsapp/src/auto-reply/monitor/status-reaction.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getSenderIdentity } from "../../identity.js";
99
import { resolveWhatsAppReactionLevel } from "../../reaction-level.js";
1010
import { sendReactionWhatsApp } from "../../send.js";
1111
import type { WebInboundMsg } from "../types.js";
12+
import { resolveWhatsAppAckEmoji } from "./ack-emoji.js";
1213
import { resolveGroupActivationFor } from "./group-activation.js";
1314

1415
export type { StatusReactionController };
@@ -44,7 +45,11 @@ export async function createWhatsAppStatusReactionController(
4445
}
4546

4647
const ackConfig = params.cfg.channels?.whatsapp?.ackReaction;
47-
const ackEmoji = (ackConfig?.emoji ?? "").trim();
48+
const ackEmoji = resolveWhatsAppAckEmoji({
49+
cfg: params.cfg,
50+
agentId: params.agentId,
51+
ackConfig,
52+
});
4853
if (!ackEmoji) {
4954
return null;
5055
}

0 commit comments

Comments
 (0)