Skip to main content
Glama

get_user_profile_photos

Retrieve Telegram user profile photo file IDs for bot integration, enabling avatar display or storage in aiogram applications.

Instructions

Return a lightweight list of Telegram profile photo file IDs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idYes
limitNo

Implementation Reference

  • Implementation of the get_user_profile_photos MCP tool handler.
    async def get_user_profile_photos(
        user_id: int, limit: int = 5
    ) -> UserProfilePhotosResult:
        """Return a lightweight list of Telegram profile photo file IDs."""
        if limit < 1 or limit > 100:
            result = UserProfilePhotosResult(
                ok=False, error="limit must be between 1 and 100."
            )
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "get_user_profile_photos",
                    {"user_id": user_id, "limit": limit},
                    result.ok,
                    result.error,
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            photos = await ctx.bot.get_user_profile_photos(user_id=user_id, limit=limit)
            result = UserProfilePhotosResult(
                ok=True,
                user_id=user_id,
                total_count=photos.total_count,
                photos=[
                    [
                        {
                            "file_id": size.file_id,
                            "file_unique_id": size.file_unique_id,
                            "width": size.width,
                            "height": size.height,
                            "file_size": size.file_size,
                        }
                        for size in group
                    ]
                    for group in photos.photos
                ],
            )
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = UserProfilePhotosResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "get_user_profile_photos",
                {"user_id": user_id, "limit": limit},
                result.ok,
                result.error,
            )
        return result
  • Result schema for get_user_profile_photos tool.
    class UserProfilePhotosResult(ToolResponse):
        user_id: int | None = None
        total_count: int | None = None
        photos: list[list[dict[str, Any]]] | None = None
  • Registration condition for get_user_profile_photos tool within register_user_tools.
    if allowed_tools is None or "get_user_profile_photos" in allowed_tools:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Py2755/aiogram-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server