diff --git a/lib/model.go b/lib/model.go index fb776f9..3dd6172 100644 --- a/lib/model.go +++ b/lib/model.go @@ -178,9 +178,13 @@ type SubscribersTopicRequest struct { } type SubscriberNotificationFeedOptions struct { - Page int `queryKey:"page"` - FeedIdentifier string `queryKey:"feedIdentifier"` - Seen bool `queryKey:"seen"` + Page int `queryKey:"page"` + FeedIdentifier string `queryKey:"feedIdentifier"` + Seen bool `queryKey:"seen"` + Payload interface{} `queryKey:"payload"` +} +type Base64Payload struct { + Payload string `queryKey:"payload"` } type SubscriberUnseenCountOptions struct { @@ -260,7 +264,7 @@ type CTA struct { Type string `json:"type"` Action struct { Status string `json:"status"` - Buttons struct { + Buttons []struct { Type string `json:"type"` Content string `json:"content"` ResultContent string `json:"resultContent"` diff --git a/lib/subscribers.go b/lib/subscribers.go index ca7f584..6097acb 100644 --- a/lib/subscribers.go +++ b/lib/subscribers.go @@ -3,6 +3,7 @@ package lib import ( "bytes" "context" + "encoding/base64" "encoding/json" "io" "net/http" @@ -128,6 +129,23 @@ func (s *SubscriberService) GetNotificationFeed(ctx context.Context, subscriberI if opts != nil { queryValues := URL.Query() + if opts.Payload != nil { + var payloadOpts Base64Payload + payloadString, err := json.Marshal(opts.Payload) + if err != nil { + return nil, err + } + opts.Payload = nil + + payloadOpts.Payload = base64.StdEncoding.EncodeToString(payloadString) + params, err := GenerateQueryParamsFromStruct(payloadOpts) + if err != nil { + return nil, err + } + for _, param := range params { + queryValues.Add(param.Key, param.Value) + } + } params, err := GenerateQueryParamsFromStruct(*opts) if err != nil { diff --git a/lib/subscribers_test.go b/lib/subscribers_test.go index 0a18a02..cc09809 100644 --- a/lib/subscribers_test.go +++ b/lib/subscribers_test.go @@ -232,15 +232,19 @@ func TestSubscriberService_GetNotificationFeed_Success(t *testing.T) { page := 1 seen := true feedIdentifier := "feed_identifier" + payload := map[string]interface{}{ + "name": "test", + } opts := lib.SubscriberNotificationFeedOptions{ Page: page, Seen: seen, FeedIdentifier: feedIdentifier, + Payload: payload, } httpServer := createTestServer(t, TestServerOptions[io.Reader, *lib.SubscriberNotificationFeedResponse]{ - expectedURLPath: fmt.Sprintf("/v1/subscribers/%s/notifications/feed?feedIdentifier=%s&page=%s&seen=%s", subscriberID, feedIdentifier, strconv.Itoa(page), strconv.FormatBool(seen)), + expectedURLPath: fmt.Sprintf("/v1/subscribers/%s/notifications/feed?feedIdentifier=%s&page=%s&payload=eyJuYW1lIjoidGVzdCJ9&seen=%s", subscriberID, feedIdentifier, strconv.Itoa(page), strconv.FormatBool(seen)), expectedSentMethod: http.MethodGet, expectedSentBody: http.NoBody, responseStatusCode: http.StatusOK,