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): allow resharing status posts (#862)

Aldino Kemal767742b2b97d
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index c666c740..56d6fef1 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1254,6 +1254,10 @@ paths:
description: |
List of phone numbers to mention (ghost mentions - no @ required in message text).
Use special keyword "@everyone" to mention all group participants.
+ allow_reshare:
+ type: boolean
+ example: false
+ description: Show the reshare button to status viewers. Requires `phone` to be `status@broadcast`; GOWA rejects the field for any other recipient.
responses:
'200':
description: OK
@@ -1338,6 +1342,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ allow_reshare:
+ type: boolean
+ example: false
+ description: Show the reshare button to status viewers. Requires `phone` to be `status@broadcast`; GOWA rejects the field for any other recipient.
responses:
'200':
description: OK
@@ -1617,6 +1625,10 @@ paths:
type: boolean
example: false
description: Whether this is a forwarded message
+ allow_reshare:
+ type: boolean
+ example: false
+ description: Show the reshare button to status viewers. Requires `phone` to be `status@broadcast`; GOWA rejects the field for any other recipient.
responses:
'200':
description: OK
diff --git a/src/domains/send/image.go b/src/domains/send/image.go
index e2dd2b64..ea62164f 100644
--- a/src/domains/send/image.go
+++ b/src/domains/send/image.go
@@ -12,4 +12,5 @@ type ImageRequest struct {
ViewOnce bool `json:"view_once" form:"view_once"`
Compress bool `json:"compress"`
HD bool `json:"hd" form:"hd"`
+ AllowReshare bool `json:"allow_reshare,omitempty" form:"allow_reshare"` // status@broadcast only: let viewers reshare the status
}
diff --git a/src/domains/send/text.go b/src/domains/send/text.go
index 9846bea4..c674394e 100644
--- a/src/domains/send/text.go
+++ b/src/domains/send/text.go
@@ -4,5 +4,6 @@ type MessageRequest struct {
BaseRequest
Message string `json:"message" form:"message"`
ReplyMessageID *string `json:"reply_message_id" form:"reply_message_id"`
- Mentions []string `json:"mentions,omitempty" form:"mentions"` // List of phone numbers/JIDs to mention (ghost mentions)
+ Mentions []string `json:"mentions,omitempty" form:"mentions"` // List of phone numbers/JIDs to mention (ghost mentions)
+ AllowReshare bool `json:"allow_reshare,omitempty" form:"allow_reshare"` // status@broadcast only: let viewers reshare the status
}
diff --git a/src/domains/send/video.go b/src/domains/send/video.go
index 66d88ea8..593cd2c7 100644
--- a/src/domains/send/video.go
+++ b/src/domains/send/video.go
@@ -13,4 +13,5 @@ type VideoRequest struct {
HD bool `json:"hd" form:"hd"`
GifPlayback bool `json:"gif_playback" form:"gif_playback"`
VideoURL *string `json:"video_url" form:"video_url"`
+ AllowReshare bool `json:"allow_reshare,omitempty" form:"allow_reshare"` // status@broadcast only: let viewers reshare the status
}
diff --git a/src/ui/mcp/schemas.go b/src/ui/mcp/schemas.go
index a6e40491..e41ee474 100644
--- a/src/ui/mcp/schemas.go
+++ b/src/ui/mcp/schemas.go
@@ -22,6 +22,7 @@ const sendSchema = `{
"hd": {"type": "boolean", "description": "image/video: send HD without upscaling (image: 2560px max edge; video: H.264 8-bit YUV 4:2:0 at CRF 23, capped at 1280x1280); overrides compress when true (default false)"},
"video_url": {"type": "string", "description": "type=video: URL of the video (mp4/mkv/avi, fetched server-side)"},
"gif_playback": {"type": "boolean", "description": "type=video: play as looping GIF (default false)"},
+ "allow_reshare": {"type": "boolean", "description": "text/image/video: let viewers reshare the status; requires phone status@broadcast (default false)"},
"audio_url": {"type": "string", "description": "type=audio: URL of the audio file (fetched server-side)"},
"ptt": {"type": "boolean", "description": "type=audio: send as voice note (requires ffmpeg server-side, default false)"},
"file_url": {"type": "string", "description": "type=document: URL of the file; MIME type and filename derived server-side"},
diff --git a/src/ui/mcp/send.go b/src/ui/mcp/send.go
index 4e3ee318..610ae960 100644
--- a/src/ui/mcp/send.go
+++ b/src/ui/mcp/send.go
@@ -64,29 +64,32 @@ func (s *SendHandler) handleSend(ctx context.Context, request mcpg.CallToolReque
Message: request.GetString("message", ""),
ReplyMessageID: &replyID,
Mentions: request.GetStringSlice("mentions", nil),
+ AllowReshare: request.GetBool("allow_reshare", false),
})
case "image":
imageURL := request.GetString("image_url", "")
res, err = s.sendService.SendImage(ctx, domainSend.ImageRequest{
- 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),
+ 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),
+ AllowReshare: request.GetBool("allow_reshare", false),
})
case "video":
videoURL := request.GetString("video_url", "")
res, err = s.sendService.SendVideo(ctx, domainSend.VideoRequest{
- 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),
- HD: request.GetBool("hd", false),
+ 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),
+ HD: request.GetBool("hd", false),
+ AllowReshare: request.GetBool("allow_reshare", false),
})
case "audio":
audioURL := request.GetString("audio_url", "")
diff --git a/src/ui/mcp/send_test.go b/src/ui/mcp/send_test.go
index 9f05e1f1..0d1df10c 100644
--- a/src/ui/mcp/send_test.go
+++ b/src/ui/mcp/send_test.go
@@ -151,6 +151,24 @@ func TestHandleSendDispatch(t *testing.T) {
assert.True(t, svc.lastVideo.HD)
})
+ t.Run("allow_reshare", func(t *testing.T) {
+ svc := &stubSendService{}
+ h := InitMcpSend(svc, &stubResolver{})
+ for _, args := range []map[string]any{
+ {"type": "text", "message": "hi"},
+ {"type": "image", "image_url": "http://x/a.png"},
+ {"type": "video", "video_url": "http://x/a.mp4"},
+ } {
+ args["phone"] = "status@broadcast"
+ args["allow_reshare"] = true
+ _, err := h.handleSend(deviceCtx(), callReq(args))
+ require.NoError(t, err)
+ }
+ assert.True(t, svc.lastText.AllowReshare)
+ assert.True(t, svc.lastImage.AllowReshare)
+ assert.True(t, svc.lastVideo.AllowReshare)
+ })
+
t.Run("audio", func(t *testing.T) {
svc := &stubSendService{}
h := InitMcpSend(svc, &stubResolver{})
diff --git a/src/usecase/send.go b/src/usecase/send.go
index 6ef697d0..eff6c9e8 100644
--- a/src/usecase/send.go
+++ b/src/usecase/send.go
@@ -285,6 +285,20 @@ func (service serviceSend) mergeReplyContext(ctx context.Context, contextInfo *w
return contextInfo
}
+// withAllowReshare marks a status post as reshareable. Without
+// FeatureEligibilities.CanBeReshared, viewers get no reshare button, even when
+// the poster's status privacy allows resharing.
+func withAllowReshare(contextInfo *waE2E.ContextInfo, allowReshare bool) *waE2E.ContextInfo {
+ if !allowReshare {
+ return contextInfo
+ }
+ if contextInfo == nil {
+ contextInfo = &waE2E.ContextInfo{}
+ }
+ contextInfo.FeatureEligibilities = &waE2E.ContextInfo_FeatureEligibilities{CanBeReshared: proto.Bool(true)}
+ return contextInfo
+}
+
func normalizeSendError(err error) error {
if err == nil {
return nil
@@ -337,6 +351,7 @@ func (service serviceSend) SendText(ctx context.Context, request domainSend.Mess
}
msg.ExtendedTextMessage.ContextInfo = service.mergeReplyContext(ctx, msg.ExtendedTextMessage.ContextInfo, request.ReplyMessageID)
+ msg.ExtendedTextMessage.ContextInfo = withAllowReshare(msg.ExtendedTextMessage.ContextInfo, request.AllowReshare)
ts, err := service.wrapSendMessage(ctx, client, dataWaRecipient, msg, request.Message)
if err != nil {
@@ -508,6 +523,7 @@ func (service serviceSend) SendImage(ctx context.Context, request domainSend.Ima
msg.ImageMessage.ContextInfo.MentionedJID = mentionedJIDs
}
msg.ImageMessage.ContextInfo = service.mergeReplyContext(ctx, msg.ImageMessage.ContextInfo, request.ReplyMessageID)
+ msg.ImageMessage.ContextInfo = withAllowReshare(msg.ImageMessage.ContextInfo, request.AllowReshare)
caption := "🖼️ Image"
if request.Caption != "" {
@@ -1066,6 +1082,7 @@ func (service serviceSend) SendVideo(ctx context.Context, request domainSend.Vid
msg.VideoMessage.ContextInfo.MentionedJID = mentionedJIDs
}
msg.VideoMessage.ContextInfo = service.mergeReplyContext(ctx, msg.VideoMessage.ContextInfo, request.ReplyMessageID)
+ msg.VideoMessage.ContextInfo = withAllowReshare(msg.VideoMessage.ContextInfo, request.AllowReshare)
caption := "🎥 Video"
if request.Caption != "" {
diff --git a/src/usecase/send_test.go b/src/usecase/send_test.go
index 802e4a2f..f0fcbd0c 100644
--- a/src/usecase/send_test.go
+++ b/src/usecase/send_test.go
@@ -613,3 +613,17 @@ func TestMergeReplyContextPassesThroughAnUnparseableSender(t *testing.T) {
t.Fatalf("expected the raw sender to survive, got %q", got.GetParticipant())
}
}
+
+func TestWithAllowReshare(t *testing.T) {
+ assert.Nil(t, withAllowReshare(nil, false))
+
+ got := withAllowReshare(nil, true)
+ require.NotNil(t, got)
+ assert.True(t, got.GetFeatureEligibilities().GetCanBeReshared())
+
+ existing := &waE2E.ContextInfo{MentionedJID: []string{"[email protected]"}}
+ got = withAllowReshare(existing, true)
+ assert.Same(t, existing, got)
+ assert.Equal(t, []string{"[email protected]"}, got.GetMentionedJID())
+ assert.True(t, got.GetFeatureEligibilities().GetCanBeReshared())
+}
diff --git a/src/validations/send_validation.go b/src/validations/send_validation.go
index 253f7f00..939903fd 100644
--- a/src/validations/send_validation.go
+++ b/src/validations/send_validation.go
@@ -13,6 +13,7 @@ import (
"github.com/dustin/go-humanize"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/go-ozzo/ozzo-validation/v4/is"
+ "go.mau.fi/whatsmeow/types"
)
// ValidDurationValues contains WhatsApp's allowed disappearing message durations in seconds.
@@ -39,6 +40,15 @@ func validateDuration(dur *int) error {
)
}
+// validateAllowReshare rejects allow_reshare outside a status post: the
+// reshare eligibility flag only has meaning on status@broadcast.
+func validateAllowReshare(allow bool, phone string) error {
+ if allow && strings.TrimSpace(phone) != types.StatusBroadcastJID.String() {
+ return pkgError.ValidationError("allow_reshare is only supported when phone is status@broadcast")
+ }
+ return nil
+}
+
// validatePhoneNumber validates that the phone number is in international format (not starting with 0)
func validatePhoneNumber(phone string) error {
phoneNumber := strings.TrimSpace(phone)
@@ -82,6 +92,10 @@ func ValidateSendMessage(ctx context.Context, request domainSend.MessageRequest)
return err
}
+ if err := validateAllowReshare(request.AllowReshare, request.Phone); err != nil {
+ return err
+ }
+
return validateMentions(request.Mentions)
}
@@ -144,6 +158,10 @@ func ValidateSendImage(ctx context.Context, request domainSend.ImageRequest) err
return err
}
+ if err := validateAllowReshare(request.AllowReshare, request.Phone); err != nil {
+ return err
+ }
+
return validateMentions(request.Mentions)
}
@@ -298,6 +316,10 @@ func ValidateSendVideo(ctx context.Context, request domainSend.VideoRequest) err
return err
}
+ if err := validateAllowReshare(request.AllowReshare, request.Phone); err != nil {
+ return err
+ }
+
return validateMentions(request.Mentions)
}
diff --git a/src/validations/send_validation_test.go b/src/validations/send_validation_test.go
index 0efc89a9..020a678d 100644
--- a/src/validations/send_validation_test.go
+++ b/src/validations/send_validation_test.go
@@ -52,6 +52,28 @@ func TestValidateSendMessage(t *testing.T) {
}},
err: pkgError.ValidationError("message: cannot be blank."),
},
+ {
+ name: "should success with allow_reshare on status",
+ args: args{request: domainSend.MessageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "status@broadcast",
+ },
+ Message: "Hello this is testing",
+ AllowReshare: true,
+ }},
+ err: nil,
+ },
+ {
+ name: "should error with allow_reshare outside status",
+ args: args{request: domainSend.MessageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ Message: "Hello this is testing",
+ AllowReshare: true,
+ }},
+ err: pkgError.ValidationError("allow_reshare is only supported when phone is status@broadcast"),
+ },
}
for _, tt := range tests {
@@ -90,6 +112,17 @@ func TestValidateSendImage(t *testing.T) {
}},
err: nil,
},
+ {
+ name: "should error with allow_reshare outside status",
+ args: args{request: domainSend.ImageRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ Image: image,
+ AllowReshare: true,
+ }},
+ err: pkgError.ValidationError("allow_reshare is only supported when phone is status@broadcast"),
+ },
{
name: "should error with empty phone",
args: args{request: domainSend.ImageRequest{
@@ -245,6 +278,17 @@ func TestValidateSendVideo(t *testing.T) {
}},
err: nil,
},
+ {
+ name: "should error with allow_reshare outside status",
+ args: args{request: domainSend.VideoRequest{
+ BaseRequest: domainSend.BaseRequest{
+ Phone: "[email protected]",
+ },
+ Video: file,
+ AllowReshare: true,
+ }},
+ err: pkgError.ValidationError("allow_reshare is only supported when phone is status@broadcast"),
+ },
{
name: "should error with empty phone",
args: args{request: domainSend.VideoRequest{