85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
"""Telegram bot command handlers.
|
|
|
|
Registered via @bot_command decorator for auto-discovery.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from app.integrations.telegram.auth import create_link_token, get_bot_link_url
|
|
from app.integrations.telegram.decorators import bot_command
|
|
from app.integrations.telegram.client import TelegramBotClient
|
|
|
|
logger = logging.getLogger("voidea.telegram.handlers")
|
|
|
|
_bot_client: TelegramBotClient | None = None
|
|
|
|
|
|
def set_bot_client(client: TelegramBotClient) -> None:
|
|
global _bot_client
|
|
_bot_client = client
|
|
|
|
|
|
@bot_command(name="/start", description="Welcome message and getting started")
|
|
async def cmd_start(update: dict[str, Any], context: dict[str, Any]) -> str:
|
|
user = update.get("message", {}).get("from", {})
|
|
first_name = user.get("first_name", "User")
|
|
return (
|
|
f"Hello, {first_name}! 👋\n\n"
|
|
"I'm VoIdeaAI bot. Here's what I can do:\n"
|
|
"/link — Link your Telegram to VoIdea account\n"
|
|
"/idea — Create a new idea (requires linking)\n"
|
|
"/help — Show available commands"
|
|
)
|
|
|
|
|
|
@bot_command(name="/help", description="Show available commands")
|
|
async def cmd_help(update: dict[str, Any], context: dict[str, Any]) -> str:
|
|
return (
|
|
"Available commands:\n"
|
|
"/start — Welcome message\n"
|
|
"/link — Link Telegram to your VoIdea account\n"
|
|
"/idea — Create a new idea from text\n"
|
|
"/help — This message\n\n"
|
|
"To get started, use /link to connect your account."
|
|
)
|
|
|
|
|
|
@bot_command(name="/link", description="Link Telegram to your VoIdea account")
|
|
async def cmd_link(update: dict[str, Any], context: dict[str, Any]) -> str:
|
|
user_id = update.get("message", {}).get("from", {}).get("id")
|
|
if not user_id:
|
|
return "Error: could not identify you."
|
|
|
|
token = create_link_token(int(user_id))
|
|
base_url = context.get("base_url", "https://voidea.ai")
|
|
link_url = get_bot_link_url(base_url, token)
|
|
return (
|
|
"To link your Telegram account to VoIdea:\n\n"
|
|
f"1. Open this link: {link_url}\n"
|
|
"2. Confirm the pairing\n"
|
|
"3. Come back and use /idea to create ideas\n\n"
|
|
"The link expires in 30 minutes."
|
|
)
|
|
|
|
|
|
@bot_command(name="/idea", description="Create a new idea (requires linking)")
|
|
async def cmd_idea(update: dict[str, Any], context: dict[str, Any]) -> str:
|
|
text = update.get("message", {}).get("text", "")
|
|
args = text.replace("/idea", "", 1).strip()
|
|
|
|
if not args:
|
|
return (
|
|
"Usage: /idea <your idea text>\n\n"
|
|
"Example: /idea A mobile app for tracking daily water intake\n\n"
|
|
"You need to link your account first with /link."
|
|
)
|
|
|
|
return (
|
|
f"Idea received: \"{args[:200]}\"\n\n"
|
|
"To save it permanently, link your account with /link first.\n"
|
|
"After linking, your ideas will appear in your VoIdea dashboard."
|
|
)
|