This repo was created to enable push notifications for Frappe Apps such as Raven.
To be able to run this application, you will need to do the following:
- Clone this project and create a virtual environment
python -m venv env
- Install all requirements
pip install -r requirements.txt
- Create a Firebase Project & get Service Account credentials Link
- Run this command on the shell
export GOOGLE_APPLICATION_CREDENTIALS="/home/frappe/relay-server/{service-account-file_name}.json"
- Follow Register you app under Step 1 given in the Firebase documentation and obtain the
FIREBASE_CONFIG
JSON object. Save it tomy_secrets.py
. - Follow this StackOverflow Link to generate a VAPID key. Save it to
my_secrets.py
- Generate
API_KEY
&API_SECRET
and add theAPI_SECRET
value to themy_secrets.py
. - Finally, your
my_secrets.py
should like this
API_SECRET = 'tIUAGguQH-xajbkcjsd-lsd'
VAPID_PUBLIC_KEY = "Bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
FIREBASE_CONFIG = {
"apiKey": "AIzaSyC3UVxbCkUv3l4PpyWkQZGEuwOds76sdUgk0",
"authDomain": "xxxxxxxx-frappe.firebaseapp.com",
"projectId": "xxxxxxxxx-frappe",
"storageBucket": "xxxxxxxxx-frappe.appspot.com",
"messagingSenderId": "815115xxx703",
"appId": "1:815115xxx703:web:e89fcdadfcf8df09e4852",
"measurementId": "G-XXXXXXXXXG"
}
- Change the
USER_DEVICE_MAP
key values to{project_name}_{site_name}
whereproject_name
could beraven
orhrms
&site_name
as your site name while setting up the Frappe bench. - Run the application
- Add the
API_SECRET
&API_KEY
in ERPNext Push Notification settings and then enable the Push Notification Relay option.
gunicorn app:app -c gunicorn.conf.py
- Create a Systemd service file at
/etc/systemd/system/push-relay.service
and copy the following and replace the paths/filenames accordingly :
# /etc/systemd/system/push-relay.service
[Unit]
Description=Gunicorn instance to server Frappe Push Notification Relay Server
After=network.target
[Service]
User=frappe
Group=www-data
WorkingDirectory=/home/frappe/relay-server
Environment="PATH=/home/frappe/relay-server/env/bin"
Environment="GOOGLE_APPLICATION_CREDENTIALS=/home/frappe/relay-server/{service-account-file_name}.json"
ExecStart=/home/frappe/relay-server/env/bin/gunicorn app:app -c /home/frappe/relay-server/gunicorn.conf.py
[Install]
WantedBy=multi-user.target
- Run the following commands
sudo systemctl daemon-reload sudo systemctl enable push-relay sudo systemctl start push-relay
-
In case you are running Frappe instance on localhost, then perform the following steps to avoid CORS issues
-
Run the following commands
pip install flask-cors
-
app.py [add line 8 & 10]
7 from my_secrets import API_SECRET, FIREBASE_CONFIG, VAPID_PUBLIC_KEY, BADGE_ICON + 8 from flask_cors import CORS 9 app = Flask(__name__) + 10 CORS(app, resources={r"/*": {"origins": "*"}}) # This will allow all origins 11 firebase_app = firebase_admin.initialize_app() 12 basic_auth = HTTPBasicAuth()
-
firebase_admin/_messaging_encoder.py [ comment line : 507, 508 ]
506 link = result.get('link') - 507 # if link is not None and not link.startswith('https://'): - 508 # raise ValueError('WebpushFCMOptio ns.link must be a HTTPS URL.') 509 return result
-
Restart bench and gunicorn server
-