mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
Added support of Telegram BOt API 6.0
This commit is contained in:
parent
51d3ad7d94
commit
0e2beb24c2
23 changed files with 969 additions and 574 deletions
2
Makefile
2
Makefile
|
|
@ -1,4 +1,4 @@
|
|||
VENV_NAME := venv
|
||||
VENV_NAME := .venv
|
||||
PYTHON := $(VENV_NAME)/bin/python
|
||||
AIOGRAM_VERSION := $(shell $(PYTHON) -c "import aiogram;print(aiogram.__version__)")
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
[](https://pypi.python.org/pypi/aiogram)
|
||||
[](https://pypi.python.org/pypi/aiogram)
|
||||
[](https://pypi.python.org/pypi/aiogram)
|
||||
[](https://core.telegram.org/bots/api)
|
||||
[](https://core.telegram.org/bots/api)
|
||||
[](http://docs.aiogram.dev/en/latest/?badge=latest)
|
||||
[](https://github.com/aiogram/aiogram/issues)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ AIOGramBot
|
|||
:target: https://pypi.python.org/pypi/aiogram
|
||||
:alt: Supported python versions
|
||||
|
||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.7-blue.svg?style=flat-square&logo=telegram
|
||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-6.0-blue.svg?style=flat-square&logo=telegram
|
||||
:target: https://core.telegram.org/bots/api
|
||||
:alt: Telegram Bot API
|
||||
|
||||
|
|
|
|||
|
|
@ -43,5 +43,5 @@ __all__ = (
|
|||
'utils',
|
||||
)
|
||||
|
||||
__version__ = '2.19'
|
||||
__api_version__ = '5.7'
|
||||
__version__ = '2.20'
|
||||
__api_version__ = '6.0'
|
||||
|
|
|
|||
|
|
@ -278,6 +278,13 @@ class Methods(Helper):
|
|||
# Inline mode
|
||||
ANSWER_INLINE_QUERY = Item() # answerInlineQuery
|
||||
|
||||
ANSWER_WEB_APP_QUERY = Item() # answerWebAppQuery
|
||||
SET_CHAT_MENU_BUTTON = Item() # setChatMenuButton
|
||||
GET_CHAT_MENU_BUTTON = Item() # getChatMenuButton
|
||||
|
||||
SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = Item() # setMyDefaultAdministratorRights
|
||||
GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS = Item() # getMyDefaultAdministratorRights
|
||||
|
||||
# Payments
|
||||
SEND_INVOICE = Item() # sendInvoice
|
||||
ANSWER_SHIPPING_QUERY = Item() # answerShippingQuery
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import warnings
|
|||
from .base import BaseBot, api
|
||||
from .. import types
|
||||
from ..types import base
|
||||
from ..utils.deprecated import deprecated, removed_argument
|
||||
from ..utils.deprecated import deprecated
|
||||
from ..utils.exceptions import ValidationError
|
||||
from ..utils.mixins import DataMixin, ContextInstanceMixin
|
||||
from ..utils.payload import generate_payload, prepare_arg, prepare_attachment, prepare_file
|
||||
|
|
@ -1089,7 +1089,8 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
|
||||
# Check MediaGroup quantity
|
||||
if not (1 <= len(media.media) <= 10):
|
||||
raise ValidationError("Media group must include 2-10 items as written in docs, but also it works with 1 element")
|
||||
raise ValidationError(
|
||||
"Media group must include 2-10 items as written in docs, but also it works with 1 element")
|
||||
|
||||
files = dict(media.get_files())
|
||||
|
||||
|
|
@ -1834,6 +1835,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
can_restrict_members: typing.Optional[base.Boolean] = None,
|
||||
can_pin_messages: typing.Optional[base.Boolean] = None,
|
||||
can_promote_members: typing.Optional[base.Boolean] = None,
|
||||
can_manage_video_chats: typing.Optional[base.Boolean] = None,
|
||||
) -> base.Boolean:
|
||||
"""
|
||||
Use this method to promote or demote a user in a supergroup or a channel.
|
||||
|
|
@ -1885,9 +1887,17 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
directly or indirectly (promoted by administrators that were appointed by him)
|
||||
:type can_promote_members: :obj:`typing.Optional[base.Boolean]`
|
||||
|
||||
:param can_manage_video_chats: Pass True, if the administrator can manage video chats
|
||||
|
||||
:return: Returns True on success
|
||||
:rtype: :obj:`base.Boolean`
|
||||
"""
|
||||
if can_manage_voice_chats:
|
||||
warnings.warn(
|
||||
"Argument `can_manage_voice_chats` was renamed to `can_manage_video_chats` and will be removed in aiogram 2.21")
|
||||
can_manage_video_chats = can_manage_voice_chats
|
||||
can_manage_voice_chats = None
|
||||
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.PROMOTE_CHAT_MEMBER, payload)
|
||||
|
|
@ -1910,7 +1920,6 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
|
||||
return await self.request(api.Methods.SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE, payload)
|
||||
|
||||
@removed_argument("until_date", "2.19")
|
||||
async def ban_chat_sender_chat(
|
||||
self,
|
||||
chat_id: typing.Union[base.Integer, base.String],
|
||||
|
|
@ -2587,6 +2596,87 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
result = await self.request(api.Methods.GET_MY_COMMANDS, payload)
|
||||
return [types.BotCommand(**bot_command_data) for bot_command_data in result]
|
||||
|
||||
async def set_chat_menu_button(self, chat_id: typing.Optional[base.Integer] = None,
|
||||
menu_button: typing.Optional[types.MenuButton] = None) -> bool:
|
||||
"""
|
||||
Use this method to change bot's menu button in a private chat, or the default menu button.
|
||||
|
||||
Returns True on success.
|
||||
|
||||
Source https://core.telegram.org/bots/api#setchatmenubutton
|
||||
|
||||
:param chat_id: Unique identifier for the target private chat.
|
||||
If not specified, default bot's menu button will be changed
|
||||
:param menu_button:
|
||||
A JSON-serialized object for the new bot's menu button. Defaults to MenuButtonDefault
|
||||
:return: Returns True on success.
|
||||
"""
|
||||
menu_button = prepare_arg(menu_button)
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.SET_CHAT_MENU_BUTTON, payload)
|
||||
|
||||
async def get_chat_menu_button(self, chat_id: typing.Optional[base.Integer] = None) -> typing.Union[
|
||||
"types.MenuButtonCommands",
|
||||
"types.MenuButtonDefault",
|
||||
"types.MenuButtonWebApp",
|
||||
]:
|
||||
"""
|
||||
Use this method to get the current value of the bot's menu button in a private chat,
|
||||
or the default menu button.
|
||||
|
||||
Returns MenuButton on success.
|
||||
|
||||
Source https://core.telegram.org/bots/api#getchatmenu
|
||||
|
||||
:param chat_id: Unique identifier for the target private chat. If not specified,
|
||||
default bot's menu button will be returned
|
||||
:return: Returns MenuButton on success.
|
||||
"""
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
result = await self.request(api.Methods.GET_CHAT_MENU_BUTTON, payload)
|
||||
return types.MenuButton.resolve(**result)
|
||||
|
||||
async def set_my_default_administrator_rights(self, rights: typing.Optional[types.ChatAdministratorRights] = None,
|
||||
for_channels: typing.Optional[base.Boolean] = None) -> base.Boolean:
|
||||
"""
|
||||
Use this method to change default administrator rights of the bot for adding it as an administrator
|
||||
to groups or channels.
|
||||
Returns True on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#setmydefaultadministratorrights
|
||||
|
||||
:param rights: A JSON-serialized object, describing new default administrator rights.
|
||||
If not specified, the default administrator rights will be cleared.
|
||||
:param for_channels:
|
||||
Pass True to change default administrator rights of the bot in channels.
|
||||
Otherwise, default administrator rights of the bot for groups and supergroups will be changed.
|
||||
:return: Returns True on success.
|
||||
"""
|
||||
rights = prepare_arg(rights)
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
return await self.request(api.Methods.SET_MY_DEFAULT_ADMINISTRATOR_RIGHTS, payload)
|
||||
|
||||
async def get_my_default_administrator_rights(self,
|
||||
for_channels: typing.Optional[base.Boolean] = None
|
||||
) -> types.ChatAdministratorRights:
|
||||
"""
|
||||
Use this method to get the current default administrator rights of the bot.
|
||||
Returns ChatAdministratorRights on success.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#getmydefaultadministratorrights
|
||||
|
||||
:param for_channels: Pass True to get default administrator rights of the bot in channels.
|
||||
Otherwise, default administrator rights of the bot for groups and supergroups will be returned.
|
||||
:return:
|
||||
"""
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
result = await self.request(api.Methods.GET_MY_DEFAULT_ADMINISTRATOR_RIGHTS, payload)
|
||||
return types.ChatAdministratorRights(**result)
|
||||
|
||||
async def edit_message_text(self,
|
||||
text: base.String,
|
||||
chat_id: typing.Union[base.Integer, base.String, None] = None,
|
||||
|
|
@ -3133,6 +3223,25 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
|
|||
|
||||
return await self.request(api.Methods.ANSWER_INLINE_QUERY, payload)
|
||||
|
||||
async def answer_web_app_query(self, web_app_query_id: base.String,
|
||||
result: types.InlineQueryResult) -> types.SentWebAppMessage:
|
||||
"""
|
||||
Use this method to set result of interaction with web app and send corresponding message
|
||||
on behalf of the user to the chat from which the query originated.
|
||||
On success, SentWebAppMessage is returned.
|
||||
|
||||
Source https://core.telegram.org/bots/api#answerwebappquery
|
||||
|
||||
:param web_app_query_id: Unique identifier for the answered query
|
||||
:param result: A JSON-serialized object with a description of the message to send
|
||||
:return: On success, SentWebAppMessage is returned.
|
||||
"""
|
||||
result = prepare_arg(result)
|
||||
payload = generate_payload(**locals())
|
||||
|
||||
response = await self.request(api.Methods.ANSWER_WEB_APP_QUERY, payload)
|
||||
return types.SentWebAppMessage(**response)
|
||||
|
||||
# === Payments ===
|
||||
# https://core.telegram.org/bots/api#payments
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from .bot_command_scope import BotCommandScope, BotCommandScopeAllChatAdministra
|
|||
from .callback_game import CallbackGame
|
||||
from .callback_query import CallbackQuery
|
||||
from .chat import Chat, ChatActions, ChatType
|
||||
from .chat_administrator_rights import ChatAdministratorRights
|
||||
from .chat_invite_link import ChatInviteLink
|
||||
from .chat_join_request import ChatJoinRequest
|
||||
from .chat_location import ChatLocation
|
||||
|
|
@ -48,6 +49,7 @@ from .labeled_price import LabeledPrice
|
|||
from .location import Location
|
||||
from .login_url import LoginUrl
|
||||
from .mask_position import MaskPosition
|
||||
from .menu_button import MenuButton, MenuButtonCommands, MenuButtonWebApp, MenuButtonDefault
|
||||
from .message import ContentType, ContentTypes, Message, ParseMode
|
||||
from .message_auto_delete_timer_changed import MessageAutoDeleteTimerChanged
|
||||
from .message_entity import MessageEntity, MessageEntityType
|
||||
|
|
@ -64,6 +66,7 @@ from .pre_checkout_query import PreCheckoutQuery
|
|||
from .proximity_alert_triggered import ProximityAlertTriggered
|
||||
from .reply_keyboard import KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, KeyboardButtonPollType
|
||||
from .response_parameters import ResponseParameters
|
||||
from .sent_web_app_message import SentWebAppMessage
|
||||
from .shipping_address import ShippingAddress
|
||||
from .shipping_option import ShippingOption
|
||||
from .shipping_query import ShippingQuery
|
||||
|
|
@ -75,12 +78,18 @@ from .user import User
|
|||
from .user_profile_photos import UserProfilePhotos
|
||||
from .venue import Venue
|
||||
from .video import Video
|
||||
from .video_chat_ended import VideoChatEnded
|
||||
from .video_chat_participants_invited import VideoChatParticipantsInvited
|
||||
from .video_chat_scheduled import VideoChatScheduled
|
||||
from .video_chat_started import VideoChatStarted
|
||||
from .video_note import VideoNote
|
||||
from .voice import Voice
|
||||
from .voice_chat_ended import VoiceChatEnded
|
||||
from .voice_chat_participants_invited import VoiceChatParticipantsInvited
|
||||
from .voice_chat_scheduled import VoiceChatScheduled
|
||||
from .voice_chat_started import VoiceChatStarted
|
||||
from .web_app_data import WebAppData
|
||||
from .web_app_info import WebAppInfo
|
||||
from .webhook_info import WebhookInfo
|
||||
|
||||
__all__ = (
|
||||
|
|
@ -102,6 +111,7 @@ __all__ = (
|
|||
'CallbackQuery',
|
||||
'Chat',
|
||||
'ChatActions',
|
||||
'ChatAdministratorRights',
|
||||
'ChatInviteLink',
|
||||
'ChatJoinRequest',
|
||||
'ChatLocation',
|
||||
|
|
@ -174,6 +184,10 @@ __all__ = (
|
|||
'Location',
|
||||
'LoginUrl',
|
||||
'MaskPosition',
|
||||
'MenuButton',
|
||||
'MenuButtonCommands',
|
||||
'MenuButtonWebApp',
|
||||
'MenuButtonDefault',
|
||||
'MediaGroup',
|
||||
'Message',
|
||||
'MessageAutoDeleteTimerChanged',
|
||||
|
|
@ -201,6 +215,7 @@ __all__ = (
|
|||
'ReplyKeyboardMarkup',
|
||||
'ReplyKeyboardRemove',
|
||||
'ResponseParameters',
|
||||
'SentWebAppMessage',
|
||||
'ShippingAddress',
|
||||
'ShippingOption',
|
||||
'ShippingQuery',
|
||||
|
|
@ -212,12 +227,18 @@ __all__ = (
|
|||
'UserProfilePhotos',
|
||||
'Venue',
|
||||
'Video',
|
||||
'VideoChatEnded',
|
||||
'VideoChatParticipantsInvited',
|
||||
'VideoChatScheduled',
|
||||
'VideoChatStarted',
|
||||
'VideoNote',
|
||||
'Voice',
|
||||
'VoiceChatEnded',
|
||||
'VoiceChatParticipantsInvited',
|
||||
'VoiceChatScheduled',
|
||||
'VoiceChatStarted',
|
||||
'WebAppData',
|
||||
'WebAppInfo',
|
||||
'WebhookInfo',
|
||||
'base',
|
||||
'fields',
|
||||
|
|
|
|||
21
aiogram/types/chat_administrator_rights.py
Normal file
21
aiogram/types/chat_administrator_rights.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
|
||||
|
||||
class ChatAdministratorRights(base.TelegramObject):
|
||||
"""
|
||||
Represents rights of an administrator in a chat.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#chatadministratorrights
|
||||
"""
|
||||
is_anonymous: base.Boolean = fields.Field()
|
||||
can_manage_chat: base.Boolean = fields.Field()
|
||||
can_delete_messages: base.Boolean = fields.Field()
|
||||
can_manage_video_chats: base.Boolean = fields.Field()
|
||||
can_restrict_members: base.Boolean = fields.Field()
|
||||
can_promote_members: base.Boolean = fields.Field()
|
||||
can_change_info: base.Boolean = fields.Field()
|
||||
can_invite_users: base.Boolean = fields.Field()
|
||||
can_post_messages: base.Boolean = fields.Field()
|
||||
can_edit_messages: base.Boolean = fields.Field()
|
||||
can_pin_messages: base.Boolean = fields.Field()
|
||||
|
|
@ -5,7 +5,6 @@ from . import base, fields
|
|||
from .user import User
|
||||
from ..utils import helper
|
||||
|
||||
|
||||
T = typing.TypeVar('T')
|
||||
|
||||
|
||||
|
|
@ -153,6 +152,7 @@ class ChatMemberAdministrator(ChatMember):
|
|||
can_edit_messages: base.Boolean = fields.Field()
|
||||
can_delete_messages: base.Boolean = fields.Field()
|
||||
can_manage_voice_chats: base.Boolean = fields.Field()
|
||||
can_manage_video_chats: base.Boolean = fields.Field()
|
||||
can_restrict_members: base.Boolean = fields.Field()
|
||||
can_promote_members: base.Boolean = fields.Field()
|
||||
can_change_info: base.Boolean = fields.Field()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from . import base
|
|||
from . import fields
|
||||
from .callback_game import CallbackGame
|
||||
from .login_url import LoginUrl
|
||||
from .web_app_info import WebAppInfo
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(base.TelegramObject):
|
||||
|
|
@ -95,6 +96,7 @@ class InlineKeyboardButton(base.TelegramObject):
|
|||
switch_inline_query_current_chat: base.String = fields.Field()
|
||||
callback_game: CallbackGame = fields.Field(base=CallbackGame)
|
||||
pay: base.Boolean = fields.Field()
|
||||
web_app: WebAppInfo = fields.Field(base=WebAppInfo)
|
||||
|
||||
def __init__(self, text: base.String,
|
||||
url: base.String = None,
|
||||
|
|
@ -103,7 +105,9 @@ class InlineKeyboardButton(base.TelegramObject):
|
|||
switch_inline_query: base.String = None,
|
||||
switch_inline_query_current_chat: base.String = None,
|
||||
callback_game: CallbackGame = None,
|
||||
pay: base.Boolean = None, **kwargs):
|
||||
pay: base.Boolean = None,
|
||||
web_app: WebAppInfo = None,
|
||||
**kwargs):
|
||||
super(InlineKeyboardButton, self).__init__(text=text,
|
||||
url=url,
|
||||
login_url=login_url,
|
||||
|
|
@ -111,4 +115,6 @@ class InlineKeyboardButton(base.TelegramObject):
|
|||
switch_inline_query=switch_inline_query,
|
||||
switch_inline_query_current_chat=switch_inline_query_current_chat,
|
||||
callback_game=callback_game,
|
||||
pay=pay, **kwargs)
|
||||
pay=pay,
|
||||
web_app=web_app,
|
||||
**kwargs)
|
||||
|
|
|
|||
86
aiogram/types/menu_button.py
Normal file
86
aiogram/types/menu_button.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import typing
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
from .web_app_info import WebAppInfo
|
||||
from ..utils import helper
|
||||
from ..utils.helper import Item
|
||||
|
||||
|
||||
class MenuButton(base.TelegramObject):
|
||||
"""
|
||||
This object describes the bot's menu button in a private chat. It should be one of
|
||||
|
||||
- MenuButtonCommands
|
||||
- MenuButtonWebApp
|
||||
- MenuButtonDefault
|
||||
|
||||
If a menu button other than 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.
|
||||
"""
|
||||
type: base.String = fields.Field(default='default')
|
||||
|
||||
@classmethod
|
||||
def resolve(cls, **kwargs) -> typing.Union[
|
||||
"MenuButtonCommands",
|
||||
"MenuButtonDefault",
|
||||
"MenuButtonWebApp",
|
||||
]:
|
||||
type_ = kwargs.get('type')
|
||||
mapping = {
|
||||
MenuButtonType.DEFAULT: MenuButtonDefault,
|
||||
MenuButtonType.COMMANDS: MenuButtonCommands,
|
||||
MenuButtonType.WEB_APP: MenuButtonWebApp,
|
||||
}
|
||||
class_ = mapping.get(type_)
|
||||
if not class_:
|
||||
raise ValueError(f'Unknown MenuButton type: {type_}')
|
||||
return class_(**kwargs)
|
||||
|
||||
|
||||
class MenuButtonCommands(MenuButton):
|
||||
"""
|
||||
Represents a menu button, which opens the bot's list of commands.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#menubuttoncommands
|
||||
"""
|
||||
type: base.String = fields.Field(default='commands')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(type='commands', **kwargs)
|
||||
|
||||
|
||||
class MenuButtonWebApp(MenuButton):
|
||||
"""
|
||||
Represents a menu button, which launches a Web App.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#menubuttonwebapp
|
||||
"""
|
||||
type: base.String = fields.Field(default='web_app')
|
||||
text: base.String = fields.Field()
|
||||
web_app: WebAppInfo = fields.Field(base=WebAppInfo)
|
||||
|
||||
def __init__(self, text: base.String, web_app: WebAppInfo, **kwargs):
|
||||
super().__init__(type='web_app', text=text, web_app=web_app, **kwargs)
|
||||
|
||||
|
||||
class MenuButtonDefault(MenuButton):
|
||||
"""
|
||||
Describes that no specific value for the menu button was set.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#menubuttondefault
|
||||
"""
|
||||
type: base.String = fields.Field(default='default')
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(type='default', **kwargs)
|
||||
|
||||
|
||||
class MenuButtonType(helper.Helper):
|
||||
mode = helper.HelperMode.lowercase
|
||||
|
||||
DEFAULT = Item()
|
||||
COMMANDS = Item()
|
||||
WEB_APP = Item()
|
||||
|
|
@ -30,12 +30,17 @@ from .successful_payment import SuccessfulPayment
|
|||
from .user import User
|
||||
from .venue import Venue
|
||||
from .video import Video
|
||||
from .video_chat_ended import VideoChatEnded
|
||||
from .video_chat_participants_invited import VideoChatParticipantsInvited
|
||||
from .video_chat_scheduled import VideoChatScheduled
|
||||
from .video_chat_started import VideoChatStarted
|
||||
from .video_note import VideoNote
|
||||
from .voice import Voice
|
||||
from .voice_chat_ended import VoiceChatEnded
|
||||
from .voice_chat_participants_invited import VoiceChatParticipantsInvited
|
||||
from .voice_chat_scheduled import VoiceChatScheduled
|
||||
from .voice_chat_started import VoiceChatStarted
|
||||
from .web_app_data import WebAppData
|
||||
from ..utils import helper
|
||||
from ..utils import markdown as md
|
||||
from ..utils.text_decorations import html_decoration, markdown_decoration
|
||||
|
|
@ -106,6 +111,11 @@ class Message(base.TelegramObject):
|
|||
voice_chat_ended: VoiceChatEnded = fields.Field(base=VoiceChatEnded)
|
||||
voice_chat_participants_invited: VoiceChatParticipantsInvited = fields.Field(base=VoiceChatParticipantsInvited)
|
||||
reply_markup: InlineKeyboardMarkup = fields.Field(base=InlineKeyboardMarkup)
|
||||
web_app_data: WebAppData = fields.Field(base=WebAppData)
|
||||
video_chat_scheduled: VideoChatScheduled = fields.Field(base=VideoChatScheduled)
|
||||
video_chat_started: VideoChatStarted = fields.Field(base=VideoChatStarted)
|
||||
video_chat_ended: VideoChatEnded = fields.Field(base=VideoChatEnded)
|
||||
video_chat_participants_invited: VideoChatParticipantsInvited = fields.Field(base=VideoChatParticipantsInvited)
|
||||
|
||||
@property
|
||||
@functools.lru_cache()
|
||||
|
|
@ -178,6 +188,16 @@ class Message(base.TelegramObject):
|
|||
return ContentType.VOICE_CHAT_ENDED
|
||||
if self.voice_chat_participants_invited:
|
||||
return ContentType.VOICE_CHAT_PARTICIPANTS_INVITED
|
||||
if self.web_app_data:
|
||||
return ContentType.WEB_APP_DATA
|
||||
if self.video_chat_scheduled:
|
||||
return ContentType.VIDEO_CHAT_SCHEDULED
|
||||
if self.video_chat_started:
|
||||
return ContentType.VIDEO_CHAT_STARTED
|
||||
if self.video_chat_ended:
|
||||
return ContentType.VIDEO_CHAT_ENDED
|
||||
if self.video_chat_participants_invited:
|
||||
return ContentType.VIDEO_CHAT_PARTICIPANTS_INVITED
|
||||
|
||||
return ContentType.UNKNOWN
|
||||
|
||||
|
|
@ -3247,6 +3267,11 @@ class ContentType(helper.Helper):
|
|||
VOICE_CHAT_STARTED = helper.Item() # voice_chat_started
|
||||
VOICE_CHAT_ENDED = helper.Item() # voice_chat_ended
|
||||
VOICE_CHAT_PARTICIPANTS_INVITED = helper.Item() # voice_chat_participants_invited
|
||||
WEB_APP_DATA = helper.Item() # web_app_data
|
||||
VIDEO_CHAT_SCHEDULED = helper.Item() # video_chat_scheduled
|
||||
VIDEO_CHAT_STARTED = helper.Item() # video_chat_started
|
||||
VIDEO_CHAT_ENDED = helper.Item() # video_chat_ended
|
||||
VIDEO_CHAT_PARTICIPANTS_INVITED = helper.Item() # video_chat_participants_invited
|
||||
|
||||
UNKNOWN = helper.Item() # unknown
|
||||
ANY = helper.Item() # any
|
||||
|
|
@ -3313,6 +3338,11 @@ class ContentTypes(helper.Helper):
|
|||
DELETE_CHAT_PHOTO = helper.ListItem() # delete_chat_photo
|
||||
GROUP_CHAT_CREATED = helper.ListItem() # group_chat_created
|
||||
PASSPORT_DATA = helper.ListItem() # passport_data
|
||||
WEB_APP_DATA = helper.Item() # web_app_data
|
||||
VIDEO_CHAT_SCHEDULED = helper.Item() # video_chat_scheduled
|
||||
VIDEO_CHAT_STARTED = helper.Item() # video_chat_started
|
||||
VIDEO_CHAT_ENDED = helper.Item() # video_chat_ended
|
||||
VIDEO_CHAT_PARTICIPANTS_INVITED = helper.Item() # video_chat_participants_invited
|
||||
|
||||
UNKNOWN = helper.ListItem() # unknown
|
||||
ANY = helper.ListItem() # any
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import typing
|
|||
|
||||
from . import base
|
||||
from . import fields
|
||||
from .web_app_info import WebAppInfo
|
||||
|
||||
|
||||
class KeyboardButtonPollType(base.TelegramObject):
|
||||
|
|
@ -117,16 +118,19 @@ class KeyboardButton(base.TelegramObject):
|
|||
request_contact: base.Boolean = fields.Field()
|
||||
request_location: base.Boolean = fields.Field()
|
||||
request_poll: KeyboardButtonPollType = fields.Field()
|
||||
web_app: WebAppInfo = fields.Field(base=WebAppInfo)
|
||||
|
||||
def __init__(self, text: base.String,
|
||||
request_contact: base.Boolean = None,
|
||||
request_location: base.Boolean = None,
|
||||
request_poll: KeyboardButtonPollType = None,
|
||||
web_app: WebAppInfo = None,
|
||||
**kwargs):
|
||||
super(KeyboardButton, self).__init__(text=text,
|
||||
request_contact=request_contact,
|
||||
request_location=request_location,
|
||||
request_poll=request_poll,
|
||||
web_app=web_app,
|
||||
**kwargs)
|
||||
|
||||
|
||||
|
|
|
|||
11
aiogram/types/sent_web_app_message.py
Normal file
11
aiogram/types/sent_web_app_message.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
|
||||
|
||||
class SentWebAppMessage(base.TelegramObject):
|
||||
"""
|
||||
Contains information about an inline message sent by a Web App on behalf of a user.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#sentwebappmessage
|
||||
"""
|
||||
inline_message_id: base.String = fields.Field()
|
||||
13
aiogram/types/video_chat_ended.py
Normal file
13
aiogram/types/video_chat_ended.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
from . import mixins
|
||||
|
||||
|
||||
class VideoChatEnded(base.TelegramObject, mixins.Downloadable):
|
||||
"""
|
||||
This object represents a service message about a video chat scheduled in the chat.
|
||||
|
||||
https://core.telegram.org/bots/api#videochatended
|
||||
"""
|
||||
|
||||
duration: base.Integer = fields.Field()
|
||||
16
aiogram/types/video_chat_participants_invited.py
Normal file
16
aiogram/types/video_chat_participants_invited.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import typing
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
from . import mixins
|
||||
from .user import User
|
||||
|
||||
|
||||
class VideoChatParticipantsInvited(base.TelegramObject, mixins.Downloadable):
|
||||
"""
|
||||
This object represents a service message about new members invited to a video chat.
|
||||
|
||||
https://core.telegram.org/bots/api#videochatparticipantsinvited
|
||||
"""
|
||||
|
||||
users: typing.List[User] = fields.ListField(base=User)
|
||||
14
aiogram/types/video_chat_scheduled.py
Normal file
14
aiogram/types/video_chat_scheduled.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from datetime import datetime
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
|
||||
|
||||
class VideoChatScheduled(base.TelegramObject):
|
||||
"""
|
||||
This object represents a service message about a video chat scheduled in the chat.
|
||||
|
||||
https://core.telegram.org/bots/api#videochatscheduled
|
||||
"""
|
||||
|
||||
start_date: datetime = fields.DateTimeField()
|
||||
11
aiogram/types/video_chat_started.py
Normal file
11
aiogram/types/video_chat_started.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from . import base
|
||||
from . import mixins
|
||||
|
||||
|
||||
class VideoChatStarted(base.TelegramObject, mixins.Downloadable):
|
||||
"""
|
||||
his object represents a service message about a video chat started in the chat. Currently holds no information.
|
||||
|
||||
https://core.telegram.org/bots/api#videochatstarted
|
||||
"""
|
||||
pass
|
||||
12
aiogram/types/web_app_data.py
Normal file
12
aiogram/types/web_app_data.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
|
||||
|
||||
class WebAppData(base.TelegramObject):
|
||||
"""
|
||||
Contains data sent from a Web App to the bot.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#webappdata
|
||||
"""
|
||||
data: str = fields.Field()
|
||||
button_text: str = fields.Field()
|
||||
11
aiogram/types/web_app_info.py
Normal file
11
aiogram/types/web_app_info.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from . import base
|
||||
from . import fields
|
||||
|
||||
|
||||
class WebAppInfo(base.TelegramObject):
|
||||
"""
|
||||
Contains information about a Web App.
|
||||
|
||||
Source: https://core.telegram.org/bots/api#webappinfo
|
||||
"""
|
||||
url: base.String = fields.Field()
|
||||
|
|
@ -18,3 +18,4 @@ class WebhookInfo(base.TelegramObject):
|
|||
last_error_message: base.String = fields.Field()
|
||||
max_connections: base.Integer = fields.Field()
|
||||
allowed_updates: typing.List[base.String] = fields.ListField()
|
||||
last_synchronization_error_date: base.Integer = fields.DateTimeField()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Welcome to aiogram's documentation!
|
|||
:target: https://pypi.python.org/pypi/aiogram
|
||||
:alt: Supported python versions
|
||||
|
||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-5.7-blue.svg?style=flat-square&logo=telegram
|
||||
.. image:: https://img.shields.io/badge/Telegram%20Bot%20API-6.0-blue.svg?style=flat-square&logo=telegram
|
||||
:target: https://core.telegram.org/bots/api
|
||||
:alt: Telegram Bot API
|
||||
|
||||
|
|
|
|||
22
test.html
Normal file
22
test.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<title>Hello, world!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, world!</h1>
|
||||
<div id="content">not inited</div>
|
||||
<button onclick="validateData()" type="button" class="btn btn-primary">Show</button>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="static/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue