Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateVAPIDKeys() (privateKey, publicKey string, err error)
- func New() supervisor.Pluggable
- func NewMessageParams() m.Attributes
- func NewSettings() m.Attributes
- func SendNotification(message []byte, s *m.Subscription, options *Options) (int, []byte, error)
- func SendNotificationWithContext(ctx context.Context, message []byte, s *m.Subscription, options *Options) (code int, body []byte, err error)
- type EventAddWebPushSubscription
- type EventGetUserDevices
- type EventGetWebPushPublicKey
- type EventNewWebPushPublicKey
- type EventUserDevices
- type Notification
- type Options
- type Urgency
Constants ¶
const ( // Name ... Name = "webpush" AttrTitle = "title" AttrUserIDS = "userIDS" AttrBody = "body" AttrPublicKey = "public_key" AttrPrivateKey = "private_key" TopicPluginWebpush = "system/plugins/webpush" Version = "0.0.1" )
const MaxRecordSize uint32 = 4096
Variables ¶
var ErrMaxPadExceeded = errors.New("payload has exceeded the maximum length")
var F embed.FS
Functions ¶
func GenerateVAPIDKeys ¶
GenerateVAPIDKeys will create a private and public VAPID key pair
func SendNotification ¶
SendNotification calls SendNotificationWithContext with default context for backwards-compatibility
func SendNotificationWithContext ¶
func SendNotificationWithContext(ctx context.Context, message []byte, s *m.Subscription, options *Options) (code int, body []byte, err error)
SendNotificationWithContext sends a push notification to a subscription's endpoint Message Encryption for Web Push, and VAPID protocols. FOR MORE INFORMATION SEE RFC8291: https://datatracker.ietf.org/doc/rfc8291
Types ¶
type EventAddWebPushSubscription ¶
type EventAddWebPushSubscription struct { UserID int64 `json:"user_id"` SessionID string `json:"session_id"` Subscription *m.Subscription `json:"subscription"` }
EventAddWebPushSubscription ...
type EventGetUserDevices ¶ added in v0.17.0
type EventGetUserDevices struct { UserID int64 `json:"user_id,omitempty"` SessionID string `json:"session_id"` }
EventGetUserDevices ...
type EventGetWebPushPublicKey ¶
type EventGetWebPushPublicKey struct { UserID int64 `json:"user_id,omitempty"` SessionID string `json:"session_id"` }
EventGetWebPushPublicKey ...
type EventNewWebPushPublicKey ¶
type EventNewWebPushPublicKey struct { UserID int64 `json:"user_id,omitempty"` SessionID string `json:"session_id"` PublicKey string `json:"public_key"` }
EventNewWebPushPublicKey ...
type EventUserDevices ¶ added in v0.17.0
type EventUserDevices struct { UserID int64 `json:"user_id,omitempty"` SessionID string `json:"session_id"` Subscriptions []*m.Subscription `json:"subscription"` }
EventUserDevices ...
type Notification ¶
type Notification struct {
Title string `json:"title"`
}
type Options ¶
type Options struct { Crawler web.Crawler // Will replace with *http.Client by default if not included RecordSize uint32 // Limit the record size Subscriber string // Sub in VAPID JWT token Topic string // Set the Topic header to collapse a pending messages (Optional) TTL int // Set the TTL on the endpoint POST request Urgency Urgency // Set the Urgency header to change a message priority (Optional) VAPIDPublicKey string // VAPID public key, passed in VAPID Authorization header VAPIDPrivateKey string // VAPID private key, used to sign VAPID JWT token }
Options are config and extra params needed to send a notification
type Urgency ¶
type Urgency string
Urgency indicates to the push service how important a message is to the user. This can be used by the push service to help conserve the battery life of a user's device by only waking up for important messages when battery is low.
const ( // UrgencyVeryLow requires device state: on power and Wi-Fi UrgencyVeryLow Urgency = "very-low" // UrgencyLow requires device state: on either power or Wi-Fi UrgencyLow Urgency = "low" // UrgencyNormal excludes device state: low battery UrgencyNormal Urgency = "normal" // UrgencyHigh admits device state: low battery UrgencyHigh Urgency = "high" )