Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk-go): send the idempotency key on a raw path with a query

Yudhi Armyndharisd96a0a83d8d1
diff --git a/sdk/go/client.go b/sdk/go/client.go
index 4464d9b05..2edbbcb64 100644
--- a/sdk/go/client.go
+++ b/sdk/go/client.go
@@ -266,6 +266,9 @@ var idempotentSendSegments = map[string]bool{
// isIdempotentSendPath reports whether path is /api/sessions/{id}/messages/{segment} for one of them.
func isIdempotentSendPath(path string) bool {
+ if i := strings.IndexAny(path, "?#"); i >= 0 {
+ path = path[:i]
+ }
parts := strings.Split(path, "/")
return len(parts) == 6 && parts[1] == "api" && parts[2] == "sessions" && parts[4] == "messages" &&
idempotentSendSegments[parts[5]]
diff --git a/sdk/go/idempotency_scope_test.go b/sdk/go/idempotency_scope_test.go
index 49ad96478..470d5a5b2 100644
--- a/sdk/go/idempotency_scope_test.go
+++ b/sdk/go/idempotency_scope_test.go
@@ -2,6 +2,7 @@ package openwa
import (
"context"
+ "net/url"
"testing"
)
@@ -25,6 +26,27 @@ func TestIdempotencyKeyReachesOnlyRoutesThatHonorIt(t *testing.T) {
{"do on a keyed route", func() error {
return c.Do(ctx, "POST", "/api/sessions/s/messages/send-text", nil, map[string]string{}, nil)
}, "order-1"},
+ {"do with a query in the path", func() error {
+ return c.Do(ctx, "POST", "/api/sessions/s/messages/send-text?x=1", nil, map[string]string{}, nil)
+ }, "order-1"},
+ {"do with a fragment", func() error {
+ return c.Do(ctx, "POST", "/api/sessions/s/messages/send-text#client", nil, map[string]string{}, nil)
+ }, "order-1"},
+ {"do with a query and fragment", func() error {
+ return c.Do(ctx, "POST", "/api/sessions/s/messages/send-text?x=1#client", nil, map[string]string{}, nil)
+ }, "order-1"},
+ {"do with separate query values", func() error {
+ return c.Do(ctx, "POST", "/api/sessions/s/messages/send-text", url.Values{"x": {"1"}}, map[string]string{}, nil)
+ }, "order-1"},
+ {"do on a bulk route with a query", func() error {
+ return c.Do(ctx, "POST", "/api/sessions/s/messages/send-bulk?x=1", nil, map[string]string{}, nil)
+ }, ""},
+ {"do on a product route with a fragment", func() error {
+ return c.Do(ctx, "POST", "/api/sessions/s/messages/send-product#client", nil, map[string]string{}, nil)
+ }, ""},
+ {"do with a non-POST method", func() error {
+ return c.Do(ctx, "GET", "/api/sessions/s/messages/send-text?x=1", nil, nil, nil)
+ }, ""},
{"do on another route", func() error { return c.Do(ctx, "POST", "/api/sessions/s/groups", nil, map[string]string{}, nil) }, ""},
} {
t.Run(tc.name, func(t *testing.T) {