mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
[3.x] Bot API 6.0 (#890)
* Base implementation * Bump license * Revert re-generated tests * Fix tests, improved docs * Remove TODO * Removed unreachable code * Changed type of `last_synchronization_error_date` * Fixed wrongly cleaned code
This commit is contained in:
parent
286cf39c8a
commit
497436595d
81 changed files with 1942 additions and 147 deletions
64
examples/web_app/routes.py
Normal file
64
examples/web_app/routes.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
from pathlib import Path
|
||||
|
||||
from aiohttp.web_fileresponse import FileResponse
|
||||
from aiohttp.web_request import Request
|
||||
from aiohttp.web_response import json_response
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.types import (
|
||||
InlineKeyboardButton,
|
||||
InlineKeyboardMarkup,
|
||||
InlineQueryResultArticle,
|
||||
InputTextMessageContent,
|
||||
WebAppInfo,
|
||||
)
|
||||
from aiogram.utils.web_app import check_webapp_signature, safe_parse_webapp_init_data
|
||||
|
||||
|
||||
async def demo_handler(request: Request):
|
||||
return FileResponse(Path(__file__).parent.resolve() / "demo.html")
|
||||
|
||||
|
||||
async def check_data_handler(request: Request):
|
||||
bot: Bot = request.app["bot"]
|
||||
|
||||
data = await request.post()
|
||||
if check_webapp_signature(bot.token, data["_auth"]):
|
||||
return json_response({"ok": True})
|
||||
return json_response({"ok": False, "err": "Unauthorized"}, status=401)
|
||||
|
||||
|
||||
async def send_message_handler(request: Request):
|
||||
bot: Bot = request.app["bot"]
|
||||
data = await request.post()
|
||||
try:
|
||||
web_app_init_data = safe_parse_webapp_init_data(token=bot.token, init_data=data["_auth"])
|
||||
except ValueError:
|
||||
return json_response({"ok": False, "err": "Unauthorized"}, status=401)
|
||||
|
||||
print(data)
|
||||
reply_markup = None
|
||||
if data["with_webview"] == "1":
|
||||
reply_markup = InlineKeyboardMarkup(
|
||||
inline_keyboard=[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="Open",
|
||||
web_app=WebAppInfo(url=str(request.url.with_scheme("https"))),
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
await bot.answer_web_app_query(
|
||||
web_app_query_id=web_app_init_data.query_id,
|
||||
result=InlineQueryResultArticle(
|
||||
id=web_app_init_data.query_id,
|
||||
title="Demo",
|
||||
input_message_content=InputTextMessageContent(
|
||||
message_text="Hello, World!",
|
||||
parse_mode=None,
|
||||
),
|
||||
reply_markup=reply_markup,
|
||||
),
|
||||
)
|
||||
return json_response({"ok": True})
|
||||
Loading…
Add table
Add a link
Reference in a new issue