From e3fea41b595b430aadad46be7352b9683f8412df Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Fri, 3 Apr 2026 10:18:59 -0500 Subject: [PATCH] fix: honor telegram account topic mention config --- extensions/telegram/src/group-policy.ts | 11 +++++-- extensions/telegram/src/targets.test.ts | 43 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/extensions/telegram/src/group-policy.ts b/extensions/telegram/src/group-policy.ts index 29614436ccc..dd7e63e9524 100644 --- a/extensions/telegram/src/group-policy.ts +++ b/extensions/telegram/src/group-policy.ts @@ -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; diff --git a/extensions/telegram/src/targets.test.ts b/extensions/telegram/src/targets.test.ts index 8888d23e91d..d310937c3c9 100644 --- a/extensions/telegram/src/targets.test.ts +++ b/extensions/telegram/src/targets.test.ts @@ -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", () => {