Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk-go): stop an empty participant list acting on every join request

Yudhi Armyndharisf0c916336b82
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0f6746a3..ec910e6a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- The Go SDK no longer approves or rejects every pending join request when handed an empty participant list: `omitempty` dropped the empty slice, so `[]string{}` reached the gateway as the bodyless "act on every request" rather than the `400` the other four clients receive. A nil slice still means every request.
- The chart's optional ServiceMonitor now selects on a new `openwa.io/scrape-target` label, so it scrapes one target per pod instead of two; series previously collected through the headless target stop appearing, so check anything keyed on the `service` label.
- The Helm chart's new startup probe stops the kubelet killing a pod that is still booting, allowing 295s (`periodSeconds: 5`, `failureThreshold: 60`) where the liveness settings allowed 50. It fires immediately, so a fast boot goes live sooner than before, not later — and it is not limited to auto-start, since the database connect retry alone can consume 30 of the old 50 seconds.
- A Helm upgrade that changes only `env` or `secretEnv` now restarts the pod through ConfigMap and Secret checksums, so the new configuration reaches the running container. With `existingSecret` set the chart renders no Secret, so that path still needs `kubectl rollout restart`; `values.yaml` notes what publishing the Secret checksum as a pod annotation means.
diff --git a/sdk/go/groups.go b/sdk/go/groups.go
index 151c95bf0..677316949 100644
--- a/sdk/go/groups.go
+++ b/sdk/go/groups.go
@@ -231,9 +231,13 @@ func (s *GroupsService) RejectMembershipRequests(
func (s *GroupsService) membershipRequestAction(
ctx context.Context, sessionID, groupID, verb string, participants []string,
) (*ParticipantsResult, error) {
- body := MembershipRequestActionRequest{}
+ // A nil slice means "every pending request", which the gateway reads from the ABSENCE of the
+ // key — `null` is not absence there, so the bodyless case sends an empty object rather than the
+ // struct. A non-nil slice always sends the key, empty included, so naming nobody stays a 400
+ // instead of collapsing into naming everybody.
+ var body any = struct{}{}
if participants != nil {
- body.Participants = participants
+ body = MembershipRequestActionRequest{Participants: participants}
}
var out ParticipantsResult
err := s.client.do(
diff --git a/sdk/go/membership_request_test.go b/sdk/go/membership_request_test.go
new file mode 100644
index 000000000..f10fb8f92
--- /dev/null
+++ b/sdk/go/membership_request_test.go
@@ -0,0 +1,38 @@
+package openwa
+
+import (
+ "context"
+ "testing"
+)
+
+// Omitting `participants` tells the gateway to act on EVERY pending join request, so the empty
+// slice and the nil slice must not reach the wire as the same body. `membershipRequestAction`
+// already draws that line (`if participants != nil`), and every other client keys on null rather
+// than emptiness: the JavaScript, Python and PHP clients send `{"participants": []}` for an empty
+// list and the gateway answers 400 (`@ArrayNotEmpty`). An `omitempty` tag would erase the
+// distinction after the check had made it, turning "approve nobody" into "approve everybody" —
+// silently, and irreversibly for the group.
+func TestMembershipRequestActionDistinguishesEmptyFromOmitted(t *testing.T) {
+ ctx := context.Background()
+
+ for _, tc := range []struct {
+ name string
+ participants []string
+ wantBody string
+ }{
+ {"nil acts on every pending request", nil, `{}`},
+ {"empty slice names nobody", []string{}, `{"participants":[]}`},
+ {"one id names that id", []string{"[email protected]"}, `{"participants":["[email protected]"]}`},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ rt := &recordTransport{status: 200, body: `{}`}
+ c := newTestClient(t, rt)
+ if _, err := c.Groups.ApproveMembershipRequests(ctx, "s1", "g1", tc.participants); err != nil {
+ t.Fatalf("ApproveMembershipRequests: %v", err)
+ }
+ if got := string(rt.lastRaw); got != tc.wantBody {
+ t.Errorf("body = %s, want %s", got, tc.wantBody)
+ }
+ })
+ }
+}
diff --git a/sdk/go/types_group.go b/sdk/go/types_group.go
index b87120e38..7218383c2 100644
--- a/sdk/go/types_group.go
+++ b/sdk/go/types_group.go
@@ -36,10 +36,16 @@ type GroupMembershipRequest struct {
RequestedAt float64 `json:"requestedAt,omitempty"`
}
-// MembershipRequestActionRequest is the body for approving or rejecting join requests. An empty
-// Participants slice acts on every pending request.
+// MembershipRequestActionRequest names the requesters to approve or reject. Acting on every pending
+// request is expressed by sending no body field at all, which membershipRequestAction does with an
+// empty body — not by this struct.
+//
+// No `omitempty`: it drops an empty slice as readily as a nil one, so "approve nobody" would reach
+// the gateway as the bodyless "approve everybody". The other four clients key on null rather than
+// emptiness and send `{"participants": []}` for an empty list, which the gateway rejects with 400;
+// the tag made Go the only client where that input silently admitted every pending requester.
type MembershipRequestActionRequest struct {
- Participants []string `json:"participants,omitempty"`
+ Participants []string `json:"participants"`
}
// GroupInfo is the full group detail.