WebpushConfig - chad63e/anvil-firebase GitHub Wiki
WebpushConfig
Class Description
WebpushConfig is an Anvil portable class designed for configuring the web push aspects of Firebase Cloud Messaging (FCM) messages. It allows customization of headers, data, notifications, and FCM-specific options for web push messages.
Attributes
headers (dict, optional): Headers to be included in the web push message.data (dict, optional): Data payload for the web push message.notification (WebpushNotification, optional): Notification configuration specific to web push messages.fcm_options (WebpushFCMOptions, optional): FCM options for the web push message.
Constructor
__init__(self, headers=None, data=None, notification=None, fcm_options=None)
Initializes a new instance of the WebpushConfig class, allowing you to set various parameters for web push messaging.
Parameters:
headers (dict, optional): Custom headers for the web push message.data (dict, optional): Data payload for the message.notification (WebpushNotification, optional): Configuration for the web push notification.fcm_options (WebpushFCMOptions, optional): Options for Firebase Cloud Messaging.
Methods
to_dict()
Converts the WebpushConfig object into a dictionary format for serialization and integration with Firebase SDKs.
Usage Notes
WebpushConfigis essential for tailoring web push messages in Firebase, allowing detailed customization of headers, data, and notification appearance.- As an Anvil portable class, it can be seamlessly used between client and server code in Anvil applications.
- This class provides a comprehensive way to define web push notifications, ensuring they are tailored to specific application requirements and user experiences.
Example
from Firebase.messages import WebpushConfig, WebpushNotification, WebpushFCMOptions
# Creating a web push configuration
webpush_config = WebpushConfig(
headers={"Content-Type": "application/json"},
data={"key1": "value1"},
notification=WebpushNotification(title="New Alert", body="You have a new alert."),
fcm_options=WebpushFCMOptions(link="https://example.com")
)
# Converting the web push config to a dictionary
webpush_config_dict = webpush_config.to_dict()
print(webpush_config_dict)
In this example, WebpushConfig is used to create a detailed configuration for a web push message. This includes custom headers, data payload, notification settings, and FCM options. The to_dict method is then utilized to convert the WebpushConfig object into a dictionary format, ready for use with Firebase Cloud Messaging to deliver customized web push messages.