Initial commit: VoIdeaAI - voice-first AI idea assistant
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""Telegram ↔ VoIdea account linking."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
from typing import Any
|
||||
|
||||
# In-memory store for link tokens (in production: Redis with TTL)
|
||||
_link_tokens: dict[str, int] = {} # token → user_id
|
||||
|
||||
|
||||
def create_link_token(user_id: int) -> str:
|
||||
"""Generate a one-time token for linking Telegram to VoIdea account."""
|
||||
token = secrets.token_urlsafe(32)
|
||||
_link_tokens[token] = user_id
|
||||
return token
|
||||
|
||||
|
||||
def consume_link_token(token: str) -> int | None:
|
||||
"""Validate and consume a link token. Returns user_id or None."""
|
||||
user_id = _link_tokens.pop(token, None)
|
||||
return user_id
|
||||
|
||||
|
||||
def get_bot_link_url(base_url: str, token: str) -> str:
|
||||
"""Return the URL for the user to confirm account linking."""
|
||||
return f"{base_url}/bot/link?token={token}"
|
||||
Reference in New Issue
Block a user