Web Push Elixir

Simple web push library for Elixir.

GitHub Workflow Status (with event)codecov

Prerequisities

Installation

  1. Add web_push_elixir to your list of dependencies in mix.exs:
def deps do
[
{:web_push_elixir, "~> 0.1.0"}
]
end
  1. Run mix command to generate your Vapid public and private keys:
mix generate.vapid.keys
  1. Set your environment variables for your keys:
environment:
- VAPID_PUBLIC_KEY=someVapidPublicKey
- VAPID_PRIVATE_KEY=someVapidPrivateKey
- VAPID_SUBJECT=mailto:admin@email.com

Usage

WebPushElixir provides a simple public API send_notification/2 that accepts 2 arguments:

subscription = '{"endpoint":"https://some-push-service","keys":{"p256dh":"BNcRdreALRFXTkOOUHK1EtK2wtaz5Ry4YfYCA_0QTpQtUbVlUls0VJXg7A8u-Ts1XbjhazAkj7I99e8QcYP7DkM=","auth":"tBHItJI5svbpez7KI4CCXg=="}}'
message = "Some message"
WebPushElixir.send_notification(subscription, message)

For more information on how to subscribe a client, permission UX and more - have a look at https://web.dev/notifications/

Credits

Heavily inspired by elixir-web-push-encryption