Skip to content

add channel_id to messaging.AndroidNotification #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# 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
returns an integer, and never returns `None`.
- [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
Expand Down
6 changes: 5 additions & 1 deletion firebase_admin/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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')
Expand Down
9 changes: 8 additions & 1 deletion tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,20 @@ 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',
android=messaging.AndroidConfig(
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'
)
)
)
Expand All @@ -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',
},
},
}
Expand Down