Telegram机器人API客户端

提供Telegram Bot API的完整功能覆盖(166个方法),支持MCP服务器和CLI模式。

  • by 0xDEADBEEF-all
  • Rust
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 0xDEADBEEF-all/telegram-bot-mcp

使用说明

电报机器人mcp

用于Telegram Bot API的MCP服务器和CLI。全面覆盖 166种方法 所有API类别。

用Rust构建, rmcp 1.3,东京,reqwest。

特性

  • 166 Bot API方法 --消息、媒体、聊天、论坛、贴纸、内联、支付、游戏、护照、礼物
  • MCP服务器 (stdio传输)-适用于Claude Code、Claude Desktop和任何MCP客户端
  • CLI模式 --直接方法调用没有MCP支持的代理和脚本
  • 单个二进制 --无运行时依赖关系,快速启动

API覆盖范围

模块 方法 示例
机器人信息 16 getMe, setMyCommands, setMyName, setMyProfilePhoto
更新 4 getUpdates, setWebhook, deleteWebhook, getWebhookInfo
消息 10 sendMessage, forwardMessage, copyMessage, pinChatMessage
编辑 9 editMessageText, editMessageCaption, deleteMessage
媒体 14 sendPhoto, sendVideo, sendDocument, sendPoll, sendDice
聊天 27 getChat, banChatMember, promoteChatMember, setChatPermissions
论坛 13 createForumTopic, editForumTopic, closeForumTopic
贴纸 16 sendSticker, createNewStickerSet, setStickerSetTitle
内联 4 answerCallbackQuery, answerInlineQuery
付款 7 sendInvoice, createInvoiceLink, getStarTransactions
游戏 3 sendGame, setGameScore, getGameHighScores
商业 11 readBusinessMessage, setBusinessAccountName, transferBusinessAccountStars
故事 4 postStory, editStory, deleteStory, repostStory
其他 28 sendGift, verifyUser, sendChecklist, getUserGifts, getFile

安装

来自crates.io

cargo install telegram-bot-mcp

来源

git clone https://github.com/0xDEADBEEF-all/telegram-bot-mcp.git
cd telegram-bot-mcp
cargo build --release

设置

  1. 从获取机器人令牌 @植物学家
  2. 添加到MCP配置(~/.mcp.json 或项目 .mcp.json):
{
  "mcpServers": {
    "telegram-bot": {
      "command": "telegram-bot-mcp",
      "env": {
        "TELEGRAM_BOT_TOKEN": "your-token-from-botfather"
      }
    }
  }
}
  1. 重新启动MCP客户端(Claude Code、Claude Desktop等)

用法

MCP服务器(默认)

# Starts stdio MCP server (used automatically by MCP clients)
TELEGRAM_BOT_TOKEN=123:abc telegram-bot-mcp

# or via flag
telegram-bot-mcp --token 123:abc

命令行接口命令模式

# List all available methods
./telegram-bot-mcp list

# Call a method (no params)
./telegram-bot-mcp -t 123:abc call getMe

# Call with JSON params
./telegram-bot-mcp -t 123:abc call sendMessage '{"chat_id":"123","text":"hello"}'

# Call with token from env
TELEGRAM_BOT_TOKEN=123:abc ./telegram-bot-mcp call sendDice '{"chat_id":"123","emoji":"🎰"}'

CLI输出是stdout上的JSON,stderr上的错误,退出代码0/1。

项目结构

src/
├── main.rs          # Entry point, CLI parsing, MCP transport
├── bot_api.rs       # Telegram Bot API HTTP client
├── cli.rs           # CLI mode handler
├── server.rs        # MCP ServerHandler + ToolRouter
└── tools/
    ├── mod.rs       # Router composition
    ├── bot.rs       # Bot info & commands (16 methods)
    ├── updates.rs   # Updates & webhooks (4 methods)
    ├── messages.rs  # Sending & pinning (10 methods)
    ├── editing.rs   # Editing & deleting (9 methods)
    ├── media.rs     # Photos, videos, polls, etc. (14 methods)
    ├── chats.rs     # Chat management (27 methods)
    ├── forum.rs     # Forum topics (13 methods)
    ├── stickers.rs  # Sticker operations (16 methods)
    ├── inline.rs    # Inline & callbacks (4 methods)
    ├── payments.rs  # Invoices & Stars (7 methods)
    ├── games.rs     # Games (3 methods)
    ├── business.rs  # Business accounts (11 methods)
    ├── stories.rs   # Stories (4 methods)
    └── other.rs     # Gifts, verification, passport, etc. (28 methods)

许可证

麻省理工学院