diff --git a/telegram/user.py b/telegram/user.py index 1956af194..1ca5e52cb 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -83,6 +83,17 @@ class User(TelegramObject): return '%s %s' % (self.first_name, self.last_name) return self.first_name + @property + def full_name(self): + """ + :obj:`str`: The users :attr:`first_name` and if present :attr:`last_name`. + + """ + + if self.last_name: + return '%s %s' % (self.first_name, self.last_name) + return self.first_name + @classmethod def de_json(cls, data, bot): if not data: diff --git a/tests/test_user.py b/tests/test_user.py index 720159ce4..14ddab2e2 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -90,6 +90,11 @@ class TestUser(object): assert user.name == 'first_name' user.username = self.username assert user.name == '@username' + + def test_full_name(self, user): + assert user.full_name == 'first_name last_name' + user.last_name = None + assert user.full_name == 'first_name' def test_get_profile_photos(self, monkeypatch, user): def test(_, *args, **kwargs):