From 7019143c8ede3d390b77c54c54a16d97e15e37c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=97=BB=E6=B6=B50668001344?= Date: Tue, 16 Jun 2026 20:43:37 +0800 Subject: [PATCH] fix(telegram): use compositeChatID in InboundContext.ChatID for forum topics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When handling inbound Telegram messages from forum topics, InboundContext.ChatID was set to the plain chat ID (without thread). This caused outbound messages to lose the thread routing, sending replies to the General topic instead of the specific forum topic — even though typing indicators correctly targeted the right thread because StartTyping received the compositeChatID. The fix sets InboundContext.ChatID to compositeChatID (chatID/threadID format) for forum messages, matching the format already used for session routing and typing indicators. TopicID is still preserved as a redundant fallback for any path that strips the composite format. Closes #3110 --- pkg/channels/telegram/telegram.go | 2 +- pkg/channels/telegram/telegram_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/channels/telegram/telegram.go b/pkg/channels/telegram/telegram.go index bb04261a..d7265fb3 100644 --- a/pkg/channels/telegram/telegram.go +++ b/pkg/channels/telegram/telegram.go @@ -1185,7 +1185,7 @@ func (c *TelegramChannel) handleMessages(ctx context.Context, messages []*telego inboundCtx := bus.InboundContext{ Channel: c.Name(), - ChatID: fmt.Sprintf("%d", chatID), + ChatID: compositeChatID, ChatType: peerKind, SenderID: platformID, MessageID: messageID, diff --git a/pkg/channels/telegram/telegram_test.go b/pkg/channels/telegram/telegram_test.go index 6d243e18..ddecad28 100644 --- a/pkg/channels/telegram/telegram_test.go +++ b/pkg/channels/telegram/telegram_test.go @@ -1212,8 +1212,9 @@ func TestHandleMessage_ForumTopic_SetsMetadata(t *testing.T) { inbound, ok := <-messageBus.InboundChan() require.True(t, ok, "expected inbound message") - // ChatID remains the parent chat; TopicID isolates the sub-conversation. - assert.Equal(t, "-1001234567890", inbound.ChatID) + // ChatID includes the thread ID for forum topics so outbound + // delivery resolves the correct topic without relying solely on TopicID fallback. + assert.Equal(t, "-1001234567890/42", inbound.ChatID) assert.Equal(t, "group", inbound.Context.ChatType) assert.Equal(t, "42", inbound.Context.TopicID) }