|
47 | 47 |
|
48 | 48 | 'send',
|
49 | 49 | 'sendAll',
|
| 50 | + 'sendMulticast', |
50 | 51 | 'subscribe_to_topic',
|
51 | 52 | 'unsubscribe_from_topic',
|
52 | 53 | ]
|
@@ -110,6 +111,35 @@ def sendAll(messages, dry_run=False, app=None):
|
110 | 111 | """
|
111 | 112 | return _get_messaging_service(app).sendAll(messages, dry_run)
|
112 | 113 |
|
| 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 | + |
113 | 143 | def subscribe_to_topic(tokens, topic, app=None):
|
114 | 144 | """Subscribes a list of registration tokens to an FCM topic.
|
115 | 145 |
|
@@ -272,8 +302,6 @@ def encode_message(cls, message):
|
272 | 302 | raise ValueError('Message must be an instance of messaging.Message class.')
|
273 | 303 | return cls.JSON_ENCODER.default(message)
|
274 | 304 |
|
275 |
| - # TODO: sendMulticast |
276 |
| - |
277 | 305 | def send(self, message, dry_run=False):
|
278 | 306 | data = self._message_data(message, dry_run)
|
279 | 307 | try:
|
|
0 commit comments