Giter VIP home page Giter VIP logo

django-webpush-demo's Introduction

django-webpush-demo

This is a django server using jazzband's django-push-notifications (https://github.com/jazzband/django-push-notifications), Django REST framework and Web-push-libs modules implementation of the Open Standard for Push API with VAPID (https://github.com/web-push-libs).

One nice features is the ability to store the user response when interactif with the call-to-actions of the Push notification; yep, did you know that a Push notification can display various CTAs ?

It's compatible with any browser supporting native push notifications with the Push API and Service workers (https://developer.mozilla.org/fr/docs/Web/API/Push_API)

More important source-code is :

  • webpush.js and service-worker.js: the client-side code. Notifications are displayed with an default icon, two action buttons (OK, forget), and a click handler opening/focusing the browser on the URL carried by the notification data.
  • webpush/urls.py: the server's API
  • webpush/management/commands/send_webpush.py: server's cron-job to send the pending notifications

How-to configure VAPID

  • After cloning this repository, please install the python environment
    cd django-webpush-demo
    virtualenv .venv --python=python3
    source .venv/bin/activate
    pip install -r requirements.txt
  • Create a temporary file (claim.json) to create your signing keys:
   {
     "sub": "mailto: [email protected]",
     "aud": "https://fcm.googleapis.com"
   }
  • Generate client public key (applicationServerKey) and public and private keys
     vapid --applicationServerKey

[output]

       Application Server Key = BEFuGfKKEFp-kEB...JlkA34llWF0xHya70

Install and run the Django server

Configure Django settings:

  • Create your own local_settings.py next to settings.py, and add Application Server Key to PUSH_NOTIFICATIONS_SETTINGS['APP_SERVER_KEY']
  • Modify the key WP_CLAIMS in settings.py : "sub" with the same email used in the file claim.json. Do not add the "aud" key, because the push servers could be Mozilla's or Google's, and django-push-notifications takes care of that.

Launch it !

    python manage.py migrate
    python manage.py createsuperuser
    python manage.py runserver

Push !

    python manage.py send_webpush
  
  Found a device id =  8 to push the notification id = 1

More...

Deployment.

You need HTTPs to use service workers on your server. We provide everything in the etc directory to deploy on Debian 10, with python 3.7, uWSGI, systemd, Nginx and Certbot LetsEncrypt. Please read the instructions at :

TODO

  • UI obviously
  • Better documentation
  • Tests !
  • Replace the booleans is read and is sent (read previous section) Store a timestamp when sending the notification, store a timestamp when receiving the callback when the user clicks on an action button on the push notification (OK or Forget).

django-webpush-demo's People

Contributors

elishowk avatar

Watchers

James Cloos 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.