diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c5f8dea5..e9007b7b 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -419,6 +419,10 @@ def pyrogram_api(): GameHighScore CallbackGame WebAppInfo + MenuButton + MenuButtonCommands + MenuButtonWebApp + MenuButtonDefault """, bot_commands=""" Bot commands diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 44fd5894..58f98ced 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -33,6 +33,10 @@ from .inline_keyboard_button import InlineKeyboardButton from .inline_keyboard_markup import InlineKeyboardMarkup from .keyboard_button import KeyboardButton from .login_url import LoginUrl +from .menu_button import MenuButton +from .menu_button_commands import MenuButtonCommands +from .menu_button_default import MenuButtonDefault +from .menu_button_web_app import MenuButtonWebApp from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove from .web_app_info import WebAppInfo @@ -57,5 +61,9 @@ __all__ = [ "BotCommandScopeChatAdministrators", "BotCommandScopeChatMember", "BotCommandScopeDefault", - "WebAppInfo" + "WebAppInfo", + "MenuButton", + "MenuButtonCommands", + "MenuButtonWebApp", + "MenuButtonDefault" ] diff --git a/pyrogram/types/bots_and_keyboards/menu_button.py b/pyrogram/types/bots_and_keyboards/menu_button.py new file mode 100644 index 00000000..e61e7baa --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button.py @@ -0,0 +1,44 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram import raw +from ..object import Object + + +class MenuButton(Object): + """Describes the bot's menu button in a private chat. + + It should be one of: + + - :obj:`~pyrogram.types.MenuButtonCommands` + - :obj:`~pyrogram.types.MenuButtonWebApp` + - :obj:`~pyrogram.types.MenuButtonDefault` + + If a menu button other than :obj:`~pyrogram.types.MenuButtonDefault` is set for a private chat, then it is applied + in the chat. Otherwise the default menu button is applied. By default, the menu button opens the list of bot + commands. + """ + + def __init__(self, type: str): + super().__init__() + + self.type = type + + async def write(self, client: "pyrogram.Client") -> "raw.base.BotMenuButton": + raise NotImplementedError diff --git a/pyrogram/types/bots_and_keyboards/menu_button_commands.py b/pyrogram/types/bots_and_keyboards/menu_button_commands.py new file mode 100644 index 00000000..b2ef77c9 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button_commands.py @@ -0,0 +1,32 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram import raw +from .menu_button import MenuButton + + +class MenuButtonCommands(MenuButton): + """A menu button, which opens the bot's list of commands. + """ + + def __init__(self): + super().__init__("commands") + + async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonCommands": + return raw.types.BotMenuButtonCommands() diff --git a/pyrogram/types/bots_and_keyboards/menu_button_default.py b/pyrogram/types/bots_and_keyboards/menu_button_default.py new file mode 100644 index 00000000..a00e6763 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button_default.py @@ -0,0 +1,32 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram import raw +from .menu_button import MenuButton + + +class MenuButtonDefault(MenuButton): + """Describes that no specific value for the menu button was set. + """ + + def __init__(self): + super().__init__("default") + + async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButtonDefault": + return raw.types.BotMenuButtonDefault() diff --git a/pyrogram/types/bots_and_keyboards/menu_button_web_app.py b/pyrogram/types/bots_and_keyboards/menu_button_web_app.py new file mode 100644 index 00000000..109088bb --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/menu_button_web_app.py @@ -0,0 +1,51 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram import raw, types +from .menu_button import MenuButton + + +class MenuButtonWebApp(MenuButton): + """A menu button, which launches a `Web App `_. + + Parameters: + text (``str``): + Text on the button + + web_app (:obj:`~pyrogram.types.WebAppInfo`): + Description of the Web App that will be launched when the user presses the button. + The Web App will be able to send an arbitrary message on behalf of the user using the method + :meth:`~pyrogram.Client.answer_web_app_query`. + """ + + def __init__( + self, + text: str, + web_app: "types.WebAppInfo" + ): + super().__init__("web_app") + + self.text = text + self.web_app = web_app + + async def write(self, client: "pyrogram.Client") -> "raw.types.BotMenuButton": + return raw.types.BotMenuButton( + text=self.text, + url=self.web_app.url + )