WebPushElixir (web_push_elixir v0.8.0)
Copy MarkdownModule to send web push notifications with an encrypted payload.
Summary
Functions
Sends a web push notification with an encrypted payload.
Functions
Sends a web push notification with an encrypted payload.
Arguments
subscription- the subscription JSON string received from the clientmessage- the message string to sendopts- Optional message options, currently:ttl: time to live in seconds if the client is disconnected, defaults to 60 secondsurgency: Urgency of the message, one of::very-low,:low,:normal,:hightopic: a string with a topic, that is used to replace previous same topic notifications
Examples
case WebPushElixir.send_notification(subscription, "Hello!") do
{:ok, _response} ->
:ok
{:error, :expired} ->
Repo.delete(subscription)
{:error, {:http_error, status, body}} ->
Logger.error("HTTP error #{status}: #{body}")
endReturn Values
{:ok, response}- notification sent successfully (HTTP 200-202){:error, :expired}- subscription expired/not found (HTTP 404 or 410){:error, {:http_error, status, body}}- HTTP error from push service