Skip to main content
Glama

forward_message

Forward messages between Telegram chats by specifying source, destination, and message ID. Use this tool to share content across different conversations or channels.

Instructions

Forward an existing message from one chat to another.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
to_chat_idYes
from_chat_idYes
message_idYes
disable_notificationNo

Implementation Reference

  • The forward_message tool handler function, which forwards a message using the bot context and handles potential errors.
    async def forward_message(
        to_chat_id: int,
        from_chat_id: int,
        message_id: int,
        disable_notification: bool = False,
    ) -> ForwardMessageResult:
        """Forward an existing message from one chat to another."""
        if not ctx.is_chat_allowed(to_chat_id):
            result = ForwardMessageResult(
                ok=False, error=f"Chat {to_chat_id} is not allowed."
            )
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "forward_message",
                    {
                        "to_chat_id": to_chat_id,
                        "from_chat_id": from_chat_id,
                        "message_id": message_id,
                    },
                    result.ok,
                    result.error,
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            msg = await ctx.bot.forward_message(
                chat_id=to_chat_id,
                from_chat_id=from_chat_id,
                message_id=message_id,
                disable_notification=disable_notification,
            )
            result = ForwardMessageResult(ok=True, message_id=msg.message_id)
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = ForwardMessageResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "forward_message",
                {
                    "to_chat_id": to_chat_id,
                    "from_chat_id": from_chat_id,
                    "message_id": message_id,
                },
                result.ok,
                result.error,
            )
        return result
  • Data structure for the forward_message tool result.
    class ForwardMessageResult(ToolResponse):
        message_id: int | None = None
  • Registration check for the forward_message tool.
    if allowed_tools is None or "forward_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