WebpushNotificationAction - chad63e/anvil-firebase GitHub Wiki
WebpushNotificationAction
Class Description
WebpushNotificationAction is an Anvil portable class designed to define actions for web push notifications in Firebase Cloud Messaging (FCM). It allows specifying details like action, title, and icon for interactive elements in web push notifications.
Attributes
action (str): Specifies the action associated with the notification button or interactive element.title (str): The title or label for the action, typically displayed on the notification button.icon (str, optional): URL of an icon to be displayed alongside the action title on the notification.
Constructor
__init__(self, action, title, icon=None)
Initializes a new instance of the WebpushNotificationAction class, defining an action for a web push notification.
Parameters:
action (str): The identifier for the action.title (str): The text label for the action.icon (str, optional): URL of the icon for the action.
Methods
to_dict()
Converts the WebpushNotificationAction object into a dictionary, which is useful for serialization and integration with Firebase SDKs.
Usage Notes
WebpushNotificationActionis ideal for creating interactive notifications, allowing recipients to take specific actions directly from the notification interface.- As an Anvil portable class, it can be seamlessly used between client and server code in Anvil applications.
- This class enhances the functionality and user experience of web push notifications by adding actionable elements with clear titles and icons.
Example
from Firebase.messages import WebpushNotificationAction
# Creating a Webpush notification action
notification_action = WebpushNotificationAction(
action="view_details",
title="View Details",
icon="https://example.com/icon.png"
)
# Converting the action to a dictionary
notification_action_dict = notification_action.to_dict()
print(notification_action_dict)
In this example, a WebpushNotificationAction is created with a specified action, title, and icon. The to_dict method is then used to convert the action object into a dictionary format, suitable for use with web push notifications in Firebase Cloud Messaging. This approach adds interactive elements to the notifications, enhancing user engagement.