Telegram send text
tg_send_messageSend text or markdown messages to a Telegram chat using a bot. Specify chat ID, parse mode, and reply to message ID.
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 core handler function for the tg_send_message tool. It sends a text/markdown message via a Telegram bot, supporting optional parse_mode (MarkdownV2) and reply_to_message_id parameters. It returns the Telegram API response 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-44 (schema)Input parameters (text, chat_id, parse_mode, reply_to_message_id) are defined using Pydantic Field descriptors directly in the function signature, serving as the schema for validation.
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:24-27 (registration)The tool is registered with FastMCP via the @mcp.tool() decorator with title 'Telegram send text' and description 'Send text or markdown message via telegram bot'.
@mcp.tool( title="Telegram send text", description="Send text or markdown message via telegram bot", ) - mcp_notify/tgbot.py:16-21 (helper)The add_tools function is the module-level entry point that receives the FastMCP instance and registers all Telegram bot tools. It also initializes the Bot client with environment variables.
def add_tools(mcp: FastMCP, logger=None): bot = Bot( TELEGRAM_BOT_TOKEN, base_url=f"{TELEGRAM_BASE_URL}/bot", base_file_url=f"{TELEGRAM_BASE_URL}/file/bot", ) if TELEGRAM_BOT_TOKEN else None - mcp_notify/__init__.py:19-23 (registration)Top-level registration: tgbot.add_tools(mcp) is called in __init__.py to wire up the module's tools onto the FastMCP server.
wework.add_tools(mcp) tgbot.add_tools(mcp) other.add_tools(mcp) hass.add_tools(mcp) util.add_tools(mcp)