From f17136abd0323f98d550ecff6640710b3f0081b0 Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Sun, 8 Sep 2019 18:03:42 +0200 Subject: [PATCH 1/4] Add incoming inline reply markup support --- botogram/objects/markup.py | 29 +++++++++++++++++++++++++++++ botogram/objects/messages.py | 2 ++ 2 files changed, 31 insertions(+) diff --git a/botogram/objects/markup.py b/botogram/objects/markup.py index a6ea92f..c9ac7c7 100644 --- a/botogram/objects/markup.py +++ b/botogram/objects/markup.py @@ -63,3 +63,32 @@ class ForceReply(BaseObject): optional = { "selective": bool, } + + +class InlineKeyboardButton(BaseObject): + """Telegram API representation of a inline keyboard button + + https://core.telegram.org/bots/api#inlinekeyboardbutton + """ + + required = { + "text": str, + } + optional = { + "url": str, + "callback_data": str, + "switch_inline_query": str, + "switch_inline_query_current_chat": str, + "pay": bool, + } + + +class KeyboardMarkup(BaseObject): + """Telegram API representation of a keyboard markup + + https://core.telegram.org/bots/api#inlinekeyboardmarkup + """ + + required = { + "inline_keyboard": multiple(multiple(InlineKeyboardButton)), + } diff --git a/botogram/objects/messages.py b/botogram/objects/messages.py index 2bd2110..e8c9176 100644 --- a/botogram/objects/messages.py +++ b/botogram/objects/messages.py @@ -24,6 +24,7 @@ from . import mixins from .. import utils from .chats import User, Chat +from .markup import KeyboardMarkup from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \ Animation, Contact, Location, Venue from .polls import Poll @@ -365,6 +366,7 @@ def from_(self): "migrate_from_chat_id": int, "pinned_message": _itself, "edit_date": int, + "reply_markup": KeyboardMarkup, } replace_keys = { "from": "sender", From a5536c4d6044922b232dc2fedde50ee252ff41ec Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Sun, 8 Sep 2019 18:26:13 +0200 Subject: [PATCH 2/4] Add documentation --- docs/api/telegram.rst | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index 0a30669..0705e33 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -100,6 +100,14 @@ about its business. .. versionadded:: 0.2 + .. py:attribute:: reply_markup + + This attribute contains the inline keyboard attached to the message. + + It's always an instance of :py:class:`~botogram.KeyboardMarkup` class. + + *This attribute can be None if it's not provided by Telegram.* + .. py:method:: avatar_history() Get the user's avatar history. This returns a list of the current and all @@ -3256,6 +3264,45 @@ about its business. *This attribute can be None if it's not provided by Telegram.* +.. py:class:: botogram.InlineKeyboardButton + + This class represents an inline keyboard button. + + .. py:attribute:: text + + Label text of the button. + + .. py:attribute:: url + + The URL that the button is carrying. + + *This attribute can be None if it's not provided by Telegram.* + + .. py:attribute:: callback_data + + The callback data that the button is carrying. + + *This attribute can be None if it's not provided by Telegram.* + + .. py:attribute:: switch_inline_query + + The switch inline query parameter that the button is carrying. + + *This attribute can be None if it's not provided by Telegram.* + + .. py:attribute:: switch_inline_query_current_chat + + The switch inline query current chat parameter that the button is carrying. + + *This attribute can be None if it's not provided by Telegram.* + + .. py:attribute:: pay + + This attribute is `True` when the button is a pay button. + + *This attribute can be None if it's not provided by Telegram.* + + .. _Telegram's Bot API: https://core.telegram.org/bots/api .. _API methods: https://core.telegram.org/bots/api#available-methods .. _API types: https://core.telegram.org/bots/api#available-types From 36f8875ff3188432537569d5f2851f6ba43b1dff Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Sun, 8 Sep 2019 18:38:22 +0200 Subject: [PATCH 3/4] Renamed KeyboardMarkup to InlineKeyboardMarkup and missing changelog --- botogram/objects/__init__.py | 2 ++ botogram/objects/markup.py | 4 ++-- botogram/objects/messages.py | 4 ++-- docs/api/telegram.rst | 17 ++++++++++++++++- docs/changelog/0.7.rst | 6 ++++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/botogram/objects/__init__.py b/botogram/objects/__init__.py index d933881..13a6564 100644 --- a/botogram/objects/__init__.py +++ b/botogram/objects/__init__.py @@ -57,6 +57,8 @@ "ReplyKeyboardMarkup", "ReplyKeyboardHide", "ForceReply", + "InlineKeyboardButton", + "InlineKeyboardMarkup", # Polls-related objects "Poll", diff --git a/botogram/objects/markup.py b/botogram/objects/markup.py index c9ac7c7..c89ffca 100644 --- a/botogram/objects/markup.py +++ b/botogram/objects/markup.py @@ -83,8 +83,8 @@ class InlineKeyboardButton(BaseObject): } -class KeyboardMarkup(BaseObject): - """Telegram API representation of a keyboard markup +class InlineKeyboardMarkup(BaseObject): + """Telegram API representation of a inline keyboard markup https://core.telegram.org/bots/api#inlinekeyboardmarkup """ diff --git a/botogram/objects/messages.py b/botogram/objects/messages.py index e8c9176..5a15101 100644 --- a/botogram/objects/messages.py +++ b/botogram/objects/messages.py @@ -24,7 +24,7 @@ from . import mixins from .. import utils from .chats import User, Chat -from .markup import KeyboardMarkup +from .markup import InlineKeyboardMarkup from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \ Animation, Contact, Location, Venue from .polls import Poll @@ -366,7 +366,7 @@ def from_(self): "migrate_from_chat_id": int, "pinned_message": _itself, "edit_date": int, - "reply_markup": KeyboardMarkup, + "reply_markup": InlineKeyboardMarkup, } replace_keys = { "from": "sender", diff --git a/docs/api/telegram.rst b/docs/api/telegram.rst index 0705e33..4973b68 100644 --- a/docs/api/telegram.rst +++ b/docs/api/telegram.rst @@ -37,6 +37,8 @@ about its business. * :py:class:`~botogram.ReplyKeyboardMarkup` * :py:class:`~botogram.ReplyKeyboardHide` * :py:class:`~botogram.ForceReply` +* :py:class:`~botogram.InlineKeyboardButton` +* :py:class:`~botogram.InlineKeyboardMarkup` .. py:class:: botogram.User @@ -104,7 +106,7 @@ about its business. This attribute contains the inline keyboard attached to the message. - It's always an instance of :py:class:`~botogram.KeyboardMarkup` class. + It's always an instance of :py:class:`~botogram.InlineKeyboardMarkup` class. *This attribute can be None if it's not provided by Telegram.* @@ -3302,6 +3304,19 @@ about its business. *This attribute can be None if it's not provided by Telegram.* + .. versionadded:: 0.7 + + +.. py:class:: botogram.InlineReplyMarkup + + This class represents a keyboard markup. + + .. py:attribute:: inline_keyboard + + Array of button rows, each represented by an array of + :py:class:`~botogram.InlineKeyboardButton`. + + .. versionadded:: 0.7 .. _Telegram's Bot API: https://core.telegram.org/bots/api .. _API methods: https://core.telegram.org/bots/api#available-methods diff --git a/docs/changelog/0.7.rst b/docs/changelog/0.7.rst index 498a589..42b3dc3 100644 --- a/docs/changelog/0.7.rst +++ b/docs/changelog/0.7.rst @@ -71,6 +71,12 @@ New features * New method :py:meth:`Chat.remove_photo` * New attribute :py:attr:`Chat.photo` +* Added support for incoming messages inline reply markup + + * New :py:class:`~botogram.InlineKeyboardMarkup` class + * New :py:class:`~botogram.InlineKeyboardButton` class + * New attribute :py:attr:`Message.reply_markup` + Bug fixes --------- From 7a57fd054c08847c00fbd29fe42113aa911b17cb Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Sun, 8 Sep 2019 18:45:09 +0200 Subject: [PATCH 4/4] Add missing import --- botogram/objects/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/botogram/objects/__init__.py b/botogram/objects/__init__.py index 13a6564..711538f 100644 --- a/botogram/objects/__init__.py +++ b/botogram/objects/__init__.py @@ -24,7 +24,8 @@ from .media import PhotoSize, Photo, Audio, Voice, Document, Sticker, \ Video, VideoNote, Animation, Contact, Location, Venue from .messages import Message -from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply +from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply, \ + InlineKeyboardButton, InlineKeyboardMarkup from .polls import Poll, PollOption from .updates import Update, Updates from .mixins import Album