Skip to content

Commit

Permalink
Add try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoMoreta committed Mar 18, 2024
1 parent 699a8d7 commit 2953f2f
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions helpers/fcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,30 @@ def broadcast_notification(node_shortname=None, data=None, event=NotificationEve
'''
logger.info("Sending FCM broadcast...")

data = data or {}
data["event"] = str(event.title)

if not body and not title:
silent = True
if title and silent:
data['title'] = title
if body and silent:
data['message'] = body

topic = node_shortname + "_" + event.prefix

if silent:
result = FCMDevice.send_topic_message(
Message(data=data),
topic
)
else:
result = FCMDevice.send_topic_message(
Message(notification=Notification(title=title, body=body, image=image), data=data),
topic
)
try:
data = data or {}
data["event"] = str(event.title)

if not body and not title:
silent = True
if title and silent:
data['title'] = title
if body and silent:
data['message'] = body

topic = node_shortname + "_" + event.prefix

if silent:
result = FCMDevice.send_topic_message(
Message(data=data),
topic
)
else:
result = FCMDevice.send_topic_message(
Message(notification=Notification(title=title, body=body, image=image), data=data),
topic
)
except Exception as e:
logger.error(e)

logger.info(f"FCM Broadcast sent: {result}")

0 comments on commit 2953f2f

Please sign in to comment.