def build_notification(destination: str, title: str, body: str) -> PushMessage: """ Creates and returns a valid notification, ready to be broadcast. Can raise TypeError and ValueError. :param destination: The client's notification token (ExponentPushToken). :param title: The notification's title. :param body: The main body of the notification. :return: The built notification to broadcast. """ if type(destination) is not str or type(title) is not str or type(body) is not str: # Check for type errors raise TypeError("Expected type <class 'str'>") if not PushClient.is_exponent_push_token(destination): # Check if the token is valid raise ValueError("Not a value notification token") notification = PushMessage(to=destination, title=title, body=body, sound="default") # Build the push message (notification) return notification
def build_notification(destination, title, body): """ Creates and returns a valid notification, ready to be broadcast :param destination: expo client notification token (str) :param title: notification title (str) :param body: main body of the notification (str) :return: built notification to broadcast (PushMessage) """ if type(destination) is not str or type(title) is not str or type( body) is not str: # Check for type errors raise TypeError("Expected type <class 'str'>") if not PushClient.is_exponent_push_token( destination): # Check if the token is valid raise ValueError("Not a value notification token") notification = PushMessage( to=destination, title=title, body=body, sound="default") # Build the push message (notification) return notification