@@ -150,14 +150,16 @@ class WebpushConfig(object):
150
150
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
151
151
strings. When specified, overrides any data fields set via ``Message.data``.
152
152
notification: A ``messaging.WebpushNotification`` to be included in the message (optional).
153
+ fcm_options: A ``messaging.WebpushFcmOptions`` to be included in the messsage (optional).
153
154
154
155
.. _Webpush Specification: https://tools.ietf.org/html/rfc8030#section-5
155
156
"""
156
157
157
- def __init__ (self , headers = None , data = None , notification = None ):
158
+ def __init__ (self , headers = None , data = None , notification = None , fcm_options = None ):
158
159
self .headers = headers
159
160
self .data = data
160
161
self .notification = notification
162
+ self .fcm_options = fcm_options
161
163
162
164
163
165
class WebpushNotificationAction (object ):
@@ -232,6 +234,18 @@ def __init__(self, title=None, body=None, icon=None, actions=None, badge=None, d
232
234
self .custom_data = custom_data
233
235
234
236
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
+
235
249
class APNSConfig (object ):
236
250
"""APNS-specific options that can be included in a message.
237
251
@@ -503,7 +517,7 @@ def encode_android_notification(cls, notification):
503
517
504
518
@classmethod
505
519
def encode_webpush (cls , webpush ):
506
- """Encodes an WebpushConfig instance into JSON."""
520
+ """Encodes a WebpushConfig instance into JSON."""
507
521
if webpush is None :
508
522
return None
509
523
if not isinstance (webpush , WebpushConfig ):
@@ -514,12 +528,13 @@ def encode_webpush(cls, webpush):
514
528
'headers' : _Validators .check_string_dict (
515
529
'WebpushConfig.headers' , webpush .headers ),
516
530
'notification' : cls .encode_webpush_notification (webpush .notification ),
531
+ 'fcmOptions' : cls .encode_webpush_fcm_options (webpush .fcm_options ),
517
532
}
518
533
return cls .remove_null_values (result )
519
534
520
535
@classmethod
521
536
def encode_webpush_notification (cls , notification ):
522
- """Encodes an WebpushNotification instance into JSON."""
537
+ """Encodes a WebpushNotification instance into JSON."""
523
538
if notification is None :
524
539
return None
525
540
if not isinstance (notification , WebpushNotification ):
@@ -588,6 +603,20 @@ def encode_webpush_notification_actions(cls, actions):
588
603
results .append (cls .remove_null_values (result ))
589
604
return results
590
605
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
+
591
620
@classmethod
592
621
def encode_apns (cls , apns ):
593
622
"""Encodes an APNSConfig instance into JSON."""
0 commit comments