update notification payload and add demo
This commit is contained in:
parent
20b0bccbc2
commit
282a94a2ef
|
@ -0,0 +1,58 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Selly-Modules/natsio"
|
||||
|
||||
"github.com/Selly-Modules/notification"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c, err := notification.NewClient(notification.Config{
|
||||
APIKey: "UWvieSs2erFfhwvl1g8CavEY2V7ouc3",
|
||||
Nats: natsio.Config{
|
||||
URL: "127.0.0.1:4222",
|
||||
User: "",
|
||||
Password: "",
|
||||
TLS: nil,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
userID := "61a499ad8d5770f8872b03d8"
|
||||
requestID, err := c.PushToUsers(notification.PushRequest{
|
||||
Title: "Notification 1",
|
||||
Body: "nats stream view notification",
|
||||
Data: "{}",
|
||||
Users: []string{userID},
|
||||
Label: "tracking-label",
|
||||
Category: "order",
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("Push err: ", err)
|
||||
}
|
||||
fmt.Println("Request id: ", requestID)
|
||||
|
||||
total, err := c.CountUnread(notification.CountUnread{
|
||||
User: userID,
|
||||
Category: "order",
|
||||
})
|
||||
fmt.Println("Count: ", total, err)
|
||||
|
||||
res, err := c.Query(notification.Query{
|
||||
User: userID,
|
||||
Category: "order",
|
||||
Page: 0,
|
||||
Limit: 20,
|
||||
})
|
||||
fmt.Println("Query : ", res, err)
|
||||
|
||||
total, err = c.CountUnread(notification.CountUnread{
|
||||
User: userID,
|
||||
Category: "order",
|
||||
})
|
||||
fmt.Println("Count: 2", total, err)
|
||||
}
|
2
model.go
2
model.go
|
@ -15,6 +15,7 @@ type PushRequest struct {
|
|||
Data string `json:"data"`
|
||||
Users []string `json:"users"`
|
||||
Label string `json:"label"`
|
||||
Category string `json:"category"`
|
||||
}
|
||||
|
||||
// PushResponse ...
|
||||
|
@ -32,6 +33,7 @@ type pushRequest struct {
|
|||
Users []string `json:"users"`
|
||||
Topic string `json:"topic"`
|
||||
Label string `json:"label"`
|
||||
Category string `json:"category"`
|
||||
}
|
||||
|
||||
// Query ...
|
||||
|
|
|
@ -58,6 +58,7 @@ func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error)
|
|||
SendBy: SendByUsers,
|
||||
Users: payload.Users,
|
||||
Label: payload.Label,
|
||||
Category: payload.Category,
|
||||
}
|
||||
msg, err := c.natsServer.Request(SubjectPushNotification, toBytes(p))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue