In app simulatro for steward
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bfdb76b496
commit
aa5c6ee1f0
@ -4,6 +4,11 @@ import logging
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Bot, Message
|
||||
|
||||
try:
|
||||
from telegram import WebAppInfo
|
||||
except Exception: # pragma: no cover - optional dependency in older PTB
|
||||
WebAppInfo = None
|
||||
from telegram.error import TelegramError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -15,6 +20,7 @@ def _build_keyboard(buttons: Optional[List[dict]]) -> Optional[InlineKeyboardMar
|
||||
|
||||
Supported kinds:
|
||||
- open_url: {"label":"...", "kind":"open_url", "url":"https://..."}
|
||||
- web_app: {"label":"...", "kind":"web_app", "url":"https://..."}
|
||||
- callback_api: {"label":"...", "kind":"callback_api", "action":"rerun",
|
||||
"params": {...}, "state_token":"..."}
|
||||
"""
|
||||
@ -35,6 +41,16 @@ def _build_keyboard(buttons: Optional[List[dict]]) -> Optional[InlineKeyboardMar
|
||||
continue
|
||||
btn = InlineKeyboardButton(text=label, url=url)
|
||||
|
||||
elif kind == "web_app":
|
||||
url = b.get("url")
|
||||
if not url:
|
||||
logger.warning("renderer: web_app without url; skipping")
|
||||
continue
|
||||
if WebAppInfo is None:
|
||||
btn = InlineKeyboardButton(text=label, url=url)
|
||||
else:
|
||||
btn = InlineKeyboardButton(text=label, web_app=WebAppInfo(url=url))
|
||||
|
||||
elif kind == "callback_api":
|
||||
# Keep callback_data tiny; prefer server-issued state_token.
|
||||
if b.get("state_token"):
|
||||
|
||||
@ -257,7 +257,13 @@ def steward_handle(request: HttpRequest):
|
||||
f"Power window: {remaining}h\n"
|
||||
f"Simulation: {sim_url}"
|
||||
)
|
||||
return _render_text(text, buttons=[{"label": "Open Simulation", "kind": "open_url", "url": sim_url}])
|
||||
return _render_text(
|
||||
text,
|
||||
buttons=[
|
||||
{"label": "Open Simulation", "kind": "web_app", "url": sim_url},
|
||||
{"label": "Open in Browser", "kind": "open_url", "url": sim_url},
|
||||
],
|
||||
)
|
||||
|
||||
if cmd == "bless":
|
||||
if steward.status != Stewardship.STATUS_ACTIVE or not steward.geohash:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user