Add the class WebAppData

This commit is contained in:
Dan 2022-04-24 11:56:07 +02:00
parent b645a75b93
commit c44643faad
5 changed files with 67 additions and 1 deletions

View File

@ -407,6 +407,7 @@ def pyrogram_api():
VideoChatStarted VideoChatStarted
VideoChatEnded VideoChatEnded
VideoChatMembersInvited VideoChatMembersInvited
WebAppData
""", """,
bot_keyboards=""" bot_keyboards="""
Bot keyboards Bot keyboards

View File

@ -68,3 +68,6 @@ class MessageService(AutoName):
VIDEO_CHAT_MEMBERS_INVITED = auto() VIDEO_CHAT_MEMBERS_INVITED = auto()
"Video chat members invited" "Video chat members invited"
WEB_APP_DATA = auto()
"Web app data"

View File

@ -37,9 +37,10 @@ from .video import Video
from .video_note import VideoNote from .video_note import VideoNote
from .voice import Voice from .voice import Voice
from .webpage import WebPage from .webpage import WebPage
from .web_app_data import WebAppData
__all__ = [ __all__ = [
"Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail", "Animation", "Audio", "Contact", "Document", "Game", "Location", "Message", "MessageEntity", "Photo", "Thumbnail",
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "StrippedThumbnail", "Poll", "PollOption", "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice",
"Reaction" "Reaction", "WebAppData"
] ]

View File

@ -285,6 +285,9 @@ class Message(Object, Update):
video_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*): video_chat_members_invited (:obj:`~pyrogram.types.VoiceChatParticipantsInvited`, *optional*):
Service message: new members were invited to the voice chat. 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*): 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, 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. 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_started: "types.VideoChatStarted" = None,
video_chat_ended: "types.VideoChatEnded" = None, video_chat_ended: "types.VideoChatEnded" = None,
video_chat_members_invited: "types.VideoChatMembersInvited" = None, video_chat_members_invited: "types.VideoChatMembersInvited" = None,
web_app_data: "types.WebAppData" = None,
reply_markup: Union[ reply_markup: Union[
"types.InlineKeyboardMarkup", "types.InlineKeyboardMarkup",
"types.ReplyKeyboardMarkup", "types.ReplyKeyboardMarkup",
@ -441,6 +445,7 @@ class Message(Object, Update):
self.video_chat_started = video_chat_started self.video_chat_started = video_chat_started
self.video_chat_ended = video_chat_ended self.video_chat_ended = video_chat_ended
self.video_chat_members_invited = video_chat_members_invited self.video_chat_members_invited = video_chat_members_invited
self.web_app_data = web_app_data
self.reactions = reactions self.reactions = reactions
@staticmethod @staticmethod
@ -491,6 +496,7 @@ class Message(Object, Update):
video_chat_started = None video_chat_started = None
video_chat_ended = None video_chat_ended = None
video_chat_members_invited = None video_chat_members_invited = None
web_app_data = None
service_type = None service_type = None
@ -537,6 +543,9 @@ class Message(Object, Update):
elif isinstance(action, raw.types.MessageActionInviteToGroupCall): elif isinstance(action, raw.types.MessageActionInviteToGroupCall):
video_chat_members_invited = types.VideoChatMembersInvited._parse(client, action, users) video_chat_members_invited = types.VideoChatMembersInvited._parse(client, action, users)
service_type = enums.MessageService.VIDEO_CHAT_MEMBERS_INVITED 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)) 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 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_started=video_chat_started,
video_chat_ended=video_chat_ended, video_chat_ended=video_chat_ended,
video_chat_members_invited=video_chat_members_invited, video_chat_members_invited=video_chat_members_invited,
web_app_data=web_app_data,
client=client client=client
# TODO: supergroup_chat_created # TODO: supergroup_chat_created
) )

View File

@ -0,0 +1,51 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.
from pyrogram import raw
from ..object import Object
class WebAppData(Object):
"""Contains data sent from a `Web App <https://core.telegram.org/bots/webapps>`_ 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
)