diff --git a/CHANGELOG.md b/CHANGELOG.md index e7fcf53de..06c0b779c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- [added] `messaging.AndroidNotification`type now supports channel_id. - [fixed] Fixing error handling in FCM. The SDK now checks the key type.googleapis.com/google.firebase.fcm.v1.FcmError to set error code. - [fixed] Ensuring that `UserRecord.tokens_valid_after_time` always @@ -7,6 +8,7 @@ - [fixed] Fixing a performance issue in the `db.listen()` API where it was taking a long time to process large RTDB nodes. + # v2.13.0 - [added] The `db.Reference` type now provides a `listen()` API for diff --git a/firebase_admin/messaging.py b/firebase_admin/messaging.py index 28e80935c..96b38295e 100644 --- a/firebase_admin/messaging.py +++ b/firebase_admin/messaging.py @@ -246,11 +246,12 @@ class AndroidNotification(object): title text (optional). title_loc_args: A list of resource keys that will be used in place of the format specifiers in ``title_loc_key`` (optional). + channel_id: channel_id of the notification (optional). """ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag=None, click_action=None, body_loc_key=None, body_loc_args=None, title_loc_key=None, - title_loc_args=None): + title_loc_args=None, channel_id=None): self.title = title self.body = body self.icon = icon @@ -262,6 +263,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag self.body_loc_args = body_loc_args self.title_loc_key = title_loc_key self.title_loc_args = title_loc_args + self.channel_id = channel_id class WebpushConfig(object): @@ -596,6 +598,8 @@ def encode_android_notification(cls, notification): 'AndroidNotification.title_loc_args', notification.title_loc_args), 'title_loc_key': _Validators.check_string( 'AndroidNotification.title_loc_key', notification.title_loc_key), + 'channel_id': _Validators.check_string( + 'AndroidNotification.channel_id', notification.channel_id), } result = cls.remove_null_values(result) color = result.get('color') diff --git a/tests/test_messaging.py b/tests/test_messaging.py index 5b3a17232..a31f16447 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -335,6 +335,12 @@ def test_no_body_loc_key(self): expected = 'AndroidNotification.body_loc_key is required when specifying body_loc_args.' assert str(excinfo.value) == expected + @pytest.mark.parametrize('data', NON_STRING_ARGS) + def test_invalid_channek_id(self, data): + notification = messaging.AndroidNotification(channel_id=data) + excinfo = self._check_notification(notification) + assert str(excinfo.value) == 'AndroidNotification.channel_id must be a string.' + def test_android_notification(self): msg = messaging.Message( topic='topic', @@ -342,7 +348,7 @@ def test_android_notification(self): notification=messaging.AndroidNotification( title='t', body='b', icon='i', color='#112233', sound='s', tag='t', click_action='ca', title_loc_key='tlk', body_loc_key='blk', - title_loc_args=['t1', 't2'], body_loc_args=['b1', 'b2'] + title_loc_args=['t1', 't2'], body_loc_args=['b1', 'b2'], channel_id='c' ) ) ) @@ -361,6 +367,7 @@ def test_android_notification(self): 'body_loc_key': 'blk', 'title_loc_args': ['t1', 't2'], 'body_loc_args': ['b1', 'b2'], + 'channel_id' : 'c', }, }, }