Telegram消息管理服务

连接Claude到Telegram账户,实现消息的读取、发送和管理功能,适用于个人和团队沟通。

  • by alexandertsai
  • Python
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 alexandertsai/mcp-telegram

使用说明

电报MCP服务器

将Claude连接到您的Telegram帐户以阅读和发送消息。

特性

可用工具

  1. get_chats -列出您的Telegram聊天记录

    • 返回带有聊天名称、ID和未读计数的分页列表
    • 对于第1页,只需提供页码
    • 对于后续页面,使用前一个响应中的分页参数
  2. 获取消息 -读取特定聊天中的消息

    • 获取分页的消息历史记录
    • 自动将邮件标记为已读
  3. mark_messages_read -将聊天中的所有未读消息标记为已读

  4. send_message -向任何聊天室发送消息

    • 支持回复特定邮件
  5. get_conversation_context -分析聊天风格以获得自然反应

    • 阅读您的对话风格指南 convostyle.txt
    • 帮助Claude匹配您的短信模式

安装指南

步骤1:获取Telegram API凭据

  1. 首选 https://my.telegram.org/apps
  2. 登录并创建应用程序
  3. 保存您的 API ID 和 API哈希

步骤2:安装

# Clone the repository
git clone https://github.com/alexandertsai/mcp-telegram
cd mcp-telegram

# Set up Python environment
pip install uv
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv sync

步骤3:配置

# Copy the example file
cp .env.example .env

# Edit .env and add your API credentials:
# TELEGRAM_API_ID=your_api_id_here
# TELEGRAM_API_HASH=your_api_hash_here

步骤4:身份验证

cd src/mcp_telegram
python telethon_auth.py

按照提示操作:

  • 输入您的电话号码(带国家代码,例如+1234567890)
  • 输入发送到您的Telegram的代码
  • 如果您有2FA密码,请输入

步骤5:添加到Claude桌面

查找您的Claude Desktop配置文件:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 视窗: %APPDATA%\Claude\claude_desktop_config.json

添加此配置:

{
  "mcpServers": {
    "telegram": {
      "command": "/path/to/python",
      "args": ["/path/to/mcp-telegram/src/mcp_telegram/main.py"]
    }
  }
}

要查找路径,请执行以下操作:

  • Python:运行 which python (Mac)或 where.exe python (Windows)
  • main.py:右键单击文件并选择“复制路径”

重新启动克劳德桌面。

用法

设置后,您可以要求Claude:

  • “查看我的电报消息”
  • “向[联系人姓名]发送消息”
  • “我的未读聊天记录是什么?”
  • “回复[联系人姓名]的最后一条消息”

样式指南(可选)

创建 src/mcp_telegram/convostyle.txt 帮助Claude匹配您的短信风格:

I text casually with friends, formally with work contacts.
I use emojis sparingly and prefer short messages.

故障排除

身份验证问题

如果身份验证失败:

  1. 在中检查您的API凭据 .env
  2. 从中删除TELEGRAM_SESSION_STRING行 .env
  3. 跑 python telethon_auth.py 再次

常见错误

  • “请设置TELEGRAM_API_ID和TELEGRAM-API_HASH”:缺失 .env 文件或凭据
  • “会话字符串无效或已过期”:重新运行身份验证
  • 2FA密码未显示:这很正常-继续打字

需求

  • Python 3.10+
  • 克劳德桌面
  • 电报账户

许可证

Apache 2.0