Skip to content

Commit e5013c8

Browse files
committed
Adds messaging sendMulticast function
1 parent 2d91a98 commit e5013c8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

firebase_admin/messaging.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
'send',
4949
'sendAll',
50+
'sendMulticast',
5051
'subscribe_to_topic',
5152
'unsubscribe_from_topic',
5253
]
@@ -110,6 +111,35 @@ def sendAll(messages, dry_run=False, app=None):
110111
"""
111112
return _get_messaging_service(app).sendAll(messages, dry_run)
112113

114+
def sendMulticast(tokens, message, dry_run=False, app=None):
115+
"""Batch sends the given message to the specified via Firebase Cloud Messaging (FCM).
116+
117+
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
118+
recipients. Instead FCM performs all the usual validations, and emulates the send operation.
119+
120+
Args:
121+
tokens: A list of token strings.
122+
message: An instance of ``messaging.Message``.
123+
dry_run: A boolean indicating whether to run the operation in dry run mode (optional).
124+
app: An App instance (optional).
125+
126+
Returns:
127+
list: A list of message ID string that uniquely identifies the sent the messages.
128+
129+
Raises:
130+
ApiCallError: If an error occurs while sending the message to FCM service.
131+
ValueError: If the input arguments are invalid.
132+
"""
133+
messages = map(lambda token: Message(
134+
data=message.data,
135+
notification=message.notification,
136+
android=message.android,
137+
webpush=message.webpush,
138+
apns=message.apns,
139+
token=token
140+
), tokens)
141+
return _get_messaging_service(app).sendAll(messages, dry_run)
142+
113143
def subscribe_to_topic(tokens, topic, app=None):
114144
"""Subscribes a list of registration tokens to an FCM topic.
115145

0 commit comments

Comments
 (0)