Skip to content

Commit 5060d03

Browse files
fix(whatsapp): preserve source direction for automatic reactions
1 parent 2f06ed3 commit 5060d03

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function createMessage(overrides: TestMsgOverrides = {}): AdmittedWebInboundMess
2525
platform: {
2626
chatJid: "[email protected]",
2727
recipientJid: "15559876543",
28+
fromMe: false,
2829
},
2930
admission: {
3031
accountId: "default",
@@ -182,6 +183,47 @@ describe("maybeSendAckReaction", () => {
182183
);
183184
});
184185

186+
it("preserves self-authored direction for ack send and removal", async () => {
187+
const cfg = createConfig("ack");
188+
const ackReaction = await runAckReaction({
189+
cfg,
190+
msg: createMessage({
191+
platform: {
192+
chatJid: "[email protected]",
193+
recipientJid: "15559876543",
194+
fromMe: true,
195+
},
196+
}),
197+
});
198+
199+
await expect(ackReaction?.ackReactionPromise).resolves.toBe(true);
200+
expect(hoisted.sendReactionWhatsApp).toHaveBeenCalledWith(
201+
202+
"msg-1",
203+
"👀",
204+
{
205+
verbose: false,
206+
fromMe: true,
207+
accountId: "default",
208+
cfg,
209+
},
210+
);
211+
212+
await ackReaction?.remove();
213+
214+
expect(hoisted.sendReactionWhatsApp).toHaveBeenLastCalledWith(
215+
216+
"msg-1",
217+
"",
218+
{
219+
verbose: false,
220+
fromMe: true,
221+
accountId: "default",
222+
cfg,
223+
},
224+
);
225+
});
226+
185227
it("uses the sender LID as the group reaction participant when no sender JID is available", async () => {
186228
const cfg = createConfig("ack");
187229
const ackReaction = await runAckReaction({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function resolveWhatsAppReactionEligibility(params: {
7373
emoji,
7474
reactionOptions: {
7575
verbose: params.verbose,
76-
fromMe: false,
76+
fromMe: params.msg.platform.fromMe === true,
7777
...(participant ? { participant } : {}),
7878
accountId,
7979
cfg: params.cfg,

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function createMessage(overrides: TestMsgOverrides = {}): AdmittedWebInboundMess
2525
platform: {
2626
chatJid: "[email protected]",
2727
recipientJid: "15559876543",
28+
fromMe: false,
2829
},
2930
admission: {
3031
accountId: "default",
@@ -162,6 +163,66 @@ describe("createWhatsAppStatusReactionController", () => {
162163
await controller?.clear();
163164
});
164165

166+
it("preserves self-authored direction for status set and clear", async () => {
167+
const cfg = {
168+
messages: {
169+
ackReaction: "👀",
170+
ackReactionScope: "all",
171+
statusReactions: {
172+
enabled: true,
173+
},
174+
},
175+
channels: {
176+
whatsapp: {
177+
reactionLevel: "ack",
178+
},
179+
},
180+
} as OpenClawConfig;
181+
182+
const controller = await createWhatsAppStatusReactionController({
183+
cfg,
184+
msg: createMessage({
185+
platform: {
186+
chatJid: "[email protected]",
187+
recipientJid: "15559876543",
188+
fromMe: true,
189+
},
190+
}),
191+
agentId: "agent",
192+
sessionKey: "whatsapp:default:15551234567",
193+
verbose: false,
194+
});
195+
196+
void controller?.setQueued();
197+
await vi.waitFor(() => {
198+
expect(hoisted.sendReactionWhatsApp).toHaveBeenCalledWith(
199+
200+
"msg-1",
201+
"👀",
202+
{
203+
verbose: false,
204+
fromMe: true,
205+
accountId: "default",
206+
cfg,
207+
},
208+
);
209+
});
210+
211+
await controller?.clear();
212+
213+
expect(hoisted.sendReactionWhatsApp).toHaveBeenLastCalledWith(
214+
215+
"msg-1",
216+
"",
217+
{
218+
verbose: false,
219+
fromMe: true,
220+
accountId: "default",
221+
cfg,
222+
},
223+
);
224+
});
225+
165226
it("uses the active account reactionLevel override from admission", async () => {
166227
const cfg = {
167228
messages: {

0 commit comments

Comments
 (0)