64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.selly.red/Selly-Modules/natsio"
|
|
|
|
"git.selly.red/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 campaign 111",
|
|
Body: "Notification campaign 11",
|
|
Data: "{}",
|
|
Users: []string{userID},
|
|
Label: "tracking-campaign",
|
|
Category: "campaign",
|
|
})
|
|
if err != nil {
|
|
fmt.Println("Push err: ", err)
|
|
}
|
|
fmt.Println("Request id: ", requestID)
|
|
|
|
unread, err := c.CountUnread(notification.CountUnread{
|
|
User: userID,
|
|
Category: "", // count all if not specify category
|
|
})
|
|
fmt.Println("Count: ", unread, err)
|
|
|
|
res, err := c.Query(notification.Query{
|
|
User: userID,
|
|
Page: 0,
|
|
Limit: 20,
|
|
Category: "", // get all if not specify category
|
|
})
|
|
fmt.Println("Query : ", res, err)
|
|
|
|
unread, err = c.CountUnread(notification.CountUnread{
|
|
User: userID,
|
|
Category: "",
|
|
})
|
|
fmt.Printf("Count: 2 %+v, %v\n", unread, err)
|
|
|
|
err = c.Subscribe("test", []string{
|
|
"eX1gEc7WokSHh-zJ3WR5Hn:APA91bFZDuzkjjFFL6TNpMg0ot93a0wsypWi4aCdm7M2x6AihgjS_QWsbKSFCT4hNhv_d8wKGy-DG6_3e8OlwPiWiJB4R33xLbbUekgxKcfCiiFooIC1E1OE3XWkvUtn4egn8aLG5jqv",
|
|
})
|
|
fmt.Println("Subscribe err: ", err)
|
|
}
|