docs: absorb documentation PR sweep

This commit is contained in:
Peter Steinberger
2026-05-23 10:23:22 +01:00
parent 6b04170167
commit 2c536a8626
39 changed files with 455 additions and 71 deletions

View File

@@ -55,6 +55,19 @@ export function resolveTelegramScopedGroupConfig(
chatId: string | number,
messageThreadId?: number,
) {
const resolveTopicConfig = <T extends object>(
scopedConfig: { topics?: Record<string, T | undefined> } | undefined,
): T | undefined => {
if (!scopedConfig || messageThreadId == null) {
return undefined;
}
const defaultConfig = scopedConfig.topics?.["*"];
const exactConfig = scopedConfig.topics?.[String(messageThreadId)];
if (defaultConfig && exactConfig) {
return { ...defaultConfig, ...exactConfig };
}
return exactConfig ?? defaultConfig;
};
const groups = telegramCfg.groups;
const direct = telegramCfg.direct;
const chatIdStr = String(chatId);
@@ -62,18 +75,12 @@ export function resolveTelegramScopedGroupConfig(
if (isDm) {
const groupConfig = direct?.[chatIdStr] ?? direct?.["*"];
const topicConfig =
groupConfig && messageThreadId != null
? groupConfig.topics?.[String(messageThreadId)]
: undefined;
const topicConfig = resolveTopicConfig(groupConfig);
return { groupConfig, topicConfig };
}
const groupConfig = groups?.[chatIdStr] ?? groups?.["*"];
const topicConfig =
groupConfig && messageThreadId != null
? groupConfig.topics?.[String(messageThreadId)]
: undefined;
const topicConfig = resolveTopicConfig(groupConfig);
return { groupConfig, topicConfig };
}

View File

@@ -2622,6 +2622,72 @@ describe("createTelegramBot", () => {
expect(topicConfig).toEqual({});
});
it("uses topics.* as the default config for unmatched forum topics", () => {
const { groupConfig, topicConfig } = resolveTelegramScopedGroupConfig(
{
groupPolicy: "allowlist",
groups: {
"-1001234567890": {
allowFrom: ["999999999"],
topics: {
"*": { allowFrom: ["123456789"], agentId: "zu" },
},
},
},
},
-1001234567890,
77,
);
const group = groupConfig as TelegramGroupConfig | undefined;
expect(group?.allowFrom).toEqual(["999999999"]);
expect(topicConfig).toEqual({ allowFrom: ["123456789"], agentId: "zu" });
});
it("prefers exact topic config over topics.* fallback", () => {
const { topicConfig } = resolveTelegramScopedGroupConfig(
{
groupPolicy: "allowlist",
groups: {
"-1001234567890": {
topics: {
"*": { allowFrom: ["123456789"], agentId: "zu" },
"77": { allowFrom: ["555555555"], agentId: "main" },
},
},
},
},
-1001234567890,
77,
);
expect(topicConfig).toEqual({ allowFrom: ["555555555"], agentId: "main" });
});
it("inherits topics.* fields that exact topic config does not override", () => {
const { topicConfig } = resolveTelegramScopedGroupConfig(
{
groupPolicy: "allowlist",
groups: {
"-1001234567890": {
topics: {
"*": { allowFrom: ["123456789"], requireMention: false },
"77": { agentId: "main" },
},
},
},
},
-1001234567890,
77,
);
expect(topicConfig).toEqual({
allowFrom: ["123456789"],
requireMention: false,
agentId: "main",
});
});
it.each([
{
label: "parent binding",

View File

@@ -33,6 +33,36 @@ describe("resolveTelegramGroupRequireMention", () => {
}),
).toBe(false);
});
it("lets exact topic configs inherit wildcard topic requireMention", () => {
const cfg = {
channels: {
telegram: {
botToken: "telegram-test",
groups: {
"-1001": {
requireMention: true,
topics: {
"*": {
requireMention: false,
},
"77": {
agentId: "main",
},
},
},
},
},
},
} as OpenClawConfig;
expect(
resolveTelegramGroupRequireMention({
cfg,
groupId: "-1001:topic:77",
}),
).toBe(false);
});
});
describe("resolveTelegramGroupToolPolicy", () => {

View File

@@ -40,9 +40,14 @@ function resolveTelegramRequireMention(params: {
cfg.channels?.telegram?.groups;
const groupConfig = scopedGroups?.[chatId];
const groupDefault = scopedGroups?.["*"];
const topicConfig = topicId && groupConfig?.topics ? groupConfig.topics[topicId] : undefined;
const topicConfig =
topicId && groupConfig?.topics
? { ...groupConfig.topics["*"], ...groupConfig.topics[topicId] }
: undefined;
const defaultTopicConfig =
topicId && groupDefault?.topics ? groupDefault.topics[topicId] : undefined;
topicId && groupDefault?.topics
? { ...groupDefault.topics["*"], ...groupDefault.topics[topicId] }
: undefined;
if (typeof topicConfig?.requireMention === "boolean") {
return topicConfig.requireMention;
}