Documentation ¶
Overview ¶
Package webpush provides a service for sending messages to viber.
Usage:
package main import ( "context" "log" "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/webpush" ) const vapidPublicKey = "..." // Add a vapidPublicKey const vapidPrivateKey = "..." // Add a vapidPrivateKey func main() { subscription := webpush.Subscription{ Endpoint: "https://your-endpoint", Keys: { Auth: "...", P256dh: "...", }, } webpushSvc := webpush.New(vapidPublicKey, vapidPrivateKey) webpushSvc.AddReceivers(subscription) notifier := notify.NewWithServices(webpushSvc) if err := notifier.Send(context.Background(), "TEST", "Message using golang notifier library"); err != nil { log.Fatalf("notifier.Send() failed: %s", err.Error()) } log.Println("Notification sent successfully") }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options = webpush.Options
Options are optional settings for the sending of a message. It's a type alias for webpush.Options.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service encapsulates the webpush notification system along with the internal state
func (*Service) AddReceivers ¶
func (s *Service) AddReceivers(subscriptions ...Subscription)
AddReceivers adds one or more subscriptions to the Service.
func (*Service) Send ¶
Send sends a message to all the webpush subscriptions that have been added to the Service. The subject and message arguments are the subject and message of the messagePayload payload. The context can be used to optionally add options and data to the messagePayload payload. See the WithOptions and WithData functions.
type Subscription ¶
type Subscription = webpush.Subscription
Subscription is a JSON representation of a webpush subscription. It's a type alias for webpush.Subscription.
type Urgency ¶
type Urgency = webpush.Urgency
Urgency indicates the importance of the message. It's a type alias for webpush.Urgency.
var ( // UrgencyVeryLow requires device state: on power and Wi-Fi UrgencyVeryLow Urgency = webpush.UrgencyVeryLow // UrgencyLow requires device state: on either power or Wi-Fi UrgencyLow Urgency = webpush.UrgencyLow // UrgencyNormal excludes device state: low battery UrgencyNormal Urgency = webpush.UrgencyNormal // UrgencyHigh admits device state: low battery UrgencyHigh Urgency = webpush.UrgencyHigh )
These are exposed Urgency constants from the webpush package.