From 2d404a1c99ac39088f69b5b2a6c64c17b72588f8 Mon Sep 17 00:00:00 2001 From: Francesco Zimbolo Date: Mon, 8 Jul 2019 19:40:31 +0200 Subject: [PATCH 1/2] Added support for setting a new chat title --- botogram/objects/mixins.py | 14 ++++++++++++++ docs/api/telegram.rst | 10 ++++++++++ docs/changelog/0.7.rst | 3 +++ 3 files changed, 27 insertions(+) diff --git a/botogram/objects/mixins.py b/botogram/objects/mixins.py index 657f527..9c6ff77 100644 --- a/botogram/objects/mixins.py +++ b/botogram/objects/mixins.py @@ -372,6 +372,20 @@ def send_album(self, album=None, reply_to=None, notify=True): return albums.send() return albums + @_require_api + def set_title(self, title): + """Set a new chat title""" + if type(title) is not str or len(title) > 255 or len(title) < 1: + raise ValueError( + "The new chat title must be a string between" + + " 1 and 255 characters long" + ) + else: + self._api.call("setChatTitle", { + "chat_id": self.id, + "title": title + }) + class MessageMixin: """Add some methods for messages""" diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index fa36fef..07af2d1 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -1445,6 +1445,16 @@ about its business. .. versionadded:: 0.6 + .. py:method:: set_title(title) + + Set a new chat title. + + The bot must be an administrator with the correct rights for this method to work. + + :param str title: The new chat title, must be between 1 and 255 characters long + + .. versionadded:: 0.7 + .. py:class:: botogram.ParsedText This class contains the parsed representation of the text of a received diff --git a/docs/changelog/0.7.rst b/docs/changelog/0.7.rst index 48b4f7d..6504a7d 100644 --- a/docs/changelog/0.7.rst +++ b/docs/changelog/0.7.rst @@ -32,6 +32,9 @@ New features * New method :py:meth:`~Message.edit_live_location` * New method :py:meth:`~Message.stop_live_location` +* Added support for editing the chat title + + * New method :py:meth:`~Chat.set_title` Bug fixes --------- From 6ed48dd07f416c7cbd643470efee377f2cb079b6 Mon Sep 17 00:00:00 2001 From: Francesco Zimbolo Date: Fri, 23 Oct 2020 19:07:20 +0200 Subject: [PATCH 2/2] set_title now returns api call result (True if succeeded) --- botogram/objects/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botogram/objects/mixins.py b/botogram/objects/mixins.py index 9c6ff77..03b4e9c 100644 --- a/botogram/objects/mixins.py +++ b/botogram/objects/mixins.py @@ -381,7 +381,7 @@ def set_title(self, title): " 1 and 255 characters long" ) else: - self._api.call("setChatTitle", { + return self._api.call("setChatTitle", { "chat_id": self.id, "title": title })