diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index be5c14bb..a626649d 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -407,6 +407,7 @@ def pyrogram_api(): VideoChatStarted VideoChatEnded VideoChatMembersInvited + WebAppData """, bot_keyboards=""" Bot keyboards diff --git a/pyrogram/enums/message_service.py b/pyrogram/enums/message_service.py index 7b23c730..636e6db5 100644 --- a/pyrogram/enums/message_service.py +++ b/pyrogram/enums/message_service.py @@ -68,3 +68,6 @@ class MessageService(AutoName): VIDEO_CHAT_MEMBERS_INVITED = auto() "Video chat members invited" + + WEB_APP_DATA = auto() + "Web app data" diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index cbed4f0f..e5ade1ea 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -37,9 +37,10 @@ from .video import Video from .video_note import VideoNote from .voice import Voice from .webpage import WebPage +from .web_app_data import WebAppData __all__ = [ "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", - "Reaction" + "Reaction", "WebAppData" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 7a5341fd..526839c9 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -285,6 +285,9 @@ class Message(Object, Update): video_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*): Service message: new members were invited to the voice chat. + web_app_data (:obj:`~pyrogram.types.WebAppData`, *optional*): + Service message: web app data sent to the bot. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardMarkup` | :obj:`~pyrogram.types.ReplyKeyboardRemove` | :obj:`~pyrogram.types.ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. @@ -366,6 +369,7 @@ class Message(Object, Update): video_chat_started: "types.VideoChatStarted" = None, video_chat_ended: "types.VideoChatEnded" = None, video_chat_members_invited: "types.VideoChatMembersInvited" = None, + web_app_data: "types.WebAppData" = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -441,6 +445,7 @@ class Message(Object, Update): self.video_chat_started = video_chat_started self.video_chat_ended = video_chat_ended self.video_chat_members_invited = video_chat_members_invited + self.web_app_data = web_app_data self.reactions = reactions @staticmethod @@ -491,6 +496,7 @@ class Message(Object, Update): video_chat_started = None video_chat_ended = None video_chat_members_invited = None + web_app_data = None service_type = None @@ -537,6 +543,9 @@ class Message(Object, Update): elif isinstance(action, raw.types.MessageActionInviteToGroupCall): video_chat_members_invited = types.VideoChatMembersInvited._parse(client, action, users) service_type = enums.MessageService.VIDEO_CHAT_MEMBERS_INVITED + elif isinstance(action, raw.types.MessageActionWebViewDataSentMe): + web_app_data = types.WebAppData._parse(action) + service_type = enums.MessageService.WEB_APP_DATA from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None @@ -561,6 +570,7 @@ class Message(Object, Update): video_chat_started=video_chat_started, video_chat_ended=video_chat_ended, video_chat_members_invited=video_chat_members_invited, + web_app_data=web_app_data, client=client # TODO: supergroup_chat_created ) diff --git a/pyrogram/types/messages_and_media/web_app_data.py b/pyrogram/types/messages_and_media/web_app_data.py new file mode 100644 index 00000000..b9a471fd --- /dev/null +++ b/pyrogram/types/messages_and_media/web_app_data.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 . + +from pyrogram import raw +from ..object import Object + + +class WebAppData(Object): + """Contains data sent from a `Web App `_ to the bot. + + Parameters: + data (``str``): + The data. + + button_text (``str``): + Text of the *web_app* keyboard button, from which the Web App was opened. + + """ + + def __init__( + self, + *, + data: str, + button_text: str, + ): + super().__init__() + + self.data = data + self.button_text = button_text + + @staticmethod + def _parse(action: "raw.types.MessageActionWebViewDataSentMe"): + return WebAppData( + data=action.data, + button_text=action.text + )