I succeeded to play popup message to be an pop notification using hooks (using scheduler event), but the problem that this message is disappearing once the user is clicking on any place at the screen and that will let the message to disappear. I used:
frappe.publish_realtime(event=‘msgprint’, message=‘Popup Msg As Test’, user=frappe.session.user,doctype=‘Trip Order’)
I am sure there should be a way to display the message in dialogue box and stay on the screen until user close it or bless on any button related to this message.
The event here doesn’t correspond to the method you want to call from the server/client side, but rather the event that you’ll be passing from the server to the client.
As an example, see the event setup_task in the setup wizard used to execute .js code from .py:
The primary purpose of frappe.publish_realtime() is to call client-side scripts via the server side. So, I think even if you call your .py function via hooks, you can use this functionality to render any .js dialog you want. You can also pass all relevant parameters you may need from .py in the second argument of publish_realtime, like the data passed in the above example.
Thank you @Mohammed_Redha.
My problem with frappe.session.user that is always return Administrator even the logged in user is other than Administrator. Why? What it should normally return?
Also, if I need to notify all the logged in users, what should I pass for user argument in publish_real?
@rahy No, you can read the documentation of that function :
"""Publish real-time updates
:param event: Event name, like `task_progress` etc.
:param message: JSON message object. For async must contain `task_id`
:param room: Room in which to publish update (default entire site)
:param user: Transmit to user
:param doctype: Transmit to doctype, docname
:param docname: Transmit to doctype, docname
:param after_commit: (default False) will emit after current transaction is committed