support webpush with link

This commit is contained in:
Sinh 2021-12-24 10:28:08 +07:00
parent 4b7991bbbf
commit 2b543fa47c
2 changed files with 8 additions and 0 deletions

View File

@ -17,6 +17,7 @@ type PushRequest struct {
Label string `json:"label,omitempty"` Label string `json:"label,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`
Sound *Sound `json:"sound,omitempty"` Sound *Sound `json:"sound,omitempty"`
Link string `json:"link"` // for webpush
} }
// Sound ... // Sound ...
@ -31,6 +32,7 @@ type PushResponse struct {
} }
type pushRequest struct { type pushRequest struct {
Version string `json:"version"`
APIKey string `json:"apiKey"` APIKey string `json:"apiKey"`
Title string `json:"title"` Title string `json:"title"`
Body string `json:"body"` Body string `json:"body"`
@ -41,6 +43,7 @@ type pushRequest struct {
Label string `json:"label"` Label string `json:"label"`
Category string `json:"category"` Category string `json:"category"`
Sound *Sound `json:"sound,omitempty"` Sound *Sound `json:"sound,omitempty"`
Link string `json:"link"`
} }
// Query ... // Query ...

View File

@ -8,6 +8,9 @@ import (
"github.com/Selly-Modules/natsio" "github.com/Selly-Modules/natsio"
) )
// version specify current version of client
const version = "1.0.2"
const ( const (
SendByTopic = "topic" SendByTopic = "topic"
SendByUsers = "users" SendByUsers = "users"
@ -53,6 +56,7 @@ func NewClient(cfg Config) (*Client, error) {
// PushToUsers push notification to list user id // PushToUsers push notification to list user id
func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) { func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) {
p := pushRequest{ p := pushRequest{
Version: version,
APIKey: c.Config.APIKey, APIKey: c.Config.APIKey,
Title: payload.Title, Title: payload.Title,
Body: payload.Body, Body: payload.Body,
@ -62,6 +66,7 @@ func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error)
Label: payload.Label, Label: payload.Label,
Category: payload.Category, Category: payload.Category,
Sound: payload.Sound, Sound: payload.Sound,
Link: payload.Link,
} }
msg, err := c.natsServer.Request(SubjectPushNotification, toBytes(p)) msg, err := c.natsServer.Request(SubjectPushNotification, toBytes(p))
if err != nil { if err != nil {