mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add the class WebAppData
This commit is contained in:
parent
b645a75b93
commit
c44643faad
@ -407,6 +407,7 @@ def pyrogram_api():
|
||||
VideoChatStarted
|
||||
VideoChatEnded
|
||||
VideoChatMembersInvited
|
||||
WebAppData
|
||||
""",
|
||||
bot_keyboards="""
|
||||
Bot keyboards
|
||||
|
@ -68,3 +68,6 @@ class MessageService(AutoName):
|
||||
|
||||
VIDEO_CHAT_MEMBERS_INVITED = auto()
|
||||
"Video chat members invited"
|
||||
|
||||
WEB_APP_DATA = auto()
|
||||
"Web app data"
|
||||
|
@ -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"
|
||||
]
|
||||
|
@ -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
|
||||
)
|
||||
|
51
pyrogram/types/messages_and_media/web_app_data.py
Normal file
51
pyrogram/types/messages_and_media/web_app_data.py
Normal 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
|
||||
)
|
Loading…
Reference in New Issue
Block a user