uploader-bot/app/core/_utils/share_links.py

25 lines
804 B
Python

from typing import Optional
from urllib.parse import urlencode
STARTAPP_SEPARATOR = '!'
STARTAPP_LIMIT = 64
def build_content_links(content_token: str, ref_id: Optional[str], *, project_host: str, bot_username: str):
"""Return tuple of (startapp_payload, telegram_url, web_url)."""
payload = content_token
short_ref = (ref_id or '').strip()[:3]
if short_ref:
candidate = f"{content_token}{STARTAPP_SEPARATOR}{short_ref}"
if len(candidate) <= STARTAPP_LIMIT:
payload = candidate
telegram_url = f"https://t.me/{bot_username}/content?startapp={payload}"
query = [('content', content_token)]
if ref_id:
query.append(('ref', ref_id))
web_url = f"{project_host}/viewContent?{urlencode(query)}"
return payload, telegram_url, web_url