Coder Social home page Coder Social logo

web-push-libs / web-push-elixir Goto Github PK

View Code? Open in Web Editor NEW

This project forked from midarrlabs/web-push-elixir

2.0 2.0 0.0 51 KB

Simple web push library for Elixir

Home Page: https://hexdocs.pm/web_push_elixir

License: MIT License

JavaScript 9.38% Elixir 83.81% HTML 6.81%

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.2.0"}
  ]
end
  1. Run mix command to generate your Vapid public and private keys:
mix generate.vapid.keys
  1. Set environment variables for your generated keys:
environment:
  - VAPID_PUBLIC_KEY=someVapidPublicKey
  - VAPID_PRIVATE_KEY=someVapidPrivateKey
  - VAPID_SUBJECT=mailto:[email protected]

Usage

WebPushElixir provides a simple send_notification/2 function that accepts 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

truechazza avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.