2021-12-03 04:58:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-10-10 03:27:52 +00:00
|
|
|
"git.selly.red/Selly-Modules/natsio"
|
2021-12-03 04:58:55 +00:00
|
|
|
|
2022-10-10 03:27:52 +00:00
|
|
|
"git.selly.red/Selly-Modules/notification"
|
2021-12-03 04:58:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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{
|
2022-11-14 08:54:11 +00:00
|
|
|
Title: "Notification campaign 111",
|
|
|
|
Body: "Notification campaign 11",
|
2021-12-03 04:58:55 +00:00
|
|
|
Data: "{}",
|
|
|
|
Users: []string{userID},
|
2022-11-14 08:54:11 +00:00
|
|
|
Label: "tracking-campaign",
|
|
|
|
Category: "campaign",
|
2021-12-03 04:58:55 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Push err: ", err)
|
|
|
|
}
|
|
|
|
fmt.Println("Request id: ", requestID)
|
|
|
|
|
2022-11-14 08:54:11 +00:00
|
|
|
unread, err := c.CountUnread(notification.CountUnread{
|
2021-12-03 04:58:55 +00:00
|
|
|
User: userID,
|
2022-11-14 08:54:11 +00:00
|
|
|
Category: "", // count all if not specify category
|
2021-12-03 04:58:55 +00:00
|
|
|
})
|
2022-11-14 08:54:11 +00:00
|
|
|
fmt.Println("Count: ", unread, err)
|
2021-12-03 04:58:55 +00:00
|
|
|
|
|
|
|
res, err := c.Query(notification.Query{
|
|
|
|
User: userID,
|
|
|
|
Page: 0,
|
|
|
|
Limit: 20,
|
2022-11-14 08:54:11 +00:00
|
|
|
Category: "", // get all if not specify category
|
2021-12-03 04:58:55 +00:00
|
|
|
})
|
|
|
|
fmt.Println("Query : ", res, err)
|
|
|
|
|
2022-11-14 08:54:11 +00:00
|
|
|
unread, err = c.CountUnread(notification.CountUnread{
|
2021-12-03 04:58:55 +00:00
|
|
|
User: userID,
|
2022-11-14 08:54:11 +00:00
|
|
|
Category: "",
|
2021-12-03 04:58:55 +00:00
|
|
|
})
|
2022-11-14 08:54:11 +00:00
|
|
|
fmt.Printf("Count: 2 %+v, %v\n", unread, err)
|
2021-12-06 04:02:29 +00:00
|
|
|
|
|
|
|
err = c.Subscribe("test", []string{
|
|
|
|
"eX1gEc7WokSHh-zJ3WR5Hn:APA91bFZDuzkjjFFL6TNpMg0ot93a0wsypWi4aCdm7M2x6AihgjS_QWsbKSFCT4hNhv_d8wKGy-DG6_3e8OlwPiWiJB4R33xLbbUekgxKcfCiiFooIC1E1OE3XWkvUtn4egn8aLG5jqv",
|
|
|
|
})
|
|
|
|
fmt.Println("Subscribe err: ", err)
|
2021-12-03 04:58:55 +00:00
|
|
|
}
|