diff --git a/pkg/channels/line/line.go b/pkg/channels/line/line.go index e29896389..269f14997 100644 --- a/pkg/channels/line/line.go +++ b/pkg/channels/line/line.go @@ -350,8 +350,9 @@ func (c *LINEChannel) processEvent(event lineEvent) { } // In group chats, apply unified group trigger filtering + isMentioned := false if isGroup { - isMentioned := c.isBotMentioned(msg) + isMentioned = c.isBotMentioned(msg) respond, cleaned := c.ShouldRespondInGroup(isMentioned, content) if !respond { logger.DebugCF("line", "Ignoring group message by group trigger", map[string]any{ @@ -392,7 +393,25 @@ func (c *LINEChannel) processEvent(event lineEvent) { return } - c.HandleMessage(c.ctx, peer, msg.ID, senderID, chatID, content, mediaPaths, metadata, sender) + inboundCtx := bus.InboundContext{ + Channel: c.Name(), + ChatID: chatID, + ChatType: peer.Kind, + SenderID: senderID, + MessageID: msg.ID, + Mentioned: isMentioned, + Raw: metadata, + } + if event.ReplyToken != "" { + inboundCtx.ReplyHandles = map[string]string{ + "reply_token": event.ReplyToken, + } + if msg.QuoteToken != "" { + inboundCtx.ReplyHandles["quote_token"] = msg.QuoteToken + } + } + + c.HandleMessageWithContext(c.ctx, peer, chatID, content, mediaPaths, inboundCtx, sender) } // isBotMentioned checks if the bot is mentioned in the message. diff --git a/pkg/channels/onebot/onebot.go b/pkg/channels/onebot/onebot.go index a9b95c20f..e5651b046 100644 --- a/pkg/channels/onebot/onebot.go +++ b/pkg/channels/onebot/onebot.go @@ -991,6 +991,8 @@ func (c *OneBotChannel) handleMessage(raw *oneBotRawEvent) { senderID := strconv.FormatInt(userID, 10) var chatID string + var contextChatID string + var contextChatType string var peer bus.Peer @@ -1003,11 +1005,15 @@ func (c *OneBotChannel) handleMessage(raw *oneBotRawEvent) { switch raw.MessageType { case "private": chatID = "private:" + senderID + contextChatID = senderID + contextChatType = "direct" peer = bus.Peer{Kind: "direct", ID: senderID} case "group": groupIDStr := strconv.FormatInt(groupID, 10) chatID = "group:" + groupIDStr + contextChatID = groupIDStr + contextChatType = "group" peer = bus.Peer{Kind: "group", ID: groupIDStr} metadata["group_id"] = groupIDStr @@ -1072,7 +1078,18 @@ func (c *OneBotChannel) handleMessage(raw *oneBotRawEvent) { return } - c.HandleMessage(c.ctx, peer, messageID, senderID, chatID, content, parsed.Media, metadata, senderInfo) + inboundCtx := bus.InboundContext{ + Channel: c.Name(), + ChatID: contextChatID, + ChatType: contextChatType, + SenderID: senderID, + MessageID: messageID, + Mentioned: isBotMentioned, + ReplyToMessageID: parsed.ReplyTo, + Raw: metadata, + } + + c.HandleMessageWithContext(c.ctx, peer, chatID, content, parsed.Media, inboundCtx, senderInfo) } func (c *OneBotChannel) isDuplicate(messageID string) bool { diff --git a/pkg/channels/qq/qq.go b/pkg/channels/qq/qq.go index 3a8cf9652..ba0045da6 100644 --- a/pkg/channels/qq/qq.go +++ b/pkg/channels/qq/qq.go @@ -647,15 +647,23 @@ func (c *QQChannel) handleC2CMessage() event.C2CMessageEventHandler { metadata := map[string]string{ "account_id": senderID, } + inboundCtx := bus.InboundContext{ + Channel: c.Name(), + Account: c.config.AppID, + ChatID: senderID, + ChatType: "direct", + SenderID: senderID, + MessageID: data.ID, + Raw: metadata, + } - c.HandleMessage(c.ctx, + c.HandleMessageWithContext( + c.ctx, bus.Peer{Kind: "direct", ID: senderID}, - data.ID, - senderID, senderID, content, mediaPaths, - metadata, + inboundCtx, sender, ) @@ -725,15 +733,24 @@ func (c *QQChannel) handleGroupATMessage() event.GroupATMessageEventHandler { "account_id": senderID, "group_id": data.GroupID, } + inboundCtx := bus.InboundContext{ + Channel: c.Name(), + Account: c.config.AppID, + ChatID: data.GroupID, + ChatType: "group", + SenderID: senderID, + MessageID: data.ID, + Mentioned: true, + Raw: metadata, + } - c.HandleMessage(c.ctx, + c.HandleMessageWithContext( + c.ctx, bus.Peer{Kind: "group", ID: data.GroupID}, - data.ID, - senderID, data.GroupID, content, mediaPaths, - metadata, + inboundCtx, sender, ) diff --git a/pkg/channels/wecom/wecom.go b/pkg/channels/wecom/wecom.go index 9689d5171..65b9b4ca4 100644 --- a/pkg/channels/wecom/wecom.go +++ b/pkg/channels/wecom/wecom.go @@ -583,7 +583,20 @@ func (c *WeComChannel) dispatchIncoming(reqID string, msg wecomIncomingMessage) metadata["quote_text"] = quoteText } - c.HandleMessage(c.ctx, peer, msg.MsgID, senderID, actualChatID, content, mediaRefs, metadata, sender) + inboundCtx := bus.InboundContext{ + Channel: c.Name(), + Account: strings.TrimSpace(msg.AIBotID), + ChatID: actualChatID, + ChatType: peerKind, + SenderID: senderID, + MessageID: msg.MsgID, + ReplyHandles: map[string]string{ + "req_id": reqID, + }, + Raw: metadata, + } + + c.HandleMessageWithContext(c.ctx, peer, actualChatID, content, mediaRefs, inboundCtx, sender) return nil }