Hi everyone,
I’m Emmanuel Katto, currently working on a chat application using the WhatsApp Business API with Frappe as the backend. All messages are logged in Frappe, and the frontend (Android app) displays these messages. At the moment, I’m using frappe.publish_realtime
to broadcast new message events to the Frappe frontend with the help of frappe.realtime.on
. However, I now need to push the same events to my Android app.
I’d love some advice on how to send real-time events from Frappe to the Android app efficiently. Should I continue using frappe.publish_realtime
, or is there a better method to send the data to my Android app?
Here’s a snippet of my backend code that works for the Frappe frontend:
def after_insert(self):
try:
wa_team = self.whatsapp_team
user = frappe.db.get_value(“WhatsApp Team”, wa_team, “user”)
message_data = {
"name": self.name,
"type": "Incoming",
"from": getattr(self, "from"),
"contact": self.contact,
"message": self.message,
"creation": self.creation,
}
frappe.publish_realtime(
event="new_whatsapp_message",
message={"message": message_data, "user": user},
doctype="WhatsApp Message",
docname=self.name,
user=user,
after_commit=True,
)
except Exception as e:
frappe.log_error(frappe.get_traceback(), "Socket Error")
Any suggestions or ideas on how to achieve this would be greatly appreciated!
Regards
Emmanuel Katto