mirror of https://github.com/openclaw/openclaw.git
fix: honor telegram account topic mention config
This commit is contained in:
parent
c71df2f4b0
commit
e3fea41b59
|
|
@ -29,13 +29,17 @@ function resolveTelegramRequireMention(params: {
|
|||
cfg: ChannelGroupContext["cfg"];
|
||||
chatId?: string;
|
||||
topicId?: string;
|
||||
accountId?: string | null;
|
||||
}): boolean | undefined {
|
||||
const { cfg, chatId, topicId } = params;
|
||||
const { cfg, chatId, topicId, accountId } = params;
|
||||
if (!chatId) {
|
||||
return undefined;
|
||||
}
|
||||
const groupConfig = cfg.channels?.telegram?.groups?.[chatId];
|
||||
const groupDefault = cfg.channels?.telegram?.groups?.["*"];
|
||||
const scopedGroups =
|
||||
(accountId ? cfg.channels?.telegram?.accounts?.[accountId]?.groups : undefined) ??
|
||||
cfg.channels?.telegram?.groups;
|
||||
const groupConfig = scopedGroups?.[chatId];
|
||||
const groupDefault = scopedGroups?.["*"];
|
||||
const topicConfig = topicId && groupConfig?.topics ? groupConfig.topics[topicId] : undefined;
|
||||
const defaultTopicConfig =
|
||||
topicId && groupDefault?.topics ? groupDefault.topics[topicId] : undefined;
|
||||
|
|
@ -62,6 +66,7 @@ export function resolveTelegramGroupRequireMention(
|
|||
cfg: params.cfg,
|
||||
chatId,
|
||||
topicId,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
if (typeof requireMention === "boolean") {
|
||||
return requireMention;
|
||||
|
|
|
|||
|
|
@ -170,6 +170,49 @@ describe("telegram group policy", () => {
|
|||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("honors account-scoped topic requireMention overrides", () => {
|
||||
const telegramCfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
botToken: "telegram-test",
|
||||
groups: {
|
||||
"-1001": {
|
||||
requireMention: true,
|
||||
topics: {
|
||||
"77": {
|
||||
requireMention: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
accounts: {
|
||||
work: {
|
||||
botToken: "telegram-work",
|
||||
groups: {
|
||||
"-1001": {
|
||||
topics: {
|
||||
"77": {
|
||||
requireMention: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
} as any;
|
||||
|
||||
expect(
|
||||
resolveTelegramGroupRequireMention({
|
||||
cfg: telegramCfg,
|
||||
accountId: "work",
|
||||
groupId: "-1001:topic:77",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("telegram allow-from helpers", () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue