edit_message
Modify existing Telegram message text or inline keyboard by specifying chat ID, message ID, and new content. Update messages without deleting and reposting them.
Instructions
Edit the text and/or inline keyboard of an existing message.
Args: chat_id: Chat containing the message. message_id: ID of the message to edit. text: New message text. buttons: New inline keyboard (None to remove buttons). parse_mode: HTML, Markdown, MarkdownV2, or None.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chat_id | Yes | ||
| message_id | Yes | ||
| text | Yes | ||
| buttons | No | ||
| parse_mode | No | HTML |
Implementation Reference
- aiogram_mcp/tools/interactive.py:140-215 (handler)The implementation of the `edit_message` tool.
async def edit_message( chat_id: int, message_id: int, text: str, buttons: list[list[dict[str, str]]] | None = None, parse_mode: str | None = "HTML", ) -> EditMessageResult: """Edit the text and/or inline keyboard of an existing message. Args: chat_id: Chat containing the message. message_id: ID of the message to edit. text: New message text. buttons: New inline keyboard (None to remove buttons). parse_mode: HTML, Markdown, MarkdownV2, or None. """ if not ctx.is_chat_allowed(chat_id): result = EditMessageResult( ok=False, error=f"Chat {chat_id} is not in allowed_chat_ids.", ) if ctx.audit_logger: ctx.audit_logger.log( "edit_message", {"chat_id": chat_id, "message_id": message_id, "text": text}, result.ok, result.error, ) return result reply_markup = None if buttons is not None: keyboard = _build_keyboard(buttons) if isinstance(keyboard, str): result = EditMessageResult(ok=False, error=keyboard) if ctx.audit_logger: ctx.audit_logger.log( "edit_message", {"chat_id": chat_id, "message_id": message_id, "text": text}, result.ok, result.error, ) return result reply_markup = keyboard try: if ctx.rate_limiter: await ctx.rate_limiter.acquire() api_result = await ctx.bot.edit_message_text( chat_id=chat_id, message_id=message_id, text=text, parse_mode=normalize_parse_mode(parse_mode), reply_markup=reply_markup, ) if isinstance(api_result, bool): result = EditMessageResult(ok=True, message_id=message_id, chat_id=chat_id) else: result = EditMessageResult( ok=True, message_id=api_result.message_id, chat_id=api_result.chat.id, ) except ValueError as exc: result = EditMessageResult(ok=False, error=str(exc)) except (TelegramBadRequest, TelegramForbiddenError) as exc: result = EditMessageResult(ok=False, error=str(exc)) if ctx.audit_logger: ctx.audit_logger.log( "edit_message", {"chat_id": chat_id, "message_id": message_id, "text": text}, result.ok, result.error, ) return result - The return type schema for `edit_message`.
class EditMessageResult(ToolResponse): message_id: int | None = None chat_id: int | None = None - aiogram_mcp/tools/interactive.py:137-137 (registration)Conditional registration of the edit_message tool.
if allowed_tools is None or "edit_message" in allowed_tools: