Skip to main content
Glama

send_message

Send text messages to Telegram chats or users through aiogram-mcp server, supporting message formatting, notifications, and replies.

Instructions

Send a text message to a Telegram chat or user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes
textYes
parse_modeNoHTML
disable_notificationNo
reply_to_message_idNo

Implementation Reference

  • The handler implementation for the `send_message` tool.
    async def send_message(
        chat_id: int,
        text: str,
        parse_mode: str | None = "HTML",
        disable_notification: bool = False,
        reply_to_message_id: int | None = None,
    ) -> SendMessageResult:
        """Send a text message to a Telegram chat or user."""
        if not ctx.is_chat_allowed(chat_id):
            result = SendMessageResult(
                ok=False,
                error=f"Chat {chat_id} is not in the allowed_chat_ids whitelist.",
            )
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "send_message", {"chat_id": chat_id, "text": text}, result.ok, result.error
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            msg = await ctx.bot.send_message(
                chat_id=chat_id,
                text=text,
                parse_mode=normalize_parse_mode(parse_mode),
                disable_notification=disable_notification,
                reply_parameters=(
                    ReplyParameters(message_id=reply_to_message_id)
                    if reply_to_message_id is not None
                    else None
                ),
            )
            result = SendMessageResult(
                ok=True,
                message_id=msg.message_id,
                chat_id=msg.chat.id,
                date=msg.date.isoformat(),
            )
        except ValueError as exc:
            result = SendMessageResult(ok=False, error=str(exc))
        except TelegramForbiddenError:
            result = SendMessageResult(
                ok=False, error="Bot was blocked by the user or lacks permission."
            )
        except TelegramBadRequest as exc:
            result = SendMessageResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "send_message", {"chat_id": chat_id, "text": text}, result.ok, result.error
            )
        return result
  • Result schema for the `send_message` tool.
    class SendMessageResult(ToolResponse):
        message_id: int | None = None
        chat_id: int | None = None
        date: str | None = None
  • Registration logic for the `send_message` tool within `register_messaging_tools`.
    def register_messaging_tools(
        mcp: FastMCP, ctx: BotContext, allowed_tools: set[str] | None = None
    ) -> None:
        if allowed_tools is None or "send_message" 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