claude-plugins-official/external_plugins/telegram/README.md at main · anthropics/claude-plugins-official

Open original

This guide explains how to set up a Telegram bot with Claude Code using an MCP server. It covers creating a bot through BotFather, installing the necessary plugin, and the steps to configure and pair the bot with your Claude session.

  • Setting up requires creating a bot via BotFather, installing the plugin, and running `/telegram:configure` with the token to write it into the environment file.
  • Multiple bot instances need separate `TELEGRAM_STATE_DIR` values to avoid conflicts.
  • Pairing works by DMing the bot for a 6-character code, then running `/telegram:access pair <code>` in Claude Code, avoiding the need for numeric user IDs.
  • The bot can reply, react with emoji, and edit its own messages, but has no access to message history—only real-time interaction.

To connect a Telegram bot with Claude Code using an MCP server, you start by creating a bot through Telegram's BotFather. This involves sending the command `/newbot` to BotFather, who prompts you for a display name and a unique username ending with "bot." Once created, you'll receive a token, which is essential for the bot to communicate with Claude Code. After setting up the bot, you need to install the Telegram plugin in your Claude Code session. Use the command `/plugin install telegram@claude-plugins-official`, followed by `/reload-plugins`. Next, configure the server with the bot token by running the command `/telegram:configure` and inputting the token. This step is critical as it writes the token to the appropriate environment file. To handle multiple bots, ensure you set the `TELEGRAM_STATE_DIR` to different directories for each instance. Relaunch the session with the channel flag to establish the connection. Once your session is active, you can pair your bot by sending it a direct message on Telegram. The bot will reply with a 6-character pairing code. Use this code in your Claude Code session with the command `/telegram:access pair <code>`. This process allows the bot to identify your user ID without requiring numeric IDs. For security, it's recommended to switch to an allowlist policy after pairing to prevent unauthorized access. The bot can then reply to messages, add emoji reactions, and edit its own previous messages. Inbound messages trigger a typing indicator, but the bot can't access message history or fetch earlier messages, meaning it relies on real-time communication.

Ask about this article