Skip to content

Commit eea8bec

Browse files
authored
Make WebAppData.data optional to support both WebViewDataSent actions (#290)
1 parent 5ebde1e commit eea8bec

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

pyrogram/types/messages_and_media/web_app_data.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from typing import Optional, Union
20+
1921
from pyrogram import raw
2022
from ..object import Object
2123

@@ -24,7 +26,7 @@ class WebAppData(Object):
2426
"""Contains data sent from a `Web App <https://core.telegram.org/bots/webapps>`_ to the bot.
2527
2628
Parameters:
27-
data (``str``):
29+
data (``str``, *optional*):
2830
The data.
2931
3032
button_text (``str``):
@@ -35,7 +37,7 @@ class WebAppData(Object):
3537
def __init__(
3638
self,
3739
*,
38-
data: str,
40+
data: Optional[str],
3941
button_text: str,
4042
):
4143
super().__init__()
@@ -44,8 +46,8 @@ def __init__(
4446
self.button_text = button_text
4547

4648
@staticmethod
47-
def _parse(action: "raw.types.MessageActionWebViewDataSentMe"):
49+
def _parse(action: Union["raw.types.MessageActionWebViewDataSent", "raw.types.MessageActionWebViewDataSentMe"]):
4850
return WebAppData(
49-
data=action.data,
51+
data=getattr(action, "data", None),
5052
button_text=action.text
5153
)

0 commit comments

Comments
 (0)