|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import Union |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import raw |
| 23 | +from pyrogram import types |
| 24 | + |
| 25 | + |
| 26 | +class GetChatMenuButton: |
| 27 | + async def get_chat_menu_button( |
| 28 | + self: "pyrogram.Client", |
| 29 | + chat_id: Union[int, str] = None, |
| 30 | + ) -> "types.MenuButton": |
| 31 | + """Get the current value of the bot's menu button in a private chat, or the default menu button. |
| 32 | +
|
| 33 | + chat_id (``int`` | ``str``): |
| 34 | + Unique identifier (int) or username (str) of the target chat. |
| 35 | + If not specified, default bot's menu button will be returned. |
| 36 | + """ |
| 37 | + |
| 38 | + if chat_id: |
| 39 | + r = await self.invoke( |
| 40 | + raw.functions.bots.GetBotMenuButton( |
| 41 | + user_id=await self.resolve_peer(chat_id), |
| 42 | + ) |
| 43 | + ) |
| 44 | + else: |
| 45 | + r = (await self.invoke( |
| 46 | + raw.functions.users.GetFullUser( |
| 47 | + id=raw.types.InputUserSelf() |
| 48 | + ) |
| 49 | + )).full_user.bot_info.menu_button |
| 50 | + |
| 51 | + if isinstance(r, raw.types.BotMenuButtonCommands): |
| 52 | + return types.MenuButtonCommands() |
| 53 | + |
| 54 | + if isinstance(r, raw.types.BotMenuButtonDefault): |
| 55 | + return types.MenuButtonDefault() |
| 56 | + |
| 57 | + if isinstance(r, raw.types.BotMenuButton): |
| 58 | + return types.MenuButtonWebApp( |
| 59 | + text=r.text, |
| 60 | + web_app=types.WebAppInfo( |
| 61 | + url=r.url |
| 62 | + ) |
| 63 | + ) |
0 commit comments