Skip to content

WebpushFCMOptions

chad63e edited this page Jan 29, 2024 · 1 revision

WebpushFCMOptions

Class Description

WebpushFCMOptions is an Anvil portable class specifically designed for configuring web push options in Firebase Cloud Messaging (FCM). It primarily focuses on specifying the action when the user interacts with the notification, such as opening a specific link.

Attributes

  • link (str, optional): A URL to open when the user clicks on the notification. This must be an HTTPS URL.

Constructor

__init__(self, link=None)

Initializes a new instance of the WebpushFCMOptions class, setting the optional link for the notification.

Parameters:

  • link (str, optional): The HTTPS link that should be opened upon the user clicking the notification.

Methods

to_dict()

Converts the WebpushFCMOptions object into a dictionary. This is useful for serialization and integration with Firebase SDKs and APIs.

Usage Notes

  • WebpushFCMOptions is useful for creating web push notifications in Firebase that require specific user interaction, such as opening a link.
  • As an Anvil portable class, it can be passed seamlessly between client and server code in Anvil applications.
  • This class enhances the functionality and user experience of web push notifications by directing users to relevant web pages or resources upon interaction.

Example

from Firebase.messages import WebpushFCMOptions

# Creating Webpush FCM options with a link
webpush_fcm_options = WebpushFCMOptions(link="https://example.com/landing-page")

# Converting the FCM options to a dictionary
webpush_fcm_options_dict = webpush_fcm_options.to_dict()
print(webpush_fcm_options_dict)

In this example, WebpushFCMOptions is instantiated with a specific HTTPS link. The to_dict method is then used to convert the options object into a dictionary format, making it ready to be integrated with Firebase SDKs or other parts of a Firebase application where such options are required. This approach is particularly useful for driving user engagement and directing users to specific web content through notifications.