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(send): support mentions in image, file and video captions (#853)

Aldino Kemal424c6875a83c
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 401ba959..153bd90b 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1297,6 +1297,15 @@ paths:
type: string
example: selamat malam
description: Caption to send
+ mentions:
+ type: array
+ items:
+ type: string
+ example: ["628123456789", "@everyone"]
+ description: |
+ List of phone numbers to mention (ghost mentions - no @ required in caption).
+ `@phone` in the caption is also mentioned. Use special keyword "@everyone" to mention all group participants.
+ Send one `mentions` form field per entry.
reply_message_id:
type: string
example: 3EB089B9D6ADD58153C561
@@ -1435,6 +1444,15 @@ paths:
type: string
example: selamat malam
description: Caption to send
+ mentions:
+ type: array
+ items:
+ type: string
+ example: ["628123456789", "@everyone"]
+ description: |
+ List of phone numbers to mention (ghost mentions - no @ required in caption).
+ `@phone` in the caption is also mentioned. Use special keyword "@everyone" to mention all group participants.
+ Send one `mentions` form field per entry.
reply_message_id:
type: string
example: 3EB089B9D6ADD58153C561
@@ -1554,6 +1572,15 @@ paths:
type: string
example: ini contoh caption video
description: Caption to send
+ mentions:
+ type: array
+ items:
+ type: string
+ example: ["628123456789", "@everyone"]
+ description: |
+ List of phone numbers to mention (ghost mentions - no @ required in caption).
+ `@phone` in the caption is also mentioned. Use special keyword "@everyone" to mention all group participants.
+ Send one `mentions` form field per entry.
reply_message_id:
type: string
example: 3EB089B9D6ADD58153C561
diff --git a/readme.md b/readme.md
index e4e702a1..a6acec28 100644
--- a/readme.md
+++ b/readme.md
@@ -86,7 +86,7 @@ Download:
- **MCP (Model Context Protocol) server support** — Integrate with AI agents and tools using a standardized protocol.
- **Optional MCP OAuth 2.1** — Connect remote MCP clients that cannot supply a Basic Auth header. See
[MCP OAuth](./docs/mcp-oauth.md).
-- Mention users:
+- Mention users in message text and image, video, or file captions:
- `@phoneNumber`
- Example: `Hello @628974812XXXX, @628974812XXXX`
- **Ghost mentions (mention all)** — Mention group participants without showing `@phone` in the message text.
diff --git a/src/domains/send/file.go b/src/domains/send/file.go
index bcd43ec4..bcb2e752 100644
--- a/src/domains/send/file.go
+++ b/src/domains/send/file.go
@@ -8,4 +8,5 @@ type FileRequest struct {
FileURL *string `json:"file_url" form:"file_url"`
Caption string `json:"caption" form:"caption"`
ReplyMessageID *string `json:"reply_message_id" form:"reply_message_id"`
+ Mentions []string `json:"mentions,omitempty" form:"mentions"` // Phone numbers/JIDs to mention (ghost mentions)
}
diff --git a/src/domains/send/image.go b/src/domains/send/image.go
index a0e2ac88..e2dd2b64 100644
--- a/src/domains/send/image.go
+++ b/src/domains/send/image.go
@@ -6,6 +6,7 @@ type ImageRequest struct {
BaseRequest
Caption string `json:"caption" form:"caption"`
ReplyMessageID *string `json:"reply_message_id" form:"reply_message_id"`
+ Mentions []string `json:"mentions,omitempty" form:"mentions"` // Phone numbers/JIDs to mention (ghost mentions)
Image *multipart.FileHeader `json:"image" form:"image"`
ImageURL *string `json:"image_url" form:"image_url"`
ViewOnce bool `json:"view_once" form:"view_once"`
diff --git a/src/domains/send/video.go b/src/domains/send/video.go
index 2e690cd8..66d88ea8 100644
--- a/src/domains/send/video.go
+++ b/src/domains/send/video.go
@@ -6,6 +6,7 @@ type VideoRequest struct {
BaseRequest
Caption string `json:"caption" form:"caption"`
ReplyMessageID *string `json:"reply_message_id" form:"reply_message_id"`
+ Mentions []string `json:"mentions,omitempty" form:"mentions"` // Phone numbers/JIDs to mention (ghost mentions)
Video *multipart.FileHeader `json:"video" form:"video"`
ViewOnce bool `json:"view_once" form:"view_once"`
Compress bool `json:"compress"`
diff --git a/src/ui/mcp/schemas.go b/src/ui/mcp/schemas.go
index 561fbcf9..0f5693ab 100644
--- a/src/ui/mcp/schemas.go
+++ b/src/ui/mcp/schemas.go
@@ -14,7 +14,7 @@ const sendSchema = `{
"is_forwarded": {"type": "boolean", "description": "Mark the message as forwarded (default false)"},
"message": {"type": "string", "description": "type=text: the text body"},
"reply_message_id": {"type": "string", "description": "type=text: message ID to reply to"},
- "mentions": {"type": "array", "items": {"type": "string"}, "description": "type=text: ghost mentions; \"@everyone\" mentions all group participants"},
+ "mentions": {"type": "array", "items": {"type": "string"}, "description": "text/image/video/document: ghost mentions; \"@everyone\" mentions all group participants"},
"image_url": {"type": "string", "description": "type=image: URL of the image (fetched server-side)"},
"caption": {"type": "string", "description": "image/video/document/link: caption text"},
"view_once": {"type": "boolean", "description": "image/video: view-once message (default false)"},
diff --git a/src/ui/mcp/send.go b/src/ui/mcp/send.go
index e0be00ae..4e3ee318 100644
--- a/src/ui/mcp/send.go
+++ b/src/ui/mcp/send.go
@@ -71,6 +71,7 @@ func (s *SendHandler) handleSend(ctx context.Context, request mcpg.CallToolReque
BaseRequest: base,
ImageURL: &imageURL,
Caption: request.GetString("caption", ""),
+ Mentions: request.GetStringSlice("mentions", nil),
ViewOnce: request.GetBool("view_once", false),
Compress: request.GetBool("compress", true),
HD: request.GetBool("hd", false),
@@ -81,6 +82,7 @@ func (s *SendHandler) handleSend(ctx context.Context, request mcpg.CallToolReque
BaseRequest: base,
VideoURL: &videoURL,
Caption: request.GetString("caption", ""),
+ Mentions: request.GetStringSlice("mentions", nil),
ViewOnce: request.GetBool("view_once", false),
GifPlayback: request.GetBool("gif_playback", false),
Compress: request.GetBool("compress", false),
@@ -99,6 +101,7 @@ func (s *SendHandler) handleSend(ctx context.Context, request mcpg.CallToolReque
BaseRequest: base,
FileURL: &fileURL,
Caption: request.GetString("caption", ""),
+ Mentions: request.GetStringSlice("mentions", nil),
})
case "sticker":
stickerURL := request.GetString("sticker_url", "")
diff --git a/src/ui/mcp/send_test.go b/src/ui/mcp/send_test.go
index 64672cba..9f05e1f1 100644
--- a/src/ui/mcp/send_test.go
+++ b/src/ui/mcp/send_test.go
@@ -125,11 +125,12 @@ func TestHandleSendDispatch(t *testing.T) {
h := InitMcpSend(svc, &stubResolver{})
_, err := h.handleSend(deviceCtx(), callReq(map[string]any{
"type": "image", "phone": "628", "image_url": "http://x/a.png",
- "caption": "c", "view_once": true, "hd": true,
+ "caption": "c", "view_once": true, "hd": true, "mentions": []any{"629", "@everyone"},
}))
require.NoError(t, err)
require.NotNil(t, svc.lastImage)
assert.Equal(t, "http://x/a.png", *svc.lastImage.ImageURL)
+ assert.Equal(t, []string{"629", "@everyone"}, svc.lastImage.Mentions)
assert.True(t, svc.lastImage.ViewOnce)
assert.True(t, svc.lastImage.Compress) // image compress defaults true
assert.True(t, svc.lastImage.HD)
@@ -140,9 +141,11 @@ func TestHandleSendDispatch(t *testing.T) {
h := InitMcpSend(svc, &stubResolver{})
_, err := h.handleSend(deviceCtx(), callReq(map[string]any{
"type": "video", "phone": "628", "video_url": "http://x/a.mp4", "gif_playback": true, "hd": true,
+ "mentions": []any{"629"},
}))
require.NoError(t, err)
require.NotNil(t, svc.lastVideo)
+ assert.Equal(t, []string{"629"}, svc.lastVideo.Mentions)
assert.True(t, svc.lastVideo.GifPlayback)
assert.False(t, svc.lastVideo.Compress) // video compress defaults false
assert.True(t, svc.lastVideo.HD)
@@ -163,10 +166,11 @@ func TestHandleSendDispatch(t *testing.T) {
svc := &stubSendService{}
h := InitMcpSend(svc, &stubResolver{})
_, err := h.handleSend(deviceCtx(), callReq(map[string]any{
- "type": "document", "phone": "628", "file_url": "http://x/a.pdf",
+ "type": "document", "phone": "628", "file_url": "http://x/a.pdf", "mentions": []any{"629"},
}))
require.NoError(t, err)
require.NotNil(t, svc.lastFile)
+ assert.Equal(t, []string{"629"}, svc.lastFile.Mentions)
})
t.Run("sticker", func(t *testing.T) {
diff --git a/src/usecase/send.go b/src/usecase/send.go
index 0508de53..18de8897 100644
--- a/src/usecase/send.go
+++ b/src/usecase/send.go
@@ -332,19 +332,8 @@ func (service serviceSend) SendText(ctx context.Context, request domainSend.Mess
msg.ExtendedTextMessage.ContextInfo.Expiration = proto.Uint32(service.getDefaultEphemeralExpiration(request.BaseRequest.Phone))
}
- // Get mentions from text (existing behavior - parses @phone from message text)
- parsedMentions := service.getMentionFromText(ctx, request.Message)
-
- // Add explicit mentions from request.Mentions (ghost mentions - no @ required in text)
- if len(request.Mentions) > 0 {
- explicitMentions := service.getMentionsFromList(ctx, request.Mentions, dataWaRecipient)
- parsedMentions = append(parsedMentions, explicitMentions...)
- // Deduplicate to avoid mentioning the same person twice
- parsedMentions = utils.UniqueStrings(parsedMentions)
- }
-
- if len(parsedMentions) > 0 {
- msg.ExtendedTextMessage.ContextInfo.MentionedJID = parsedMentions
+ if mentionedJIDs := service.resolveMentions(ctx, request.Message, request.Mentions, dataWaRecipient); len(mentionedJIDs) > 0 {
+ msg.ExtendedTextMessage.ContextInfo.MentionedJID = mentionedJIDs
}
msg.ExtendedTextMessage.ContextInfo = service.mergeReplyContext(ctx, msg.ExtendedTextMessage.ContextInfo, request.ReplyMessageID)
@@ -512,6 +501,12 @@ func (service serviceSend) SendImage(ctx context.Context, request domainSend.Ima
}
msg.ImageMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
}
+ if mentionedJIDs := service.resolveMentions(ctx, request.Caption, request.Mentions, dataWaRecipient); len(mentionedJIDs) > 0 {
+ if msg.ImageMessage.ContextInfo == nil {
+ msg.ImageMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.ImageMessage.ContextInfo.MentionedJID = mentionedJIDs
+ }
msg.ImageMessage.ContextInfo = service.mergeReplyContext(ctx, msg.ImageMessage.ContextInfo, request.ReplyMessageID)
caption := "🖼️ Image"
@@ -604,6 +599,12 @@ func (service serviceSend) SendFile(ctx context.Context, request domainSend.File
}
msg.DocumentMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
}
+ if mentionedJIDs := service.resolveMentions(ctx, request.Caption, request.Mentions, dataWaRecipient); len(mentionedJIDs) > 0 {
+ if msg.DocumentMessage.ContextInfo == nil {
+ msg.DocumentMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.DocumentMessage.ContextInfo.MentionedJID = mentionedJIDs
+ }
msg.DocumentMessage.ContextInfo = service.mergeReplyContext(ctx, msg.DocumentMessage.ContextInfo, request.ReplyMessageID)
caption := "📄 Document"
@@ -1058,6 +1059,12 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid
}
msg.VideoMessage.ContextInfo.Expiration = proto.Uint32(uint32(*request.BaseRequest.Duration))
}
+ if mentionedJIDs := service.resolveMentions(ctx, request.Caption, request.Mentions, dataWaRecipient); len(mentionedJIDs) > 0 {
+ if msg.VideoMessage.ContextInfo == nil {
+ msg.VideoMessage.ContextInfo = &waE2E.ContextInfo{}
+ }
+ msg.VideoMessage.ContextInfo.MentionedJID = mentionedJIDs
+ }
msg.VideoMessage.ContextInfo = service.mergeReplyContext(ctx, msg.VideoMessage.ContextInfo, request.ReplyMessageID)
caption := "🎥 Video"
@@ -1636,6 +1643,16 @@ func (service serviceSend) getMentionFromText(ctx context.Context, messages stri
return result
}
+// resolveMentions combines @phone mentions parsed from text with explicit (ghost)
+// mentions, deduplicated so the same person is not mentioned twice.
+func (service serviceSend) resolveMentions(ctx context.Context, text string, mentions []string, recipientJID types.JID) []string {
+ result := service.getMentionFromText(ctx, text)
+ if len(mentions) > 0 {
+ result = utils.UniqueStrings(append(result, service.getMentionsFromList(ctx, mentions, recipientJID)...))
+ }
+ return result
+}
+
// getMentionsFromList converts a list of phone numbers to JIDs for ghost mentions
// Special keyword "@everyone" will fetch all group participants
func (service serviceSend) getMentionsFromList(ctx context.Context, mentions []string, recipientJID types.JID) (result []string) {
diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go
index 13182fba..253f7f00 100644
--- a/src/validations/send_validation.go
+++ b/src/validations/send_validation.go
@@ -82,9 +82,12 @@ func ValidateSendMessage(ctx context.Context, request domainSend.MessageRequest)
return err
}
- // Validate mentions if provided
- for _, mention := range request.Mentions {
- // Skip validation for special @everyone keyword
+ return validateMentions(request.Mentions)
+}
+
+// validateMentions checks explicit (ghost) mentions; "@everyone" is a keyword, not a phone.
+func validateMentions(mentions []string) error {
+ for _, mention := range mentions {
if mention == "@everyone" {
continue
}
@@ -92,7 +95,6 @@ func ValidateSendMessage(ctx context.Context, request domainSend.MessageRequest)
return pkgError.ValidationError(fmt.Sprintf("mention %s: phone number must be in international format", mention))
}
}
-
return nil
}
@@ -142,7 +144,7 @@ func ValidateSendImage(ctx context.Context, request domainSend.ImageRequest) err
return err
}
- return nil
+ return validateMentions(request.Mentions)
}
func ValidateSendSticker(ctx context.Context, request domainSend.StickerRequest) error {
@@ -239,7 +241,7 @@ func ValidateSendFile(ctx context.Context, request domainSend.FileRequest) error
return err
}
- return nil
+ return validateMentions(request.Mentions)
}
func ValidateSendVideo(ctx context.Context, request domainSend.VideoRequest) error {
@@ -296,7 +298,7 @@ func ValidateSendVideo(ctx context.Context, request domainSend.VideoRequest) err
return err
}
- return nil
+ return validateMentions(request.Mentions)
}
func ValidateSendContact(ctx context.Context, request domainSend.ContactRequest) error {
diff --git a/src/validations/send_validation_test.go b/src/validations/send_validation_test.go
index 6282b194..c73c4ff1 100644
--- a/src/validations/send_validation_test.go
+++ b/src/validations/send_validation_test.go
@@ -134,6 +134,30 @@ func TestValidateSendImage(t *testing.T) {
}
}
+func TestValidateSendMediaMentions(t *testing.T) {
+ phone := domainSend.BaseRequest{Phone: "[email protected]"}
+ imageURL, fileURL, videoURL := "https://example.com/a.png", "https://example.com/a.pdf", "https://example.com/a.mp4"
+ invalidErr := pkgError.ValidationError("mention 08123456789: phone number must be in international format")
+
+ tests := []struct {
+ name string
+ mentions []string
+ err any
+ }{
+ {name: "no mentions", mentions: nil, err: nil},
+ {name: "valid mentions and @everyone", mentions: []string{"628123456789", "@everyone"}, err: nil},
+ {name: "local-format mention", mentions: []string{"628123456789", "08123456789"}, err: invalidErr},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equal(t, tt.err, ValidateSendImage(context.Background(), domainSend.ImageRequest{BaseRequest: phone, ImageURL: &imageURL, Mentions: tt.mentions}))
+ assert.Equal(t, tt.err, ValidateSendFile(context.Background(), domainSend.FileRequest{BaseRequest: phone, FileURL: &fileURL, Mentions: tt.mentions}))
+ assert.Equal(t, tt.err, ValidateSendVideo(context.Background(), domainSend.VideoRequest{BaseRequest: phone, VideoURL: &videoURL, Mentions: tt.mentions}))
+ })
+ }
+}
+
func TestValidateSendFile(t *testing.T) {
file := &multipart.FileHeader{
Filename: "sample-image.png",