Add info if linked acc
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import logging
|
||||
|
||||
from aiogram import Router, F
|
||||
from aiogram import Router, F, Bot
|
||||
from aiogram.filters import CommandStart, Command, CommandObject
|
||||
from aiogram.types import Message
|
||||
|
||||
from config import settings
|
||||
from keyboards.main_menu import get_main_menu
|
||||
from services.api_client import api_client
|
||||
|
||||
@@ -11,6 +12,21 @@ logger = logging.getLogger(__name__)
|
||||
router = Router()
|
||||
|
||||
|
||||
async def get_user_avatar_url(bot: Bot, user_id: int) -> str | None:
|
||||
"""Get user's Telegram profile photo URL."""
|
||||
try:
|
||||
photos = await bot.get_user_profile_photos(user_id, limit=1)
|
||||
if photos.total_count > 0 and photos.photos:
|
||||
# Get the largest photo (last in the list)
|
||||
photo = photos.photos[0][-1]
|
||||
file = await bot.get_file(photo.file_id)
|
||||
if file.file_path:
|
||||
return f"https://api.telegram.org/file/bot{settings.TELEGRAM_BOT_TOKEN}/{file.file_path}"
|
||||
except Exception as e:
|
||||
logger.warning(f"[START] Could not get user avatar: {e}")
|
||||
return None
|
||||
|
||||
|
||||
@router.message(CommandStart())
|
||||
async def cmd_start(message: Message, command: CommandObject):
|
||||
"""Handle /start command with or without deep link."""
|
||||
@@ -26,16 +42,26 @@ async def cmd_start(message: Message, command: CommandObject):
|
||||
logger.info(f"[START] Token: {token}")
|
||||
logger.info(f"[START] Token length: {len(token)} chars")
|
||||
|
||||
# Get user's avatar
|
||||
avatar_url = await get_user_avatar_url(message.bot, message.from_user.id)
|
||||
logger.info(f"[START] User avatar URL: {avatar_url}")
|
||||
|
||||
logger.info(f"[START] -------- CALLING API --------")
|
||||
logger.info(f"[START] Sending to /telegram/confirm-link:")
|
||||
logger.info(f"[START] - token: {token}")
|
||||
logger.info(f"[START] - telegram_id: {message.from_user.id}")
|
||||
logger.info(f"[START] - telegram_username: {message.from_user.username}")
|
||||
logger.info(f"[START] - telegram_first_name: {message.from_user.first_name}")
|
||||
logger.info(f"[START] - telegram_last_name: {message.from_user.last_name}")
|
||||
logger.info(f"[START] - telegram_avatar_url: {avatar_url}")
|
||||
|
||||
result = await api_client.confirm_telegram_link(
|
||||
token=token,
|
||||
telegram_id=message.from_user.id,
|
||||
telegram_username=message.from_user.username
|
||||
telegram_username=message.from_user.username,
|
||||
telegram_first_name=message.from_user.first_name,
|
||||
telegram_last_name=message.from_user.last_name,
|
||||
telegram_avatar_url=avatar_url
|
||||
)
|
||||
|
||||
logger.info(f"[START] -------- API RESPONSE --------")
|
||||
|
||||
Reference in New Issue
Block a user