Esempio n. 1
0
    def send_message(
        self,
        message: messaging.Message,
        **more_send_message_kwargs,
    ) -> Union[Optional[messaging.SendResponse], FirebaseError]:
        """
        Send single message. The message's token should be blank (and will be
        overridden if not). Responds with message ID string.

        :param message: firebase.messaging.Message. If `message` includes a token/id, it
        will be overridden.
        :param more_send_message_kwargs: Parameters for firebase.messaging.send_all()
        - dry_run: bool. Whether to actually send the notification to the device
        - app: firebase_admin.App. Specify a specific app to use
        If there are any new parameters, you can still specify them here.

        :raises FirebaseError
        :returns messaging.SendResponse or FirebaseError if the device was
        deactivated due to an error.
        """
        message.token = self.registration_id
        try:
            return messaging.SendResponse(
                {"name": messaging.send(message, **more_send_message_kwargs)},
                None)
        except FirebaseError as e:
            self.deactivate_devices_with_error_result(self.registration_id, e)
            return e
Esempio n. 2
0
 def _prepare_message(message: messaging.Message, token: str):
     message.token = token
     return copy(message)