@@ -38,7 +38,7 @@ class Message(object):
38
38
android: An instance of ``messaging.AndroidConfig`` (optional).
39
39
webpush: An instance of ``messaging.WebpushConfig`` (optional).
40
40
apns: An instance of ``messaging.ApnsConfig`` (optional).
41
- fcm_options: An instance of ``messaging.FcmOptions `` (optional).
41
+ fcm_options: An instance of ``messaging.FCMOptions `` (optional).
42
42
token: The registration token of the device to which the message should be sent (optional).
43
43
topic: Name of the FCM topic to which the message should be sent (optional). Topic name
44
44
may contain the ``/topics/`` prefix.
@@ -69,7 +69,7 @@ class MulticastMessage(object):
69
69
android: An instance of ``messaging.AndroidConfig`` (optional).
70
70
webpush: An instance of ``messaging.WebpushConfig`` (optional).
71
71
apns: An instance of ``messaging.ApnsConfig`` (optional).
72
- fcm_options: An instance of ``messaging.FcmOptions `` (optional).
72
+ fcm_options: An instance of ``messaging.FCMOptions `` (optional).
73
73
"""
74
74
def __init__ (self , tokens , data = None , notification = None , android = None , webpush = None , apns = None ,
75
75
fcm_options = None ):
@@ -114,7 +114,7 @@ class AndroidConfig(object):
114
114
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
115
115
strings. When specified, overrides any data fields set via ``Message.data``.
116
116
notification: A ``messaging.AndroidNotification`` to be included in the message (optional).
117
- fcm_options: A ``messaging.AndroidFcmOptions `` to be included in the message (optional).
117
+ fcm_options: A ``messaging.AndroidFCMOptions `` to be included in the message (optional).
118
118
"""
119
119
120
120
def __init__ (self , collapse_key = None , priority = None , ttl = None , restricted_package_name = None ,
@@ -174,7 +174,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
174
174
self .channel_id = channel_id
175
175
176
176
177
- class AndroidFcmOptions (object ):
177
+ class AndroidFCMOptions (object ):
178
178
"""Options for features provided by the FCM SDK for Android.
179
179
180
180
Args:
@@ -195,7 +195,7 @@ class WebpushConfig(object):
195
195
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
196
196
strings. When specified, overrides any data fields set via ``Message.data``.
197
197
notification: A ``messaging.WebpushNotification`` to be included in the message (optional).
198
- fcm_options: A ``messaging.WebpushFcmOptions `` instance to be included in the message
198
+ fcm_options: A ``messaging.WebpushFCMOptions `` instance to be included in the message
199
199
(optional).
200
200
201
201
.. _Webpush Specification: https://tools.ietf.org/html/rfc8030#section-5
@@ -280,7 +280,7 @@ def __init__(self, title=None, body=None, icon=None, actions=None, badge=None, d
280
280
self .custom_data = custom_data
281
281
282
282
283
- class WebpushFcmOptions (object ):
283
+ class WebpushFCMOptions (object ):
284
284
"""Options for features provided by the FCM SDK for Web.
285
285
286
286
Args:
@@ -300,7 +300,7 @@ class APNSConfig(object):
300
300
Args:
301
301
headers: A dictionary of headers (optional).
302
302
payload: A ``messaging.APNSPayload`` to be included in the message (optional).
303
- fcm_options: A ``messaging.APNSFcmOptions `` instance to be included in the message
303
+ fcm_options: A ``messaging.APNSFCMOptions `` instance to be included in the message
304
304
(optional).
305
305
306
306
.. _APNS Documentation: https://developer.apple.com/library/content/documentation\
@@ -396,10 +396,13 @@ class ApsAlert(object):
396
396
action_loc_key: Key of the text in the app's string resources to use to localize the
397
397
action button text (optional).
398
398
launch_image: Image for the notification action (optional).
399
+ custom_data: A dict of custom key-value pairs to be included in the ApsAlert dictionary
400
+ (optional)
399
401
"""
400
402
401
403
def __init__ (self , title = None , subtitle = None , body = None , loc_key = None , loc_args = None ,
402
- title_loc_key = None , title_loc_args = None , action_loc_key = None , launch_image = None ):
404
+ title_loc_key = None , title_loc_args = None , action_loc_key = None , launch_image = None ,
405
+ custom_data = None ):
403
406
self .title = title
404
407
self .subtitle = subtitle
405
408
self .body = body
@@ -409,9 +412,10 @@ def __init__(self, title=None, subtitle=None, body=None, loc_key=None, loc_args=
409
412
self .title_loc_args = title_loc_args
410
413
self .action_loc_key = action_loc_key
411
414
self .launch_image = launch_image
415
+ self .custom_data = custom_data
412
416
413
417
414
- class APNSFcmOptions (object ):
418
+ class APNSFCMOptions (object ):
415
419
"""Options for features provided by the FCM SDK for iOS.
416
420
417
421
Args:
@@ -423,7 +427,7 @@ def __init__(self, analytics_label=None):
423
427
self .analytics_label = analytics_label
424
428
425
429
426
- class FcmOptions (object ):
430
+ class FCMOptions (object ):
427
431
"""Options for features provided by SDK.
428
432
429
433
Args:
@@ -533,15 +537,15 @@ def encode_android(cls, android):
533
537
534
538
@classmethod
535
539
def encode_android_fcm_options (cls , fcm_options ):
536
- """Encodes a AndroidFcmOptions instance into a json."""
540
+ """Encodes an AndroidFCMOptions instance into a json."""
537
541
if fcm_options is None :
538
542
return None
539
- if not isinstance (fcm_options , AndroidFcmOptions ):
543
+ if not isinstance (fcm_options , AndroidFCMOptions ):
540
544
raise ValueError ('AndroidConfig.fcm_options must be an instance of '
541
- 'AndroidFcmOptions class.' )
545
+ 'AndroidFCMOptions class.' )
542
546
result = {
543
547
'analytics_label' : _Validators .check_analytics_label (
544
- 'AndroidFcmOptions .analytics_label' , fcm_options .analytics_label ),
548
+ 'AndroidFCMOptions .analytics_label' , fcm_options .analytics_label ),
545
549
}
546
550
result = cls .remove_null_values (result )
547
551
return result
@@ -701,7 +705,7 @@ def encode_webpush_notification_actions(cls, actions):
701
705
702
706
@classmethod
703
707
def encode_webpush_fcm_options (cls , options ):
704
- """Encodes a WebpushFcmOptions instance into JSON."""
708
+ """Encodes a WebpushFCMOptions instance into JSON."""
705
709
if options is None :
706
710
return None
707
711
result = {
@@ -710,7 +714,7 @@ def encode_webpush_fcm_options(cls, options):
710
714
result = cls .remove_null_values (result )
711
715
link = result .get ('link' )
712
716
if link is not None and not link .startswith ('https://' ):
713
- raise ValueError ('WebpushFcmOptions .link must be a HTTPS URL.' )
717
+ raise ValueError ('WebpushFCMOptions .link must be a HTTPS URL.' )
714
718
return result
715
719
716
720
@classmethod
@@ -744,14 +748,14 @@ def encode_apns_payload(cls, payload):
744
748
745
749
@classmethod
746
750
def encode_apns_fcm_options (cls , fcm_options ):
747
- """Encodes an APNSFcmOptions instance into JSON."""
751
+ """Encodes an APNSFCMOptions instance into JSON."""
748
752
if fcm_options is None :
749
753
return None
750
- if not isinstance (fcm_options , APNSFcmOptions ):
751
- raise ValueError ('APNSConfig.fcm_options must be an instance of APNSFcmOptions class.' )
754
+ if not isinstance (fcm_options , APNSFCMOptions ):
755
+ raise ValueError ('APNSConfig.fcm_options must be an instance of APNSFCMOptions class.' )
752
756
result = {
753
757
'analytics_label' : _Validators .check_analytics_label (
754
- 'APNSFcmOptions .analytics_label' , fcm_options .analytics_label ),
758
+ 'APNSFCMOptions .analytics_label' , fcm_options .analytics_label ),
755
759
}
756
760
result = cls .remove_null_values (result )
757
761
return result
@@ -837,6 +841,14 @@ def encode_aps_alert(cls, alert):
837
841
if result .get ('title-loc-args' ) and not result .get ('title-loc-key' ):
838
842
raise ValueError (
839
843
'ApsAlert.title_loc_key is required when specifying title_loc_args.' )
844
+ if alert .custom_data is not None :
845
+ if not isinstance (alert .custom_data , dict ):
846
+ raise ValueError ('ApsAlert.custom_data must be a dict.' )
847
+ for key , val in alert .custom_data .items ():
848
+ _Validators .check_string ('ApsAlert.custom_data key' , key )
849
+ # allow specifying key override because Apple could update API so that key
850
+ # could have unexpected value type
851
+ result [key ] = val
840
852
return cls .remove_null_values (result )
841
853
842
854
@classmethod
@@ -887,14 +899,14 @@ def default(self, obj): # pylint: disable=method-hidden
887
899
888
900
@classmethod
889
901
def encode_fcm_options (cls , fcm_options ):
890
- """Encodes an FcmOptions instance into JSON."""
902
+ """Encodes an FCMOptions instance into JSON."""
891
903
if fcm_options is None :
892
904
return None
893
- if not isinstance (fcm_options , FcmOptions ):
894
- raise ValueError ('Message.fcm_options must be an instance of FcmOptions class.' )
905
+ if not isinstance (fcm_options , FCMOptions ):
906
+ raise ValueError ('Message.fcm_options must be an instance of FCMOptions class.' )
895
907
result = {
896
908
'analytics_label' : _Validators .check_analytics_label (
897
- 'FcmOptions .analytics_label' , fcm_options .analytics_label ),
909
+ 'FCMOptions .analytics_label' , fcm_options .analytics_label ),
898
910
}
899
911
result = cls .remove_null_values (result )
900
912
return result
0 commit comments