WebPush (web_push v0.1.0)

Copy Markdown View Source

Web Push sender: encrypts a JSON payload with aes128gcm (WebPush.Encryption), signs a VAPID JWT (WebPush.Vapid), and POSTs the binary body to the subscription's push service endpoint via Finch.

This is a raw library: it starts no processes. The host application must supervise a Finch pool and tell WebPush its name:

# in your application.ex
children = [
  {Finch, name: MyApp.WebPushFinch}
]

# in config
config :web_push, finch: MyApp.WebPushFinch

The pool name can also be passed per call via the :finch option.

Return values

  • :ok: push service accepted (HTTP 200/201/202/204)
  • {:error, :gone}: subscription no longer valid (404/410); the caller should delete the stored subscription
  • {:error, term}: transport failure or unexpected status

Summary

Functions

Sends payload (JSON-encoded) to subscription.

Types

send_result()

@type send_result() :: :ok | {:error, :gone} | {:error, term()}

Functions

send(sub, payload, opts \\ [])

@spec send(WebPush.Subscription.t(), map(), keyword()) :: send_result()

Sends payload (JSON-encoded) to subscription.

Options

  • :ttl: seconds the push service may hold the message (default 86400)
  • :urgency: "very-low" | "low" | "normal" | "high" (default "normal")

  • :topic: URL-safe string ≤ 32 chars; lets the push service collapse pending messages with the same topic into the latest one
  • :finch: Finch pool name, overrides config :web_push, :finch