From 2b543fa47c614c5b31d237567ae6f4c553b156d0 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 24 Dec 2021 10:28:08 +0700 Subject: [PATCH] support webpush with link --- model.go | 3 +++ notification.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/model.go b/model.go index 0746e3d..0330e3f 100644 --- a/model.go +++ b/model.go @@ -17,6 +17,7 @@ type PushRequest struct { Label string `json:"label,omitempty"` Category string `json:"category,omitempty"` Sound *Sound `json:"sound,omitempty"` + Link string `json:"link"` // for webpush } // Sound ... @@ -31,6 +32,7 @@ type PushResponse struct { } type pushRequest struct { + Version string `json:"version"` APIKey string `json:"apiKey"` Title string `json:"title"` Body string `json:"body"` @@ -41,6 +43,7 @@ type pushRequest struct { Label string `json:"label"` Category string `json:"category"` Sound *Sound `json:"sound,omitempty"` + Link string `json:"link"` } // Query ... diff --git a/notification.go b/notification.go index cc38cb0..b46d0ee 100644 --- a/notification.go +++ b/notification.go @@ -8,6 +8,9 @@ import ( "github.com/Selly-Modules/natsio" ) +// version specify current version of client +const version = "1.0.2" + const ( SendByTopic = "topic" SendByUsers = "users" @@ -53,6 +56,7 @@ func NewClient(cfg Config) (*Client, error) { // PushToUsers push notification to list user id func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) { p := pushRequest{ + Version: version, APIKey: c.Config.APIKey, Title: payload.Title, Body: payload.Body, @@ -62,6 +66,7 @@ func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) Label: payload.Label, Category: payload.Category, Sound: payload.Sound, + Link: payload.Link, } msg, err := c.natsServer.Request(SubjectPushNotification, toBytes(p)) if err != nil {