From 9740b547ea1ba6d2f7aa82401e0b3100dfb84b81 Mon Sep 17 00:00:00 2001 From: Hakancan Date: Sun, 8 Mar 2026 23:17:23 +0000 Subject: [PATCH] fix(qq): use PostGroupMessage for group chat responses The QQ channel was incorrectly using PostC2CMessage (private message API) for all messages, including group messages. This caused error code 11255 when replying to @mentions in QQ groups. Changes: - Add Peer field to OutboundMessage struct - Check msg.Peer.Kind in QQ Send method - Use PostGroupMessage for group messages - Use PostC2CMessage for direct/private messages - Pass Peer info when publishing outbound messages Fixes #1221 --- pkg/agent/loop.go | 1 + pkg/bus/types.go | 1 + pkg/channels/qq/qq.go | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 966668227..d471c8ec6 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -343,6 +343,7 @@ func (al *AgentLoop) Run(ctx context.Context) error { Channel: msg.Channel, ChatID: msg.ChatID, Content: response, + Peer: msg.Peer, }) logger.InfoCF("agent", "Published outbound response", map[string]any{ diff --git a/pkg/bus/types.go b/pkg/bus/types.go index 7ad8f0417..cf2f9ba74 100644 --- a/pkg/bus/types.go +++ b/pkg/bus/types.go @@ -33,6 +33,7 @@ type OutboundMessage struct { Channel string `json:"channel"` ChatID string `json:"chat_id"` Content string `json:"content"` + Peer Peer `json:"peer"` // routing peer (direct, group, etc.) } // MediaPart describes a single media attachment to send. diff --git a/pkg/channels/qq/qq.go b/pkg/channels/qq/qq.go index 112964143..b08bc2735 100644 --- a/pkg/channels/qq/qq.go +++ b/pkg/channels/qq/qq.go @@ -126,13 +126,25 @@ func (c *QQChannel) Send(ctx context.Context, msg bus.OutboundMessage) error { Content: msg.Content, } - // send C2C message - _, err := c.api.PostC2CMessage(ctx, msg.ChatID, msgToCreate) - if err != nil { - logger.ErrorCF("qq", "Failed to send C2C message", map[string]any{ - "error": err.Error(), - }) - return fmt.Errorf("qq send: %w", channels.ErrTemporary) + // Use appropriate API based on peer type + if msg.Peer.Kind == "group" { + // send group message + _, err := c.api.PostGroupMessage(ctx, msg.ChatID, msgToCreate) + if err != nil { + logger.ErrorCF("qq", "Failed to send group message", map[string]any{ + "error": err.Error(), + }) + return fmt.Errorf("qq send: %w", channels.ErrTemporary) + } + } else { + // send C2C (private) message + _, err := c.api.PostC2CMessage(ctx, msg.ChatID, msgToCreate) + if err != nil { + logger.ErrorCF("qq", "Failed to send C2C message", map[string]any{ + "error": err.Error(), + }) + return fmt.Errorf("qq send: %w", channels.ErrTemporary) + } } return nil