From 89e314d05b0b057ee3233c4f1e89b66a3ed458a2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 2 Apr 2026 08:06:36 +0200 Subject: [PATCH] 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 --- .../whatsapp_native/whatsapp_native.go | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pkg/channels/whatsapp_native/whatsapp_native.go b/pkg/channels/whatsapp_native/whatsapp_native.go index 35d57f11a..ca4928fa9 100644 --- a/pkg/channels/whatsapp_native/whatsapp_native.go +++ b/pkg/channels/whatsapp_native/whatsapp_native.go @@ -68,7 +68,10 @@ func NewWhatsAppNativeChannel( bus *bus.MessageBus, storePath string, ) (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 == "" { storePath = "whatsapp" } @@ -393,11 +396,41 @@ func (c *WhatsAppNativeChannel) handleIncoming(evt *events.Message) { return } + isGroup := evt.Info.Chat.Server == types.GroupServer + logger.DebugCF( "whatsapp", "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) }