Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

midarrlabs/web-push-elixir

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Web Push Elixir

Simple web push library for Elixir

Test Status Code Coverage Hex Version Hex Docs

Prerequisities

  • Elixir 1.15
  • OTP 24 / 25 / 26

Installation

  1. Add web_push_elixir to your list of dependencies in mix.exs:
def deps do
  [
    {:web_push_elixir, "~> 0.4.0"}
  ]
end
  1. Run mix command to generate your Vapid public and private keys:
mix generate.vapid.keys
  1. Set config for your generated keys:
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
  • message: the message string.
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/

Run tests

mix test

License

Web Push Elixir is open-sourced software licensed under the MIT license.

Credits

Heavily inspired by elixir-web-push-encryption

Sponsor this project

 

Contributors 3

  •  
  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.