@@ -150,14 +150,16 @@ class WebpushConfig(object):
150150 data: A dictionary of data fields (optional). All keys and values in the dictionary must be
151151 strings. When specified, overrides any data fields set via ``Message.data``.
152152 notification: A ``messaging.WebpushNotification`` to be included in the message (optional).
153+ fcm_options: A ``messaging.WebpushFcmOptions`` to be included in the messsage (optional).
153154
154155 .. _Webpush Specification: https://tools.ietf.org/html/rfc8030#section-5
155156 """
156157
157- def __init__ (self , headers = None , data = None , notification = None ):
158+ def __init__ (self , headers = None , data = None , notification = None , fcm_options = None ):
158159 self .headers = headers
159160 self .data = data
160161 self .notification = notification
162+ self .fcm_options = fcm_options
161163
162164
163165class WebpushNotificationAction (object ):
@@ -232,6 +234,18 @@ def __init__(self, title=None, body=None, icon=None, actions=None, badge=None, d
232234 self .custom_data = custom_data
233235
234236
237+ class WebpushFcmOptions (object ):
238+ """Options for features provided by the FCM SDK for Web.
239+
240+ Args:
241+ link: The link to open when the user clicks on the notification. Must be an HTTPS URL
242+ (optional).
243+ """
244+
245+ def __init__ (self , link = None ):
246+ self .link = link
247+
248+
235249class APNSConfig (object ):
236250 """APNS-specific options that can be included in a message.
237251
@@ -503,7 +517,7 @@ def encode_android_notification(cls, notification):
503517
504518 @classmethod
505519 def encode_webpush (cls , webpush ):
506- """Encodes an WebpushConfig instance into JSON."""
520+ """Encodes a WebpushConfig instance into JSON."""
507521 if webpush is None :
508522 return None
509523 if not isinstance (webpush , WebpushConfig ):
@@ -514,12 +528,13 @@ def encode_webpush(cls, webpush):
514528 'headers' : _Validators .check_string_dict (
515529 'WebpushConfig.headers' , webpush .headers ),
516530 'notification' : cls .encode_webpush_notification (webpush .notification ),
531+ 'fcmOptions' : cls .encode_webpush_fcm_options (webpush .fcm_options ),
517532 }
518533 return cls .remove_null_values (result )
519534
520535 @classmethod
521536 def encode_webpush_notification (cls , notification ):
522- """Encodes an WebpushNotification instance into JSON."""
537+ """Encodes a WebpushNotification instance into JSON."""
523538 if notification is None :
524539 return None
525540 if not isinstance (notification , WebpushNotification ):
@@ -588,6 +603,20 @@ def encode_webpush_notification_actions(cls, actions):
588603 results .append (cls .remove_null_values (result ))
589604 return results
590605
606+ @classmethod
607+ def encode_webpush_fcm_options (cls , options ):
608+ """Encodes a WebpushFcmOptions instance into JSON."""
609+ if options is None :
610+ return None
611+ result = {
612+ 'link' : _Validators .check_string ('WebpushConfig.fcm_options.link' , options .link ),
613+ }
614+ result = cls .remove_null_values (result )
615+ link = result .get ('link' )
616+ if link is not None and not link .startswith ('https://' ):
617+ raise ValueError ('WebpushFcmOptions.link must be a HTTPS URL.' )
618+ return result
619+
591620 @classmethod
592621 def encode_apns (cls , apns ):
593622 """Encodes an APNSConfig instance into JSON."""
0 commit comments