diff --git a/bot/telegram/handlers/welcome_handlers.py b/bot/telegram/handlers/welcome_handlers.py index a4fee06..ec35582 100644 --- a/bot/telegram/handlers/welcome_handlers.py +++ b/bot/telegram/handlers/welcome_handlers.py @@ -13,10 +13,10 @@ updateUserInitialised, updateUserCalloutCleared ) +from services.share_service import put_ctx # Import from utils from utils.message_templates import WELCOME_MESSAGE, HELP_MESSAGE -from utils.web_app import create_web_app_url # Import from other from urllib.parse import urlencode @@ -27,4 +27,27 @@ def register_welcome_handlers(bot): @bot.message_handler(commands=['help']) def help_command(message): - bot.reply_to(message, HELP_MESSAGE) + # Generate share token for dashboard access + chat_id = message.chat.id + thread_id = getattr(message, "message_thread_id", None) + user_id = message.from_user.id + placeholder_message_id = 0 + + token = put_ctx(user_id, chat_id, placeholder_message_id, thread_id) + + # Create dashboard button + markup = types.InlineKeyboardMarkup() + params = f"dashboard={token}" + mini_app_url = f"https://t.me/{bot.get_me().username}/meetwhenah?startapp={params}" + + dashboard_btn = types.InlineKeyboardButton( + text="Open Dashboard", + url=mini_app_url + ) + markup.add(dashboard_btn) + + if message.chat.type == 'private': + bot.reply_to(message, HELP_MESSAGE, reply_markup=markup) + else: + # In group chat, send help message without replying to the user's message + bot.send_message(message.chat.id, HELP_MESSAGE, reply_markup=markup) diff --git a/bot/utils/web_app.py b/bot/utils/web_app.py index 7061553..6fa6c0e 100644 --- a/bot/utils/web_app.py +++ b/bot/utils/web_app.py @@ -1,5 +1,5 @@ import os -from urllib.parse import urlencode +from urllib.parse import urlencode, urlparse def create_web_app_url(path: str, web_app_number: int = 1, **params) -> str: """ @@ -31,4 +31,15 @@ def create_web_app_url(path: str, web_app_number: int = 1, **params) -> str: if query_string: url = f"{url}?{query_string}" + # Validate the URL format + try: + parsed = urlparse(url) + if not parsed.scheme or not parsed.netloc: + raise ValueError("Invalid URL format") + except Exception as e: + # Fallback to a simple URL if validation fails + url = f"https://meet-when-ah.vercel.app/{path}" + if query_string: + url = f"{url}?{query_string}" + return url \ No newline at end of file