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
This commit is contained in:
Hakancan 2026-03-08 23:17:23 +00:00
parent 3738040987
commit 9740b547ea
3 changed files with 21 additions and 7 deletions

View file

@ -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{

View file

@ -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.

View file

@ -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