Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions bot/telegram/handlers/welcome_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
13 changes: 12 additions & 1 deletion bot/utils/web_app.py
Original file line number Diff line number Diff line change
@@ -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:
"""
Expand Down Expand Up @@ -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