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"`
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 ...

View File

@ -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 {