push

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package push delivers integration-bus events to browsers as Web Push notifications (RFC 8030 delivery, RFC 8291 encryption, RFC 8292 VAPID; the wire work is internal/webpush).

Each browser subscription is its own bus subscriber ("webpush:<id>"), not one subscriber fanning out to many browsers. That is what gives a push the same delivery semantics as a Slack post: its own cursor, its own outbox rows keyed by an idempotency key, its own retries and dead letters. A fan-out subscriber would have had to retry the whole event when one phone was offline -- re-notifying every browser that had already shown it.

Index

Constants

This section is empty.

Variables

Kinds are the event kinds a browser can ask to be notified about: the four that mean "a person is needed", which is what a notification on a phone is for. Pinned against integrations.AllKinds by a test.

Functions

func ValidKind

func ValidKind(k string) bool

ValidKind reports whether k is one of Kinds.

Types

type Notifier

type Notifier struct {
	SubscriptionID string
	Subscription   webpush.Subscription
	Events         map[integrations.Kind]bool
	Sender         *webpush.Sender
	// Redact masks credentials in every string that leaves the machine. The
	// payload is end-to-end encrypted to the browser, but it is still shown
	// on a lock screen.
	Redact func(string) string
	// OnResult records each attempt's outcome ("" on success).
	OnResult func(ctx context.Context, errText string)
	// OnGone is called when the push service says the subscription no
	// longer exists; the caller deletes it.
	OnGone func(ctx context.Context)
}

Notifier is the bus subscriber for one browser subscription.

func (*Notifier) Deliver

func (n *Notifier) Deliver(ctx context.Context, ev integrations.Event) error

Deliver implements integrations.Subscriber, mapping push-service answers onto the dispatcher's retry semantics: a dead subscription is permanent (and deleted), a 429's Retry-After is honoured, a 4xx that retrying cannot fix is permanent, anything else is retried with backoff.

func (*Notifier) Name

func (n *Notifier) Name() string

Name implements integrations.Subscriber.

func (*Notifier) Wants

func (n *Notifier) Wants(ev integrations.Event) bool

Wants implements integrations.Subscriber.

type Payload

type Payload struct {
	Title string `json:"title"`
	Body  string `json:"body"`
	// URL is a same-origin path + hash the notification opens. Relative, so
	// it lands on whichever address the browser subscribed from.
	URL  string `json:"url"`
	Tag  string `json:"tag"`
	Kind string `json:"kind"`
}

Payload is the JSON the service worker receives (web/public/sw.js).

func BuildPayload

func BuildPayload(ev integrations.Event, redact func(string) string) Payload

BuildPayload renders ev as a notification.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL