Telegram通知服务

一个基于Telegram的通知服务,允许LLM发送通知并接收用户响应,适用于需要与用户交互的AI应用场景。

  • by MobileVibe
  • JavaScript
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 MobileVibe/telegram-mcp

使用说明

电报MCP服务器

一种模型上下文协议(MCP)服务器,使LLM能够通过Telegram发送通知并接收用户响应。

特性

  • 向Telegram聊天发送文本通知,并可自定义紧急程度
  • 等待并检索用户响应
  • 与Cline和其他MCP兼容的LLM应用程序集成

先决条件

  • Node.js 16或更高版本
  • Telegram机器人令牌(从以下来源获得 @植物学家)
  • 您的Telegram聊天ID

安装

来自npm(推荐)

npm install -g telegram-mcp

来自GitHub

git clone https://github.com/CHarrisTech/telegram-mcp.git
cd telegram-mcp
npm install
npm run build

配置

服务器需要两个环境变量:

  • TELEGRAM_BOT_TOKEN:您的Telegram机器人令牌
  • TELEGRAM_CHAT_ID:您的Telegram聊天ID

获取Telegram Bot令牌

  1. 开始聊天 @植物学家 在Telegram上
  2. 发送命令 /newbot
  3. 按照说明创建新的机器人
  4. BotFather将为您的新机器人提供一个令牌

查找您的聊天ID

  1. 与您的新机器人开始聊天
  2. 向机器人发送消息
  3. 访问 https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
  4. 寻找 chat 响应中的对象并注意 id 领域

用法

独立运行

# Set environment variables
export TELEGRAM_BOT_TOKEN="your_bot_token"
export TELEGRAM_CHAT_ID="your_chat_id"

# Run the server
telegram-mcp

与Cline整合

将以下内容添加到Cline MCP设置文件中:

{
  "mcpServers": {
    "telegram-mcp": {
      "command": "node",
      "args": ["path/to/telegram-mcp/build/index.js"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "your_bot_token",
        "TELEGRAM_CHAT_ID": "your_chat_id"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

与Claude Desktop集成

将以下内容添加到您的Claude Desktop配置文件中:

{
  "mcpServers": {
    "telegram-mcp": {
      "command": "node",
      "args": ["path/to/telegram-mcp/build/index.js"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "your_bot_token",
        "TELEGRAM_CHAT_ID": "your_chat_id"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

可用工具

send_通知

向配置的Telegram聊天发送通知消息。

参数:

  • message (必填):要发送给用户的消息
  • project (必填):法学硕士正在进行的项目名称
  • urgency (可选):紧急程度(“低”、“中”或“高”)

检查通知响应

检查用户是否已对之前发送的通知做出响应。

参数:

  • message_id (必填):用于检查响应的消息的ID
  • timeout_seconds (可选):放弃前等待响应的时间(默认值:30)

发展

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

# Install dependencies
npm install

# Build the project
npm run build

# Watch for changes during development
npm run watch

# Test with the MCP Inspector
npm run inspector

本地测试

存储库包括帮助您在本地测试服务器的脚本:

视窗

# Set environment variables
set TELEGRAM_BOT_TOKEN=your_bot_token
set TELEGRAM_CHAT_ID=your_chat_id

# Run the test script
test-server.bat

macOS/Linux

# Set environment variables
export TELEGRAM_BOT_TOKEN=your_bot_token
export TELEGRAM_CHAT_ID=your_chat_id

# Make the script executable (first time only)
chmod +x test-server.sh

# Run the test script
./test-server.sh

例子

这 examples 目录包含演示如何使用Telegram MCP服务器的示例代码:

  • programmatic-usage.js:演示如何在自己的Node.js应用程序中以编程方式使用服务器

举个例子:

# Set required environment variables
export TELEGRAM_BOT_TOKEN="your_bot_token"
export TELEGRAM_CHAT_ID="your_chat_id"

# Run the example
node examples/programmatic-usage.js

许可证

麻省理工学院