Quick Guide to bench publish-realtime Command

Hey Frappe community!

I wanted to share a quick guide on using the bench publish-realtime command. This command is incredibly handy for publishing real-time events from the bench, which can be useful for informing users on the desk about important updates or events.

Here’s how it works:

  1. What it Does: The bench publish-realtime command is used to publish real-time events from the bench.

  2. Usage:

    • Usage: bench publish-realtime [OPTIONS] EVENT
    • For example: bench publish-realtime --message "some message" msgprint
    • Replace "some message" with the text you want to send as a real-time message.
  3. How it Works: This command sends the specified message to the msgprint event in Frappe, which is already being listened to. If the socket is working fine, the message will be displayed in Frappe. Otherwise, it won’t.

  4. Custom Events: If you want to send a message to a custom event, make sure you’re listening to that event in the frontend. For example: frappe.realtime.on(event_name, callback).

I find myself referring back to this guide every time I use the command, so I thought I’d share it with you all. Hope you find it helpful too! :sweat_smile:

Feel free to ask if you have any questions or share any tips you have for using this command.

Cheers!

4 Likes

How to setup custom events for a doctype and then getting that same event on a custom react app? I tried implementing publish_realtime within an after_insert hook call, but no events are generated. I am using react and frappe-react-sdk. Any guidance would be appreciated

Could you give me some more information on why you need real-time messages within the after_insert hook? That might help in understanding your use case better

I wanted to enable custom notifications on my custom react application using realtime events from frappe. Is there any other way to do so?