Skip to content

Commit

Permalink
Add Button.buy and Button.game (#3141)
Browse files Browse the repository at this point in the history
  • Loading branch information
New-dev0 committed Aug 29, 2021
1 parent 0a4b827 commit 9830c4e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion telethon/tl/custom/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Button:
instances instead making them yourself (i.e. don't do ``Button(...)``
but instead use methods line `Button.inline(...) <inline>` etc.
You can use `inline`, `switch_inline`, `url` and `auth`
You can use `inline`, `switch_inline`, `url`, `auth`, `buy` and `game`
together to create inline buttons (under the message).
You can use `text`, `request_location`, `request_phone` and `request_poll`
Expand Down Expand Up @@ -49,7 +49,9 @@ def _is_inline(button):
Returns `True` if the button belongs to an inline keyboard.
"""
return isinstance(button, (
types.KeyboardButtonBuy,
types.KeyboardButtonCallback,
types.KeyboardButtonGame,
types.KeyboardButtonSwitchInline,
types.KeyboardButtonUrl,
types.InputKeyboardButtonUrlAuth
Expand Down Expand Up @@ -266,8 +268,41 @@ def force_reply(single_use=None, selective=None, placeholder=None):
Args:
placeholder (str):
text to show the user at typing place of message.
If the placeholder is too long, Telegram applications will
crop the text (for example, to 64 characters and adding an
ellipsis (…) character as the 65th).
"""
return types.ReplyKeyboardForceReply(
single_use=single_use,
selective=selective,
placeholder=placeholder)

@staticmethod
def buy(text):
"""
Creates a new inline button to buy a product.
This can only be used when sending files of type
:tl:`InputMediaInvoice`, and must be the first button.
If the button is not specified, Telegram will automatically
add the button to the message. See the
`Payments API <https://core.telegram.org/api/payments>`__
documentation for more information.
"""
return types.KeyboardButtonBuy(text)

@staticmethod
def game(text):
"""
Creates a new inline button to start playing a game.
This should be used when sending files of type
:tl:`InputMediaGame`, and must be the first button.
See the
`Games <https://core.telegram.org/api/bots/games>`__
documentation for more information on using games.
"""
return types.KeyboardButtonGame(text)

0 comments on commit 9830c4e

Please sign in to comment.