mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:51:24 +00:00
fix(outbound): return error instead of silently redirecting to allowList[0] (#13578)
This commit is contained in:
43
src/channels/plugins/outbound/whatsapp.test.ts
Normal file
43
src/channels/plugins/outbound/whatsapp.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { whatsappOutbound } from "./whatsapp.js";
|
||||
|
||||
describe("whatsappOutbound.resolveTarget", () => {
|
||||
it("returns error when no target is provided even with allowFrom", () => {
|
||||
const result = whatsappOutbound.resolveTarget?.({
|
||||
to: undefined,
|
||||
allowFrom: ["+15551234567"],
|
||||
mode: "implicit",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: expect.any(Error),
|
||||
});
|
||||
});
|
||||
|
||||
it("returns error when implicit target is not in allowFrom", () => {
|
||||
const result = whatsappOutbound.resolveTarget?.({
|
||||
to: "+15550000000",
|
||||
allowFrom: ["+15551234567"],
|
||||
mode: "implicit",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: expect.any(Error),
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps group JID targets even when allowFrom does not contain them", () => {
|
||||
const result = whatsappOutbound.resolveTarget?.({
|
||||
to: "120363401234567890@g.us",
|
||||
allowFrom: ["+15551234567"],
|
||||
mode: "implicit",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: true,
|
||||
to: "120363401234567890@g.us",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -23,15 +23,9 @@ export const whatsappOutbound: ChannelOutboundAdapter = {
|
||||
if (trimmed) {
|
||||
const normalizedTo = normalizeWhatsAppTarget(trimmed);
|
||||
if (!normalizedTo) {
|
||||
if ((mode === "implicit" || mode === "heartbeat") && allowList.length > 0) {
|
||||
return { ok: true, to: allowList[0] };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: missingTargetError(
|
||||
"WhatsApp",
|
||||
"<E.164|group JID> or channels.whatsapp.allowFrom[0]",
|
||||
),
|
||||
error: missingTargetError("WhatsApp", "<E.164|group JID>"),
|
||||
};
|
||||
}
|
||||
if (isWhatsAppGroupJid(normalizedTo)) {
|
||||
@@ -44,17 +38,17 @@ export const whatsappOutbound: ChannelOutboundAdapter = {
|
||||
if (allowList.includes(normalizedTo)) {
|
||||
return { ok: true, to: normalizedTo };
|
||||
}
|
||||
return { ok: true, to: allowList[0] };
|
||||
return {
|
||||
ok: false,
|
||||
error: missingTargetError("WhatsApp", "<E.164|group JID>"),
|
||||
};
|
||||
}
|
||||
return { ok: true, to: normalizedTo };
|
||||
}
|
||||
|
||||
if (allowList.length > 0) {
|
||||
return { ok: true, to: allowList[0] };
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: missingTargetError("WhatsApp", "<E.164|group JID> or channels.whatsapp.allowFrom[0]"),
|
||||
error: missingTargetError("WhatsApp", "<E.164|group JID>"),
|
||||
};
|
||||
},
|
||||
sendText: async ({ to, text, accountId, deps, gifPlayback }) => {
|
||||
|
||||
Reference in New Issue
Block a user