fix(telegram): pass parentPeer for forum topic binding inheritance (#9789)

Fixes #9545 and #9351.

When a message comes from a Telegram forum topic, the peer ID includes
the topic suffix (e.g., `-1001234567890:topic:99`). Users configure
bindings with the base group ID, which previously did not match.

This adds `parentPeer` to `resolveAgentRoute()` calls for forum groups,
enabling binding inheritance from the parent group to all topics.

- Extract `buildTelegramParentPeer()` helper in bot/helpers.ts
- Pass parentPeer in bot-message-context.ts, bot-handlers.ts,
  bot-native-commands.ts, and bot.ts (reaction handler)
- Add tests for forum topic routing and topic precedence
This commit is contained in:
Christian Klotz
2026-02-05 18:24:49 +00:00
parent 547374220c
commit ddedb56c01
7 changed files with 157 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ import {
buildSenderName,
buildTelegramGroupFrom,
buildTelegramGroupPeerId,
buildTelegramParentPeer,
buildTypingThreadParams,
expandTextLinks,
normalizeForwardedContext,
@@ -161,6 +162,7 @@ export const buildTelegramMessageContext = async ({
const replyThreadId = threadSpec.id;
const { groupConfig, topicConfig } = resolveTelegramGroupConfig(chatId, resolvedThreadId);
const peerId = isGroup ? buildTelegramGroupPeerId(chatId, resolvedThreadId) : String(chatId);
const parentPeer = buildTelegramParentPeer({ isGroup, resolvedThreadId, chatId });
const route = resolveAgentRoute({
cfg,
channel: "telegram",
@@ -169,6 +171,7 @@ export const buildTelegramMessageContext = async ({
kind: isGroup ? "group" : "dm",
id: peerId,
},
parentPeer,
});
const baseSessionKey = route.sessionKey;
// DMs: use raw messageThreadId for thread sessions (not forum topic ids)