Skip to content

Commit 4f2a912

Browse files
committed
Added support for send_each_for_multicast_async() and updated doc string and type hints
1 parent 2df6ed5 commit 4f2a912

1 file changed

Lines changed: 58 additions & 1 deletion

File tree

firebase_admin/messaging.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,64 @@ def send_each(messages, dry_run=False, app=None):
152152
"""
153153
return _get_messaging_service(app).send_each(messages, dry_run)
154154

155-
async def send_each_async(messages, dry_run=True, app: Optional[App] = None) -> BatchResponse:
155+
async def send_each_async(
156+
messages: List[Message],
157+
dry_run: bool = False,
158+
app: Optional[App] = None
159+
) -> BatchResponse:
160+
"""Sends each message in the given list asynchronously via Firebase Cloud Messaging.
161+
162+
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
163+
recipients. Instead FCM performs all the usual validations, and emulates the send operation.
164+
165+
Args:
166+
messages: A list of ``messaging.Message`` instances.
167+
dry_run: A boolean indicating whether to run the operation in dry run mode (optional).
168+
app: An App instance (optional).
169+
170+
Returns:
171+
BatchResponse: A ``messaging.BatchResponse`` instance.
172+
173+
Raises:
174+
FirebaseError: If an error occurs while sending the message to the FCM service.
175+
ValueError: If the input arguments are invalid.
176+
"""
177+
return await _get_messaging_service(app).send_each_async(messages, dry_run)
178+
179+
async def send_each_for_multicast_async(
180+
multicast_message: MulticastMessage,
181+
dry_run: bool = False,
182+
app: Optional[App] = None
183+
) -> BatchResponse:
184+
"""Sends the given mutlicast message to each token asynchronously via Firebase Cloud Messaging
185+
(FCM).
186+
187+
If the ``dry_run`` mode is enabled, the message will not be actually delivered to the
188+
recipients. Instead FCM performs all the usual validations, and emulates the send operation.
189+
190+
Args:
191+
multicast_message: An instance of ``messaging.MulticastMessage``.
192+
dry_run: A boolean indicating whether to run the operation in dry run mode (optional).
193+
app: An App instance (optional).
194+
195+
Returns:
196+
BatchResponse: A ``messaging.BatchResponse`` instance.
197+
198+
Raises:
199+
FirebaseError: If an error occurs while sending the message to the FCM service.
200+
ValueError: If the input arguments are invalid.
201+
"""
202+
if not isinstance(multicast_message, MulticastMessage):
203+
raise ValueError('Message must be an instance of messaging.MulticastMessage class.')
204+
messages = [Message(
205+
data=multicast_message.data,
206+
notification=multicast_message.notification,
207+
android=multicast_message.android,
208+
webpush=multicast_message.webpush,
209+
apns=multicast_message.apns,
210+
fcm_options=multicast_message.fcm_options,
211+
token=token
212+
) for token in multicast_message.tokens]
156213
return await _get_messaging_service(app).send_each_async(messages, dry_run)
157214

158215
def send_each_for_multicast(multicast_message, dry_run=False, app=None):

0 commit comments

Comments
 (0)