Skip to content
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

Support for incoming inline keyboard markup in Message objects #144

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion botogram/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,8 @@
"ReplyKeyboardMarkup",
"ReplyKeyboardHide",
"ForceReply",
"InlineKeyboardButton",
"InlineKeyboardMarkup",

# Polls-related objects
"Poll",
Expand Down
29 changes: 29 additions & 0 deletions botogram/objects/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing login_url and callback_game parameters

"url": str,
"callback_data": str,
"switch_inline_query": str,
"switch_inline_query_current_chat": str,
"pay": bool,
}


class InlineKeyboardMarkup(BaseObject):
"""Telegram API representation of a inline keyboard markup

https://core.telegram.org/bots/api#inlinekeyboardmarkup
"""

required = {
"inline_keyboard": multiple(multiple(InlineKeyboardButton)),
}
2 changes: 2 additions & 0 deletions botogram/objects/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from . import mixins
from .. import utils
from .chats import User, Chat
from .markup import InlineKeyboardMarkup
from .media import Audio, Voice, Document, Photo, Sticker, Video, VideoNote, \
Animation, Contact, Location, Venue
from .polls import Poll
Expand Down Expand Up @@ -365,6 +366,7 @@ def from_(self):
"migrate_from_chat_id": int,
"pinned_message": _itself,
"edit_date": int,
"reply_markup": InlineKeyboardMarkup,
}
replace_keys = {
"from": "sender",
Expand Down
62 changes: 62 additions & 0 deletions docs/api/telegram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -100,6 +102,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.InlineKeyboardMarkup` 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
Expand Down Expand Up @@ -3256,6 +3266,58 @@ about its business.
*This attribute can be None if it's not provided by Telegram.*


.. py:class:: botogram.InlineKeyboardButton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing login_url and callback_game parameters


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.*

.. 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
.. _API types: https://core.telegram.org/bots/api#available-types
6 changes: 6 additions & 0 deletions docs/changelog/0.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------

Expand Down