Skip to main content
Glama

send_photo

Send photos to Telegram chats using URLs, with optional captions and notification settings for bot integration.

Instructions

Send a photo to a Telegram chat.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes
photo_urlYes
captionNo
parse_modeNoHTML
disable_notificationNo

Implementation Reference

  • The handler function `send_photo` that uses aiogram's bot API to send a photo to a chat.
    async def send_photo(
        chat_id: int,
        photo_url: str,
        caption: str | None = None,
        parse_mode: str | None = "HTML",
        disable_notification: bool = False,
    ) -> SendPhotoResult:
        """Send a photo to a Telegram chat."""
        if not ctx.is_chat_allowed(chat_id):
            result = SendPhotoResult(ok=False, error=f"Chat {chat_id} is not allowed.")
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "send_photo",
                    {"chat_id": chat_id, "photo_url": photo_url},
                    result.ok,
                    result.error,
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            msg = await ctx.bot.send_photo(
                chat_id=chat_id,
                photo=photo_url,
                caption=caption,
                parse_mode=normalize_parse_mode(parse_mode),
                disable_notification=disable_notification,
            )
            result = SendPhotoResult(ok=True, message_id=msg.message_id, chat_id=msg.chat.id)
        except ValueError as exc:
            result = SendPhotoResult(ok=False, error=str(exc))
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = SendPhotoResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "send_photo",
                {"chat_id": chat_id, "photo_url": photo_url},
                result.ok,
                result.error,
            )
        return result
  • The response schema for the send_photo tool.
    class SendPhotoResult(ToolResponse):
        message_id: int | None = None
        chat_id: int | None = None
  • Conditional registration logic for the send_photo tool within the register_messaging_tools function.
    if allowed_tools is None or "send_photo" 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