Telegram send text
tg_send_messageSend text or markdown messages to Telegram chats via bot. Specify chat ID, parse mode, and optional reply-to message.
Instructions
Send text or markdown message via telegram bot
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text of the message to be sent, 1-4096 characters after entities parsing | |
| chat_id | No | Telegram chat id, Default to get from environment variables | |
| parse_mode | No | Mode for parsing entities in the message text. [text/MarkdownV2] | |
| reply_to_message_id | No | Identifier of the message that will be replied to |
Implementation Reference
- mcp_notify/tgbot.py:28-44 (handler)The tg_send_message async function that sends a text/markdown message via Telegram bot. It handles markdown conversion via telegramify_markdown and delegates to bot.send_message(), returning the result as JSON.
async def tg_send_message( text: str = Field(description="Text of the message to be sent, 1-4096 characters after entities parsing"), chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"), parse_mode: str = Field("", description=f"Mode for parsing entities in the message text. [text/MarkdownV2]"), reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"), ): if not bot: return "Please set the `TELEGRAM_BOT_TOKEN` environment variable" if parse_mode == TELEGRAM_MARKDOWN_V2: text = telegramify_markdown.markdownify(text) res = await bot.send_message( chat_id=chat_id or TELEGRAM_DEFAULT_CHAT, text=text, parse_mode=parse_mode if parse_mode in [TELEGRAM_MARKDOWN_V2] else None, reply_to_message_id=reply_to_message_id or None, ) return res.to_json() - mcp_notify/tgbot.py:28-33 (schema)The function signature and pydantic Field definitions serve as the input schema: text (str, required), chat_id (str, default ''), parse_mode (str, default ''), reply_to_message_id (int, default 0).
async def tg_send_message( text: str = Field(description="Text of the message to be sent, 1-4096 characters after entities parsing"), chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"), parse_mode: str = Field("", description=f"Mode for parsing entities in the message text. [text/MarkdownV2]"), reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"), ): - mcp_notify/tgbot.py:24-44 (registration)The tool is registered via the @mcp.tool() decorator with title='Telegram send text' and description='Send text or markdown message via telegram bot' inside the add_tools() function.
@mcp.tool( title="Telegram send text", description="Send text or markdown message via telegram bot", ) async def tg_send_message( text: str = Field(description="Text of the message to be sent, 1-4096 characters after entities parsing"), chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"), parse_mode: str = Field("", description=f"Mode for parsing entities in the message text. [text/MarkdownV2]"), reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"), ): if not bot: return "Please set the `TELEGRAM_BOT_TOKEN` environment variable" if parse_mode == TELEGRAM_MARKDOWN_V2: text = telegramify_markdown.markdownify(text) res = await bot.send_message( chat_id=chat_id or TELEGRAM_DEFAULT_CHAT, text=text, parse_mode=parse_mode if parse_mode in [TELEGRAM_MARKDOWN_V2] else None, reply_to_message_id=reply_to_message_id or None, ) return res.to_json() - mcp_notify/__init__.py:20-23 (registration)The tgbot.add_tools(mcp) call in __init__.py is the top-level registration that wires up all Telegram tools (including tg_send_message) into the FastMCP server.
tgbot.add_tools(mcp) other.add_tools(mcp) hass.add_tools(mcp) util.add_tools(mcp)