fix: honor telegram account topic mention config

This commit is contained in:
Tak Hoffman 2026-04-03 10:18:59 -05:00
parent c71df2f4b0
commit e3fea41b59
No known key found for this signature in database
2 changed files with 51 additions and 3 deletions

View File

@ -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;

View File

@ -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", () => {