How to enable push notification on local setup
For frappe cloud setup there is relay server setting, but for local setup ?
anyone have enabled push notifications
How to enable push notification on local setup
For frappe cloud setup there is relay server setting, but for local setup ?
anyone have enabled push notifications
socketio
library, which Frappe already uses for real-time communication. In a local setup, you’ll need to make sure that the WebSocket server is running and accessible.socketio.js
configuration to point to your local WebSocket server.site_config.json
of your Frappe site, add or update the websocket_url
entry to point to your local server. For example:json
Copy code
{
"websocket_url": "http://localhost:3000"
}
frappe-bench
folder, you might need to adjust some settings related to redis
and socketio
in the Procfile
. Ensure that the services are correctly configured to run locally.socketio
events are correctly configured and emitted from the server-side Python code.frappe.socketio
functions.python
Copy code
import frappe
@frappe.whitelist(allow_guest=True)
def notify_user(user, message):
frappe.publish_realtime(event='msgprint', message=message, user=user)
javascript
Copy code
frappe.realtime.on('msgprint', function(message) {
frappe.msgprint(message);
});
Another Way Is
erpnext_fcm
.bench get-app https://github.com/tridz-dev/erpnext_fcm
bench install-app erpnext_fcm
Here’s an example of how you can send a notification from a server-side script:
Python
import frappe
from frappe.core.doctype.notification_log.notification_log import enqueue_create_notification
def send_push_notification(user, title, message):
notification_doc = {
'type': 'Alert',
'document_type': 'User',
'document_name': user,
'subject': title,
'from_user': frappe.session.user,
'email_content': message
}
enqueue_create_notification(notification_doc)
# Example usage
send_push_notification('user@example.com', 'Test Notification', 'This is a test push notification.')
Thank You @Abhishek_Chougule
I will try First method and my socketio is running correctly but what changes need to be done in procfile for setup ?
Procfile Configuration:
Procfile
:redis_socketio: redis-server config/redis_socketio.conf
socketio: /usr/bin/node apps/frappe/socketio.js
Adjust Paths if Needed:
node
if it differs (e.g., /usr/local/bin/node
).Restart Bench:
bench restart
Check Logs:
tail -f logs/socketio.error.log
tail -f logs/redis_socketio.error.log
I tried, but not working, I have to mention one thing i have one chat app which running on 3000 port so is there any problem with this ?
Device IDs (also known as registration tokens) are unique identifiers generated by Firebase Cloud Messaging (FCM) when a user subscribes to notifications. These can be obtained:
FirebaseInstanceId.getInstance().getToken()
.messaging.getToken()
in your web app.Store these tokens in the User Device Doctype in ERPNext to send targeted push notifications to users’ devices.
It’s pretty straightforward. Thanks for that.
Since Legacy Cloud messaging API is disabled, how to obtain Server Key for the new option Firebase Cloud Messaging API? Is there any other way to do so?