Skip to content

add analytics_label in FcmOptions #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions firebase_admin/_messaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ class Message(object):
android: An instance of ``messaging.AndroidConfig`` (optional).
webpush: An instance of ``messaging.WebpushConfig`` (optional).
apns: An instance of ``messaging.ApnsConfig`` (optional).
fcm_options: An instance of ``messaging.FcmOptions`` (optional).
token: The registration token of the device to which the message should be sent (optional).
topic: Name of the FCM topic to which the message should be sent (optional). Topic name
may contain the ``/topics/`` prefix.
condition: The FCM condition to which the message should be sent (optional).
"""

def __init__(self, data=None, notification=None, android=None, webpush=None, apns=None,
token=None, topic=None, condition=None):
fcm_options=None, token=None, topic=None, condition=None):
self.data = data
self.notification = notification
self.android = android
self.webpush = webpush
self.apns = apns
self.fcm_options = fcm_options
self.token = token
self.topic = topic
self.condition = condition
Expand All @@ -65,8 +67,10 @@ class MulticastMessage(object):
android: An instance of ``messaging.AndroidConfig`` (optional).
webpush: An instance of ``messaging.WebpushConfig`` (optional).
apns: An instance of ``messaging.ApnsConfig`` (optional).
fcm_options: An instance of ``messaging.FcmOptions`` (optional).
"""
def __init__(self, tokens, data=None, notification=None, android=None, webpush=None, apns=None):
def __init__(self, tokens, data=None, notification=None, android=None, webpush=None, apns=None,
fcm_options=None):
_Validators.check_string_list('MulticastMessage.tokens', tokens)
if len(tokens) > 100:
raise ValueError('MulticastMessage.tokens must not contain more than 100 tokens.')
Expand All @@ -76,6 +80,7 @@ def __init__(self, tokens, data=None, notification=None, android=None, webpush=N
self.android = android
self.webpush = webpush
self.apns = apns
self.fcm_options = fcm_options


class Notification(object):
Expand Down Expand Up @@ -107,16 +112,18 @@ class AndroidConfig(object):
data: A dictionary of data fields (optional). All keys and values in the dictionary must be
strings. When specified, overrides any data fields set via ``Message.data``.
notification: A ``messaging.AndroidNotification`` to be included in the message (optional).
fcm_options: A ``messaging.AndroidFcmOptions`` to be included in the message (optional).
"""

def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_package_name=None,
data=None, notification=None):
data=None, notification=None, fcm_options=None):
self.collapse_key = collapse_key
self.priority = priority
self.ttl = ttl
self.restricted_package_name = restricted_package_name
self.data = data
self.notification = notification
self.fcm_options = fcm_options


class AndroidNotification(object):
Expand Down Expand Up @@ -165,6 +172,18 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
self.channel_id = channel_id


class AndroidFcmOptions(object):
"""Options for features provided by the FCM SDK for Android.

Args:
analytics_label: contains additional options for features provided by the FCM Android SDK
(optional).
"""

def __init__(self, analytics_label=None):
self.analytics_label = analytics_label


class WebpushConfig(object):
"""Webpush-specific options that can be included in a message.

Expand Down Expand Up @@ -279,14 +298,17 @@ class APNSConfig(object):
Args:
headers: A dictionary of headers (optional).
payload: A ``messaging.APNSPayload`` to be included in the message (optional).
fcm_options: A ``messaging.APNSFcmOptions`` instance to be included in the message
(optional).

.. _APNS Documentation: https://developer.apple.com/library/content/documentation\
/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
"""

def __init__(self, headers=None, payload=None):
def __init__(self, headers=None, payload=None, fcm_options=None):
self.headers = headers
self.payload = payload
self.fcm_options = fcm_options


class APNSPayload(object):
Expand Down Expand Up @@ -387,6 +409,27 @@ def __init__(self, title=None, subtitle=None, body=None, loc_key=None, loc_args=
self.launch_image = launch_image


class APNSFcmOptions(object):
"""Options for features provided by the FCM SDK for iOS.

Args:
analytics_label: contains additional options for features provided by the FCM iOS SDK
(optional).
"""

def __init__(self, analytics_label=None):
self.analytics_label = analytics_label

class FcmOptions(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add one more empty line.

"""Options for features provided by SDK.

Args:
analytics_label: contains additional options to use across all platforms (optional).
"""

def __init__(self, analytics_label=None):
self.analytics_label = analytics_label

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more empty line.

class _Validators(object):
"""A collection of data validation utilities.

Expand Down Expand Up @@ -553,7 +596,7 @@ def encode_webpush(cls, webpush):
'headers': _Validators.check_string_dict(
'WebpushConfig.headers', webpush.headers),
'notification': cls.encode_webpush_notification(webpush.notification),
'fcmOptions': cls.encode_webpush_fcm_options(webpush.fcm_options),
'fcm_options': cls.encode_webpush_fcm_options(webpush.fcm_options),
}
return cls.remove_null_values(result)

Expand Down
7 changes: 7 additions & 0 deletions firebase_admin/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@

__all__ = [
'AndroidConfig',
'AndroidFcmOptions',
'AndroidNotification',
'APNSConfig',
'APNSFcmOptions',
'APNSPayload',
'ApiCallError',
'Aps',
'ApsAlert',
'BatchResponse',
'CriticalSound',
'ErrorInfo',
'FcmOptions',
'Message',
'MulticastMessage',
'Notification',
Expand All @@ -61,12 +64,15 @@


AndroidConfig = _messaging_utils.AndroidConfig
AndroidFcmOptions = _messaging_utils.AndroidFcmOptions
AndroidNotification = _messaging_utils.AndroidNotification
APNSConfig = _messaging_utils.APNSConfig
APNSFcmOptions = _messaging_utils.APNSFcmOptions
APNSPayload = _messaging_utils.APNSPayload
Aps = _messaging_utils.Aps
ApsAlert = _messaging_utils.ApsAlert
CriticalSound = _messaging_utils.CriticalSound
FcmOptions = _messaging_utils.FcmOptions
Message = _messaging_utils.Message
MulticastMessage = _messaging_utils.MulticastMessage
Notification = _messaging_utils.Notification
Expand Down Expand Up @@ -145,6 +151,7 @@ def send_multicast(multicast_message, dry_run=False, app=None):
android=multicast_message.android,
webpush=multicast_message.webpush,
apns=multicast_message.apns,
fcm_options=multicast_message.fcmOptions,
token=token
) for token in multicast_message.tokens]
return _get_messaging_service(app).send_all(messages, dry_run)
Expand Down