Revert "fix(whatsapp): handle group mentions and caller allowlists"

This reverts commit 9664e85599.
This commit is contained in:
xmanrui 2026-08-26 18:01:08 +08:00
parent a9bb0ed3ba
commit 25d0b2fb0b
13 changed files with 215 additions and 564 deletions

View file

@ -681,12 +681,9 @@ var EN = Object.freeze({
"\u53EA\u54CD\u5E94\u5DF2\u7ED1\u5B9A WhatsApp \u8D26\u53F7\u7684\u81EA\u804A\u6D88\u606F\u3002": "Only respond to self-chat messages from the linked WhatsApp account.",
"\u54CD\u5E94\u81EA\u804A\u548C\u767D\u540D\u5355\u8054\u7CFB\u4EBA\u7684\u79C1\u804A\uFF0C\u5FFD\u7565\u7FA4\u804A\u3002": "Respond to self-chat and allowlisted direct messages; ignore group messages.",
"\u54CD\u5E94\u6240\u6709\u79C1\u804A\u3001\u5DF2\u7ED1\u5B9A\u8D26\u53F7\u81EA\u5DF1\u53D1\u51FA\u7684\u7FA4\u804A\u6D88\u606F\uFF0C\u4EE5\u53CA\u5176\u4ED6\u7FA4\u6210\u5458\u7684\u63D0\u53CA\u6216\u56DE\u590D\u3002": "Respond to all direct messages, group messages sent by the linked account, and mentions or replies from other group members.",
"\u54CD\u5E94\u6240\u6709\u79C1\u804A\u3001\u5DF2\u7ED1\u5B9A\u8D26\u53F7\u81EA\u5DF1\u53D1\u51FA\u7684\u7FA4\u804A\u6D88\u606F\uFF0C\u4EE5\u53CA\u5141\u8BB8\u6210\u5458\u7684\u63D0\u53CA\u6216\u56DE\u590D\uFF1B\u7FA4\u804A\u53F7\u7801\u5217\u8868\u7559\u7A7A\u65F6\u5141\u8BB8\u6240\u6709\u7FA4\u6210\u5458\u3002": "Respond to all direct messages, group messages sent by the linked account, and mentions or replies from allowed members; leaving the group number list empty allows every group member.",
"\u5141\u8BB8\u79C1\u804A\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801": "WhatsApp phone numbers allowed to send direct messages",
"\u5141\u8BB8\u5728\u7FA4\u804A\u4E2D\u547C\u53EB\u673A\u5668\u4EBA\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801": "WhatsApp phone numbers allowed to call the bot in group chats",
"\u6BCF\u884C\u4E00\u4E2A\u542B\u56FD\u5BB6\u6216\u5730\u533A\u4EE3\u7801\u7684\u53F7\u7801": "One number with country or region code per line",
"\u53EF\u4EE5\u5305\u542B\u5F00\u5934\u7684 +\uFF0C\u4FDD\u5B58\u65F6\u4F1A\u81EA\u52A8\u79FB\u9664\u3002": "A leading + is allowed and removed when saved.",
"\u7559\u7A7A\u8868\u793A\u6240\u6709\u7FA4\u6210\u5458\u90FD\u53EF\u4EE5\u901A\u8FC7\u63D0\u53CA\u6216\u56DE\u590D\u547C\u53EB\u673A\u5668\u4EBA\u3002": "Leave empty to let every group member call the bot by mentioning it or replying to it.",
"\u4EC5\u6307\u5B9A\u8054\u7CFB\u4EBA\u6A21\u5F0F\u4F7F\u7528\u767D\u540D\u5355\uFF0C\u5207\u6362\u6A21\u5F0F\u65F6\u4F1A\u4FDD\u7559\u3002": "Only Selected contacts uses the allowlist; it is retained when modes change.",
"\u767D\u540D\u5355\u4E3A\u7A7A\uFF1B\u4FDD\u5B58\u540E\u5C06\u53EA\u63A5\u53D7\u81EA\u804A\u6D88\u606F\u3002": "The allowlist is empty; only self-chat messages will be accepted after saving.",
"\u7535\u8BDD\u53F7\u7801\u5FC5\u987B\u5305\u542B\u56FD\u5BB6\u6216\u5730\u533A\u4EE3\u7801\uFF0C\u6BCF\u884C\u4E00\u4E2A\u3002": "Each phone number must include a country or region code on its own line.",
@ -9409,8 +9406,7 @@ function normalizeBot6(value) {
accessMode: ["self-only", "private-allowlist", "open"].includes(
value.accessPolicy?.accessMode
) ? value.accessPolicy.accessMode : "self-only",
allowedNumbers: Array.isArray(value.accessPolicy?.allowedNumbers) ? [...new Set(value.accessPolicy.allowedNumbers.filter((entry) => typeof entry === "string" && /^[1-9]\d{4,14}$/.test(entry)))] : [],
groupAllowedNumbers: Array.isArray(value.accessPolicy?.groupAllowedNumbers) ? [...new Set(value.accessPolicy.groupAllowedNumbers.filter((entry) => typeof entry === "string" && /^[1-9]\d{4,14}$/.test(entry)))] : []
allowedNumbers: Array.isArray(value.accessPolicy?.allowedNumbers) ? [...new Set(value.accessPolicy.allowedNumbers.filter((entry) => typeof entry === "string" && /^[1-9]\d{4,14}$/.test(entry)))] : []
},
bot: {
name: text5(value.bot?.name, "WhatsApp\u673A\u5668\u4EBA", 100),
@ -9509,8 +9505,7 @@ function accessPolicyFor(account) {
) ? account.accessPolicy.accessMode : "self-only";
return {
accessMode,
allowedNumbers: Array.isArray(account?.accessPolicy?.allowedNumbers) ? account.accessPolicy.allowedNumbers : [],
groupAllowedNumbers: Array.isArray(account?.accessPolicy?.groupAllowedNumbers) ? account.accessPolicy.groupAllowedNumbers : []
allowedNumbers: Array.isArray(account?.accessPolicy?.allowedNumbers) ? account.accessPolicy.allowedNumbers : []
};
}
function allowedNumbersFromText(value) {
@ -9524,36 +9519,27 @@ function allowedNumbersFromText(value) {
function WhatsappAccessSettings({ account, busy = false, onSave }) {
const policy = accessPolicyFor(account);
const sourceNumbers = policy.allowedNumbers.join("\n");
const sourceGroupNumbers = policy.groupAllowedNumbers.join("\n");
const helpId = React19.useId();
const [accessMode, setAccessMode] = React19.useState(policy.accessMode);
const [allowedNumbers, setAllowedNumbers] = React19.useState(sourceNumbers);
const [groupAllowedNumbers, setGroupAllowedNumbers] = React19.useState(sourceGroupNumbers);
const [error, setError] = React19.useState(null);
React19.useEffect(() => {
setAccessMode(policy.accessMode);
setAllowedNumbers(sourceNumbers);
setGroupAllowedNumbers(sourceGroupNumbers);
setError(null);
}, [policy.accessMode, sourceNumbers, sourceGroupNumbers]);
}, [policy.accessMode, sourceNumbers]);
const save = async (event) => {
event.preventDefault();
setError(null);
try {
const normalized = allowedNumbersFromText(allowedNumbers);
const normalizedGroup = allowedNumbersFromText(groupAllowedNumbers);
if (typeof onSave !== "function") throw new Error("WhatsApp \u8BBF\u95EE\u8BBE\u7F6E\u6682\u4E0D\u53EF\u7528\u3002");
await onSave({
accessMode,
allowedNumbers: normalized,
groupAllowedNumbers: normalizedGroup
});
await onSave({ accessMode, allowedNumbers: normalized });
} catch (caught) {
setError(caught?.message ?? "WhatsApp \u8BBF\u95EE\u8BBE\u7F6E\u4FDD\u5B58\u5931\u8D25\u3002");
}
};
const allowlistEnabled = accessMode === "private-allowlist";
const groupAllowlistEnabled = accessMode === "open";
const labels = {
"self-only": "\u4EC5\u81EA\u5DF1\u6A21\u5F0F",
"private-allowlist": "\u6307\u5B9A\u8054\u7CFB\u4EBA\u6A21\u5F0F",
@ -9602,7 +9588,7 @@ function WhatsappAccessSettings({ account, busy = false, onSave }) {
"span",
{ className: "dwa-accessTooltipItem" },
h2("strong", null, "\u5F00\u653E\u54CD\u5E94\u6A21\u5F0F"),
h2("span", null, "\u54CD\u5E94\u6240\u6709\u79C1\u804A\u3001\u5DF2\u7ED1\u5B9A\u8D26\u53F7\u81EA\u5DF1\u53D1\u51FA\u7684\u7FA4\u804A\u6D88\u606F\uFF0C\u4EE5\u53CA\u5141\u8BB8\u6210\u5458\u7684\u63D0\u53CA\u6216\u56DE\u590D\uFF1B\u7FA4\u804A\u53F7\u7801\u5217\u8868\u7559\u7A7A\u65F6\u5141\u8BB8\u6240\u6709\u7FA4\u6210\u5458\u3002")
h2("span", null, "\u54CD\u5E94\u6240\u6709\u79C1\u804A\u3001\u5DF2\u7ED1\u5B9A\u8D26\u53F7\u81EA\u5DF1\u53D1\u51FA\u7684\u7FA4\u804A\u6D88\u606F\uFF0C\u4EE5\u53CA\u5176\u4ED6\u7FA4\u6210\u5458\u7684\u63D0\u53CA\u6216\u56DE\u590D\u3002")
)
)
)
@ -9628,23 +9614,22 @@ function WhatsappAccessSettings({ account, busy = false, onSave }) {
h2("option", { value: "open" }, "\u5F00\u653E\u54CD\u5E94\u6A21\u5F0F")
)
),
allowlistEnabled || groupAllowlistEnabled ? h2(
allowlistEnabled ? h2(
"label",
{ className: "dwa-accessField" },
h2("span", null, allowlistEnabled ? "\u5141\u8BB8\u79C1\u804A\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801" : "\u5141\u8BB8\u5728\u7FA4\u804A\u4E2D\u547C\u53EB\u673A\u5668\u4EBA\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801"),
h2("span", null, "\u5141\u8BB8\u79C1\u804A\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801"),
h2("textarea", {
value: allowlistEnabled ? allowedNumbers : groupAllowedNumbers,
value: allowedNumbers,
disabled: busy,
rows: 3,
placeholder: "\u6BCF\u884C\u4E00\u4E2A\u542B\u56FD\u5BB6\u6216\u5730\u533A\u4EE3\u7801\u7684\u53F7\u7801",
"aria-label": allowlistEnabled ? "\u5141\u8BB8\u79C1\u804A\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801" : "\u5141\u8BB8\u5728\u7FA4\u804A\u4E2D\u547C\u53EB\u673A\u5668\u4EBA\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801",
"aria-label": "\u5141\u8BB8\u79C1\u804A\u7684 WhatsApp \u7535\u8BDD\u53F7\u7801",
onChange: (event) => {
if (allowlistEnabled) setAllowedNumbers(event.target.value);
else setGroupAllowedNumbers(event.target.value);
setAllowedNumbers(event.target.value);
setError(null);
}
}),
h2("small", null, allowlistEnabled ? "\u53EF\u4EE5\u5305\u542B\u5F00\u5934\u7684 +\uFF0C\u4FDD\u5B58\u65F6\u4F1A\u81EA\u52A8\u79FB\u9664\u3002" : "\u7559\u7A7A\u8868\u793A\u6240\u6709\u7FA4\u6210\u5458\u90FD\u53EF\u4EE5\u901A\u8FC7\u63D0\u53CA\u6216\u56DE\u590D\u547C\u53EB\u673A\u5668\u4EBA\u3002")
h2("small", null, "\u53EF\u4EE5\u5305\u542B\u5F00\u5934\u7684 +\uFF0C\u4FDD\u5B58\u65F6\u4F1A\u81EA\u52A8\u79FB\u9664\u3002")
) : null,
allowlistEnabled && allowedNumbers.trim() === "" ? h2(
"p",