Skip to main content
Glama
prem-research

Telegram MCP Server

send_message

Send messages to Telegram entities with optional formatting and reply functionality.

Instructions

Send a message to an entity with optional markup and reply

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_idYes
contentNo
reply_to_message_idNo

Implementation Reference

  • MCP tool handler for 'send_message': proxies the message sending request to the HTTP API server via POST.
    @mcp.tool(
        name="send_message",
        description="Send a message to an entity with optional markup and reply",
    )
    async def send_message(
        entity_id: int | str,
        content: str = "",
        reply_to_message_id: int = None,
    ) -> dict:
        return post(
            f"{api_endpoint}send_message",
            json={
                "entity": entity_id,
                "content": content,
                "reply_to_message_id": reply_to_message_id,
            },
            headers={"Content-Type": "application/json"},
        ).json()
  • Pydantic input schema for the /send_message HTTP endpoint, matching the MCP tool parameters.
    class SendMessagePost(BaseModel):
        entity: int | str
        content: str
        reply_message_id: int = None
  • HTTP endpoint handler that performs the actual Telegram message sending using the Telethon client.
    @app.post("/send_message")
    async def send_message(post_msg: SendMessagePost):
        e_obj = await get_entity(entity=post_msg.entity, raw=True)
    
        message = await client.send_message(
            entity=e_obj,
            message=post_msg.content,
            reply_to=post_msg.reply_message_id,
            parse_mode="html",
        )
    
        if isinstance(message, types.Message) and message.id:
            return {"message_id": message.id}
        else:
            raise HTTPException(status_code=404, detail="Error sending message")

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/prem-research/telegram-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server