Git Product home page Git Product logo

web-push-elixir's Introduction

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:[email protected]"

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

web-push-elixir's People

Contributors

dependabot[bot] avatar truechazza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

web-push-elixir's Issues

Add TTL parameter

Allow TTL to be passed in as a parameter, possibly with a default.

Currently fixed to "60" seconds.

config vapid keys does not seem to work

The README suggests you can add vapid keys to config like so:

config :web_push_elixir,
  vapid_public_key: "key",
  vapid_private_key: "key",
  vapid_subject: "mailto:[email protected]"

but this fails at runtime. In the code, it appears to reference env variables direction instead at web_push_elixir.ex:111

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.