mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
refactor(channels): emit inbound context in secondary adapters
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+25
-8
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user