https://github.com/midarrlabs/web-push-elixir
Simple web push library for Elixir
https://github.com/midarrlabs/web-push-elixir
elixir elixir-lang elixir-library push-notifications web-push web-push-notifications
Last synced: 5 months ago
JSON representation
Simple web push library for Elixir
- Host: GitHub
- URL: https://github.com/midarrlabs/web-push-elixir
- Owner: midarrlabs
- License: mit
- Created: 2023-09-19T05:35:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-28T10:15:10.000Z (8 months ago)
- Last Synced: 2025-06-15T15:25:13.877Z (7 months ago)
- Topics: elixir, elixir-lang, elixir-library, push-notifications, web-push, web-push-notifications
- Language: Elixir
- Homepage: https://hexdocs.pm/web_push_elixir
- Size: 110 KB
- Stars: 24
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Web Push Elixir
Simple web push library for 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.4.0"}
]
end
```
2. Run mix command to generate your Vapid public and private keys:
```commandline
mix generate.vapid.keys
```
3. Set config for your generated keys:
```elixir
config :web_push_elixir,
vapid_public_key: "someVapidPublicKey",
vapid_private_key: "someVapidPrivateKey",
vapid_subject: "mailto:admin@email.com"
```
## Usage
`WebPushElixir` provides a simple `send_notification/2` that takes 2 arguments:
* `subscription`: the subscription information received from the client - [example demo](https://midarrlabs.github.io/web-push-elixir/)
* `message`: the message string.
```elixir
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 - take a look at [https://web.dev/notifications/](https://web.dev/notifications/)
## Run tests
```commandline
mix test
```
## License
Web Push Elixir is open-sourced software licensed under the [MIT license](LICENSE).
## Credits
Heavily inspired by [elixir-web-push-encryption](https://github.com/danhper/elixir-web-push-encryption)