Skip to main content
Glama

send_interactive_message

Send Telegram messages with interactive inline keyboard buttons for user responses and actions.

Instructions

Send a message with inline keyboard buttons.

Args: chat_id: Target chat ID. text: Message text. buttons: Rows of buttons. Each button: {"text": "Label", "callback_data": "value"} or {"text": "Label", "url": "https://..."}. parse_mode: HTML, Markdown, MarkdownV2, or None. disable_notification: Send silently.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes
textYes
buttonsYes
parse_modeNoHTML
disable_notificationNo

Implementation Reference

  • The handler function for send_interactive_message which sends a message with an inline keyboard to a Telegram chat.
    async def send_interactive_message(
        chat_id: int,
        text: str,
        buttons: list[list[dict[str, str]]],
        parse_mode: str | None = "HTML",
        disable_notification: bool = False,
    ) -> SendInteractiveResult:
        """Send a message with inline keyboard buttons.
    
        Args:
            chat_id: Target chat ID.
            text: Message text.
            buttons: Rows of buttons. Each button: {"text": "Label", "callback_data": "value"}
                     or {"text": "Label", "url": "https://..."}.
            parse_mode: HTML, Markdown, MarkdownV2, or None.
            disable_notification: Send silently.
        """
        if not ctx.is_chat_allowed(chat_id):
            result = SendInteractiveResult(
                ok=False,
                error=f"Chat {chat_id} is not in allowed_chat_ids.",
            )
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "send_interactive_message",
                    {"chat_id": chat_id, "text": text},
                    result.ok,
                    result.error,
                )
            return result
    
        keyboard = _build_keyboard(buttons)
        if isinstance(keyboard, str):
            result = SendInteractiveResult(ok=False, error=keyboard)
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "send_interactive_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),
                reply_markup=keyboard,
                disable_notification=disable_notification,
            )
            result = SendInteractiveResult(
                ok=True,
                message_id=msg.message_id,
                chat_id=msg.chat.id,
                date=msg.date.isoformat(),
            )
        except ValueError as exc:
            result = SendInteractiveResult(ok=False, error=str(exc))
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = SendInteractiveResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "send_interactive_message",
                {"chat_id": chat_id, "text": text},
                result.ok,
                result.error,
            )
        return result
  • Schema definition for the result of send_interactive_message.
    class SendInteractiveResult(ToolResponse):
        message_id: int | None = None
        chat_id: int | None = None
        date: str | None = None
  • Tool registration logic for send_interactive_message.
    def register_interactive_tools(
        mcp: FastMCP, ctx: BotContext, allowed_tools: set[str] | None = None
    ) -> None:
        if allowed_tools is None or "send_interactive_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