Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

fix: use BuildReaction for group chat reactions (#615)

Aldino Kemal432e9748a97d
diff --git a/src/usecase/message.go b/src/usecase/message.go
index 20d61220..cf39c3a6 100644
--- a/src/usecase/message.go
+++ b/src/usecase/message.go
@@ -17,7 +17,6 @@ import (
"github.com/sirupsen/logrus"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/appstate"
- "go.mau.fi/whatsmeow/proto/waCommon"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/proto/waSyncAction"
"go.mau.fi/whatsmeow/types"
@@ -81,30 +80,35 @@ func (service serviceMessage) ReactMessage(ctx context.Context, request domainMe
return response, err
}
- // FromMe in reaction refers to whether the ORIGINAL message (being reacted to) was sent by us
- isFromMe := true
+ // Determine the sender of the original message for BuildReaction.
+ // BuildReaction uses BuildMessageKey internally, which correctly sets the
+ // Participant field for group chats — required by the WhatsApp protocol.
+ // An empty JID means "message was from me".
+ senderJID := types.EmptyJID
message, err := service.chatStorageRepo.GetMessageByID(request.MessageID)
if err != nil {
- logrus.Warnf("Failed to lookup message %s for reaction: %v, using fallback heuristic", request.MessageID, err)
- isFromMe = len(request.MessageID) <= 22
+ logrus.Warnf("Failed to lookup message %s for reaction: %v, using heuristic", request.MessageID, err)
+ if len(request.MessageID) > 22 {
+ if dataWaRecipient.Server == types.GroupServer {
+ logrus.Warnf("Cannot determine original sender for group reaction to %s — reaction may not be delivered", request.MessageID)
+ }
+ }
} else if message != nil {
- isFromMe = message.IsFromMe
+ if !message.IsFromMe && message.Sender != "" {
+ parsed, parseErr := utils.ParseJID(message.Sender)
+ if parseErr == nil {
+ senderJID = parsed
+ } else {
+ logrus.Warnf("Failed to parse sender JID '%s' for reaction: %v", message.Sender, parseErr)
+ }
+ }
} else {
- logrus.Debugf("Message %s not found in database, using ID length heuristic for FromMe", request.MessageID)
- isFromMe = len(request.MessageID) <= 22
+ logrus.Debugf("Message %s not found in database, assuming sent by me", request.MessageID)
}
- msg := &waE2E.Message{
- ReactionMessage: &waE2E.ReactionMessage{
- Key: &waCommon.MessageKey{
- FromMe: proto.Bool(isFromMe),
- ID: proto.String(request.MessageID),
- RemoteJID: proto.String(dataWaRecipient.String()),
- },
- Text: proto.String(request.Emoji),
- SenderTimestampMS: proto.Int64(time.Now().UnixMilli()),
- },
- }
+ // BuildReaction correctly constructs the MessageKey with Participant field
+ // for group chats, which is required for the reaction to be delivered.
+ msg := client.BuildReaction(dataWaRecipient, senderJID, request.MessageID, request.Emoji)
ts, err := client.SendMessage(ctx, dataWaRecipient, msg)
if err != nil {
return response, err