mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-02 04:41:11 +00:00
fix(zalouser): accept prefixed group ids for member lookup
This commit is contained in:
52
extensions/zalouser/src/channel.directory.test.ts
Normal file
52
extensions/zalouser/src/channel.directory.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const listZaloGroupMembersMock = vi.hoisted(() => vi.fn(async () => []));
|
||||
|
||||
vi.mock("./zalo-js.js", async (importOriginal) => {
|
||||
const actual = (await importOriginal()) as Record<string, unknown>;
|
||||
return {
|
||||
...actual,
|
||||
listZaloGroupMembers: listZaloGroupMembersMock,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./accounts.js", async (importOriginal) => {
|
||||
const actual = (await importOriginal()) as Record<string, unknown>;
|
||||
return {
|
||||
...actual,
|
||||
resolveZalouserAccountSync: () => ({
|
||||
accountId: "default",
|
||||
profile: "default",
|
||||
name: "test",
|
||||
enabled: true,
|
||||
authenticated: true,
|
||||
config: {},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
import { zalouserPlugin } from "./channel.js";
|
||||
|
||||
describe("zalouser directory group members", () => {
|
||||
it("accepts prefixed group ids from directory groups list output", async () => {
|
||||
await zalouserPlugin.directory!.listGroupMembers!({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
groupId: "group:1471383327500481391",
|
||||
runtime: undefined,
|
||||
});
|
||||
|
||||
expect(listZaloGroupMembersMock).toHaveBeenCalledWith("default", "1471383327500481391");
|
||||
});
|
||||
|
||||
it("keeps backward compatibility for raw group ids", async () => {
|
||||
await zalouserPlugin.directory!.listGroupMembers!({
|
||||
cfg: {},
|
||||
accountId: "default",
|
||||
groupId: "1471383327500481391",
|
||||
runtime: undefined,
|
||||
});
|
||||
|
||||
expect(listZaloGroupMembersMock).toHaveBeenCalledWith("default", "1471383327500481391");
|
||||
});
|
||||
});
|
||||
@@ -117,6 +117,25 @@ function parseZalouserOutboundTarget(raw: string): {
|
||||
return { threadId: normalized, isGroup: false };
|
||||
}
|
||||
|
||||
function parseZalouserDirectoryGroupId(raw: string): string {
|
||||
const normalized = normalizePrefixedTarget(raw);
|
||||
if (!normalized) {
|
||||
throw new Error("Zalouser group target is required");
|
||||
}
|
||||
const lowered = normalized.toLowerCase();
|
||||
if (lowered.startsWith("group:")) {
|
||||
const groupId = normalized.slice("group:".length).trim();
|
||||
if (!groupId) {
|
||||
throw new Error("Zalouser group target is missing group id");
|
||||
}
|
||||
return groupId;
|
||||
}
|
||||
if (lowered.startsWith("user:")) {
|
||||
throw new Error("Zalouser group members lookup requires a group target (group:<id>)");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function resolveZalouserQrProfile(accountId?: string | null): string {
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
if (!normalized || normalized === DEFAULT_ACCOUNT_ID) {
|
||||
@@ -501,7 +520,8 @@ export const zalouserPlugin: ChannelPlugin<ResolvedZalouserAccount> = {
|
||||
},
|
||||
listGroupMembers: async ({ cfg, accountId, groupId, limit }) => {
|
||||
const account = resolveZalouserAccountSync({ cfg: cfg, accountId });
|
||||
const members = await listZaloGroupMembers(account.profile, groupId);
|
||||
const normalizedGroupId = parseZalouserDirectoryGroupId(groupId);
|
||||
const members = await listZaloGroupMembers(account.profile, normalizedGroupId);
|
||||
const rows = members.map((member) =>
|
||||
mapUser({
|
||||
id: member.userId,
|
||||
|
||||
Reference in New Issue
Block a user