fix(whatsapp_native): apply group_trigger filtering for native channel

Same fix as the bridge-based whatsapp channel:
- Pass WithGroupTrigger(cfg.GroupTrigger) when constructing the base channel
- In handleIncoming, detect group messages and call ShouldRespondInGroup
- Detect bot @mentions via ContextInfo.MentionedJID (native whatsmeow field)
- Call ObserveGroupMessage when not responding to retain context

https://claude.ai/code/session_01PfpBofWnnVaNf7uyBEJA4T
This commit is contained in:
github-actions[bot] 2026-04-02 08:06:36 +02:00
parent 55c15b8e29
commit 89e314d05b

View file

@ -68,7 +68,10 @@ func NewWhatsAppNativeChannel(
bus *bus.MessageBus, bus *bus.MessageBus,
storePath string, storePath string,
) (channels.Channel, error) { ) (channels.Channel, error) {
base := channels.NewBaseChannel("whatsapp_native", cfg, bus, cfg.AllowFrom, channels.WithMaxMessageLength(65536)) base := channels.NewBaseChannel("whatsapp_native", cfg, bus, cfg.AllowFrom,
channels.WithMaxMessageLength(65536),
channels.WithGroupTrigger(cfg.GroupTrigger),
)
if storePath == "" { if storePath == "" {
storePath = "whatsapp" storePath = "whatsapp"
} }
@ -393,11 +396,41 @@ func (c *WhatsAppNativeChannel) handleIncoming(evt *events.Message) {
return return
} }
isGroup := evt.Info.Chat.Server == types.GroupServer
logger.DebugCF( logger.DebugCF(
"whatsapp", "whatsapp",
"WhatsApp message received", "WhatsApp message received",
map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50)}, map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50), "is_group": isGroup},
) )
if isGroup {
// Detect bot mention via ContextInfo.MentionedJID (populated for @mentions in groups).
isMentioned := false
c.mu.Lock()
botJID := c.client.Store.ID
c.mu.Unlock()
var ctx2 *waE2E.ContextInfo
if ext := evt.Message.GetExtendedTextMessage(); ext != nil {
ctx2 = ext.GetContextInfo()
}
if ctx2 != nil && botJID != nil {
botUser := botJID.User
for _, jid := range ctx2.GetMentionedJID() {
if strings.HasPrefix(jid, botUser+"@") || jid == botUser {
isMentioned = true
break
}
}
}
respond, cleaned := c.ShouldRespondInGroup(isMentioned, content)
if !respond {
c.ObserveGroupMessage(c.runCtx, peer, messageID, senderID, chatID, content, mediaPaths, metadata, sender)
return
}
content = cleaned
}
c.HandleMessage(c.runCtx, peer, messageID, senderID, chatID, content, mediaPaths, metadata, sender) c.HandleMessage(c.runCtx, peer, messageID, senderID, chatID, content, mediaPaths, metadata, sender)
} }