fix(telegram): use compositeChatID in InboundContext.ChatID for forum topics

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
This commit is contained in:
徐闻涵0668001344 2026-06-16 20:43:37 +08:00
parent 083e68b49a
commit 7019143c8e
2 changed files with 4 additions and 3 deletions

View file

@ -1185,7 +1185,7 @@ func (c *TelegramChannel) handleMessages(ctx context.Context, messages []*telego
inboundCtx := bus.InboundContext{ inboundCtx := bus.InboundContext{
Channel: c.Name(), Channel: c.Name(),
ChatID: fmt.Sprintf("%d", chatID), ChatID: compositeChatID,
ChatType: peerKind, ChatType: peerKind,
SenderID: platformID, SenderID: platformID,
MessageID: messageID, MessageID: messageID,

View file

@ -1212,8 +1212,9 @@ func TestHandleMessage_ForumTopic_SetsMetadata(t *testing.T) {
inbound, ok := <-messageBus.InboundChan() inbound, ok := <-messageBus.InboundChan()
require.True(t, ok, "expected inbound message") require.True(t, ok, "expected inbound message")
// ChatID remains the parent chat; TopicID isolates the sub-conversation. // ChatID includes the thread ID for forum topics so outbound
assert.Equal(t, "-1001234567890", inbound.ChatID) // 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, "group", inbound.Context.ChatType)
assert.Equal(t, "42", inbound.Context.TopicID) assert.Equal(t, "42", inbound.Context.TopicID)
} }