refactor(channels): emit inbound context in secondary adapters
This commit is contained in:
parent
cf11ff70c3
commit
963ed07d69
4 changed files with 78 additions and 12 deletions
|
|
@ -350,8 +350,9 @@ func (c *LINEChannel) processEvent(event lineEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// In group chats, apply unified group trigger filtering
|
// In group chats, apply unified group trigger filtering
|
||||||
|
isMentioned := false
|
||||||
if isGroup {
|
if isGroup {
|
||||||
isMentioned := c.isBotMentioned(msg)
|
isMentioned = c.isBotMentioned(msg)
|
||||||
respond, cleaned := c.ShouldRespondInGroup(isMentioned, content)
|
respond, cleaned := c.ShouldRespondInGroup(isMentioned, content)
|
||||||
if !respond {
|
if !respond {
|
||||||
logger.DebugCF("line", "Ignoring group message by group trigger", map[string]any{
|
logger.DebugCF("line", "Ignoring group message by group trigger", map[string]any{
|
||||||
|
|
@ -392,7 +393,25 @@ func (c *LINEChannel) processEvent(event lineEvent) {
|
||||||
return
|
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.
|
// 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)
|
senderID := strconv.FormatInt(userID, 10)
|
||||||
var chatID string
|
var chatID string
|
||||||
|
var contextChatID string
|
||||||
|
var contextChatType string
|
||||||
|
|
||||||
var peer bus.Peer
|
var peer bus.Peer
|
||||||
|
|
||||||
|
|
@ -1003,11 +1005,15 @@ func (c *OneBotChannel) handleMessage(raw *oneBotRawEvent) {
|
||||||
switch raw.MessageType {
|
switch raw.MessageType {
|
||||||
case "private":
|
case "private":
|
||||||
chatID = "private:" + senderID
|
chatID = "private:" + senderID
|
||||||
|
contextChatID = senderID
|
||||||
|
contextChatType = "direct"
|
||||||
peer = bus.Peer{Kind: "direct", ID: senderID}
|
peer = bus.Peer{Kind: "direct", ID: senderID}
|
||||||
|
|
||||||
case "group":
|
case "group":
|
||||||
groupIDStr := strconv.FormatInt(groupID, 10)
|
groupIDStr := strconv.FormatInt(groupID, 10)
|
||||||
chatID = "group:" + groupIDStr
|
chatID = "group:" + groupIDStr
|
||||||
|
contextChatID = groupIDStr
|
||||||
|
contextChatType = "group"
|
||||||
peer = bus.Peer{Kind: "group", ID: groupIDStr}
|
peer = bus.Peer{Kind: "group", ID: groupIDStr}
|
||||||
metadata["group_id"] = groupIDStr
|
metadata["group_id"] = groupIDStr
|
||||||
|
|
||||||
|
|
@ -1072,7 +1078,18 @@ func (c *OneBotChannel) handleMessage(raw *oneBotRawEvent) {
|
||||||
return
|
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 {
|
func (c *OneBotChannel) isDuplicate(messageID string) bool {
|
||||||
|
|
|
||||||
|
|
@ -647,15 +647,23 @@ func (c *QQChannel) handleC2CMessage() event.C2CMessageEventHandler {
|
||||||
metadata := map[string]string{
|
metadata := map[string]string{
|
||||||
"account_id": senderID,
|
"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},
|
bus.Peer{Kind: "direct", ID: senderID},
|
||||||
data.ID,
|
|
||||||
senderID,
|
|
||||||
senderID,
|
senderID,
|
||||||
content,
|
content,
|
||||||
mediaPaths,
|
mediaPaths,
|
||||||
metadata,
|
inboundCtx,
|
||||||
sender,
|
sender,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -725,15 +733,24 @@ func (c *QQChannel) handleGroupATMessage() event.GroupATMessageEventHandler {
|
||||||
"account_id": senderID,
|
"account_id": senderID,
|
||||||
"group_id": data.GroupID,
|
"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},
|
bus.Peer{Kind: "group", ID: data.GroupID},
|
||||||
data.ID,
|
|
||||||
senderID,
|
|
||||||
data.GroupID,
|
data.GroupID,
|
||||||
content,
|
content,
|
||||||
mediaPaths,
|
mediaPaths,
|
||||||
metadata,
|
inboundCtx,
|
||||||
sender,
|
sender,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -583,7 +583,20 @@ func (c *WeComChannel) dispatchIncoming(reqID string, msg wecomIncomingMessage)
|
||||||
metadata["quote_text"] = quoteText
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue