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.

feat: allow group-admin bots to revoke other members' messages (#640)

Aldino Kemal536f5fb5d552
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index b1b81204..98f4ca03 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1491,6 +1491,12 @@ paths:
tags:
- message
summary: Revoke Message
+ description: |
+ Revoke (delete for everyone) a message. Revokes the bot's own message by default.
+ If the target message was sent by another user and is present in chat storage,
+ the original sender is resolved automatically so a group-admin bot can revoke
+ other members' messages (anti-spam use case). The WhatsApp server rejects the
+ request if the bot is not a group admin.
parameters:
- $ref: '#/components/parameters/DeviceIdHeader'
- in: path
diff --git a/src/usecase/message.go b/src/usecase/message.go
index cf39c3a6..cabbc854 100644
--- a/src/usecase/message.go
+++ b/src/usecase/message.go
@@ -134,7 +134,28 @@ func (service serviceMessage) RevokeMessage(ctx context.Context, request domainM
return response, err
}
- ts, err := client.SendMessage(ctx, dataWaRecipient, client.BuildRevoke(dataWaRecipient, types.EmptyJID, request.MessageID))
+ // Resolve the original sender so group admins can revoke other members'
+ // messages. BuildRevoke treats types.EmptyJID as "message was from me";
+ // any other JID is admin-revoke and requires the bot to be group admin.
+ // WhatsApp message IDs are globally unique, so a cross-device lookup
+ // via GetMessageByID yields the same sender regardless of which device
+ // owns the row.
+ senderJID := types.EmptyJID
+ message, lookupErr := service.chatStorageRepo.GetMessageByID(request.MessageID)
+ if lookupErr != nil {
+ logrus.Warnf("Failed to lookup message %s for revoke: %v, assuming self-revoke", request.MessageID, lookupErr)
+ } else if message != nil && !message.IsFromMe && message.Sender != "" {
+ parsed, parseErr := utils.ParseJID(message.Sender)
+ if parseErr != nil {
+ logrus.Warnf("Failed to parse sender JID '%s' for revoke: %v", message.Sender, parseErr)
+ } else {
+ // Stored senders can still be @lid; whatsmeow's Revoke needs
+ // the phone-number form or it rejects the request at the wire.
+ senderJID = whatsapp.NormalizeJIDFromLID(ctx, parsed, client)
+ }
+ }
+
+ ts, err := client.SendMessage(ctx, dataWaRecipient, client.BuildRevoke(dataWaRecipient, senderJID, request.MessageID))
if err != nil {
return response, err
}
diff --git a/src/views/components/MessageRevoke.js b/src/views/components/MessageRevoke.js
index 4a4f709e..144132aa 100644
--- a/src/views/components/MessageRevoke.js
+++ b/src/views/components/MessageRevoke.js
@@ -77,7 +77,7 @@ export default {
<a class="ui red right ribbon label">Message</a>
<div class="header">Revoke Message</div>
<div class="description">
- any message in private or group chat
+ Revoke your own message, or any member's message in a group where you are admin
</div>
</div>
</div>
@@ -94,7 +94,7 @@ export default {
<div class="field">
<label> Message ID</label>
- <input v-model="message_id" type="text" placeholder="Please enter your message id"
+ <input v-model="message_id" type="text" placeholder="Please enter the message id to revoke"
aria-label="message id">
</div>
</form>