# Web Push Elixir
Simple web push library for Elixir.

[](http://codecov.io/gh/midarrlabs/web-push-elixir)
## Prerequisities
* Elixir 1.15, OTP 24 / 25 / 26
## Installation
1. Add `web_push_elixir` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:web_push_elixir, "~> 0.1.0"}
]
end
```
2. Run mix command to generate your Vapid public and private keys:
```commandline
mix generate.vapid.keys
```
3. Set your environment variables for your keys:
```yaml
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`: is the subscription information received from the client.
* `message`: is a message string.
```elixir
subscription = '{"endpoint":"http://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 [http://web.dev/notifications/](http://web.dev/notifications/)
## Credits
Heavily inspired by [elixir-web-push-encryption](http://github.com/danhper/elixir-web-push-encryption)