Telegram通信服务器

一个通过Telegram与用户进行通信的MCP服务器,提供提问、通知发送、文件共享和项目归档功能。

  • by qpd-v
  • JavaScript
  • 本地部署
  • 47 星标
  • 更新于
在 GitHub 查看 qpd-v/mcp-communicator-telegram

使用说明

MCP通信器(电报)

通过Telegram与用户通信的MCP服务器。该服务器提供通过Telegram机器人与用户交互的工具,包括提问、发送通知、共享文件和创建项目档案。

安装

通过npm(全局)

npm install -g mcp-communicator-telegram

通过npx(按需)

npx mcptelegram

要获取您的Telegram聊天ID:

npx mcptelegram-chatid

特性

  • 通过Telegram向用户提问
  • 向用户发送通知(无需回复)
  • 通过Telegram向用户发送文件
  • 创建并发送项目zip文件(尊重.gitignore)
  • 异步接收响应(无限期等待响应)
  • 支持基于回复的消息跟踪
  • 安全聊天ID验证
  • 错误处理和日志

先决条件

  • Node.js(v14或更高版本)
  • 一个 Telegram 机器人令牌(从 @植物学家)
  • 您的Telegram聊天ID(可以使用附带的实用程序获得)

安装

  1. 克隆存储库:
git clone https://github.com/qpd-v/mcp-communicator-telegram.git
cd mcp-communicator-telegram
  1. 安装依赖项:
npm install
  1. 创建Telegram机器人:

    • 打开Telegram并搜索 @植物学家
    • 发送 /newbot 并遵循指示
    • 保存您收到的机器人令牌
  2. 获取您的聊天ID:

    • 复制 .env.example 向 .env
    • 将您的机器人令牌添加到 .env 文件:
      TELEGRAM_TOKEN=your_bot_token_here
      
    • 运行聊天ID实用程序:
      npm run build
      node build/get-chat-id.js
      
    • 向您的机器人发送任何消息
    • 复制控制台中显示的聊天ID
    • 将聊天ID添加到您的 .env 文件:
      TELEGRAM_TOKEN=your_bot_token_here
      CHAT_ID=your_chat_id_here
      

配置

将服务器添加到MCP设置文件(通常位于 %APPDATA%\Code\User\globalStorage\rooveterinaryinc.roo-cline\settings\cline_mcp_settings.json 在Windows上):

{
  "mcpServers": {
    "mcp-communicator-telegram": {
      "command": "node",
      "args": ["path/to/mcp-communicator-telegram/build/index.js"],
      "env": {
        "TELEGRAM_TOKEN": "your_bot_token_here",
        "CHAT_ID": "your_chat_id_here"
      }
    }
  }
}

可用工具

ask_user

通过Telegram向用户提问并等待他们的回复。

输入架构:

{
  "type": "object",
  "properties": {
    "question": {
      "type": "string",
      "description": "The question to ask the user"
    }
  },
  "required": ["question"]
}

示例用法:

const response = await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "ask_user",
  arguments: {
    question: "What is your favorite color?"
  }
});

notify_user

通过Telegram向用户发送通知消息(无需响应)。

输入架构:

{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "The message to send to the user"
    }
  },
  "required": ["message"]
}

示例用法:

await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "notify_user",
  arguments: {
    message: "Task completed successfully!"
  }
});

send_file

通过Telegram向用户发送文件。

输入架构:

{
  "type": "object",
  "properties": {
    "filePath": {
      "type": "string",
      "description": "The path to the file to send"
    }
  },
  "required": ["filePath"]
}

示例用法:

await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "send_file",
  arguments: {
    filePath: "path/to/file.txt"
  }
});

zip工程

创建项目目录的zip文件(尊重.gitignore模式),并通过Telegram将其发送给用户。

输入架构:

{
  "type": "object",
  "properties": {
    "directory": {
      "type": "string",
      "description": "Directory to zip (defaults to current working directory)"
    }
  },
  "required": []
}

默认目录(当前工作目录)的示例用法:

await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "zip_project",
  arguments: {}
});

特定目录的示例用法:

await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "zip_project",
  arguments: {
    directory: "/path/to/your/project"
  }
});

特征:

  • 创建一个名为的zip文件 [project-name]-project.zip 基于目录名
  • 可以压缩任何指定目录或当前工作目录
  • 尊重他人
  • 在存档中维护正确的文件路径
  • 发送后自动清理zip文件
  • 处理大小高达2GB的文件

发展

构建项目:

npm run build

在开发模式下运行:

npm run dev

注意变化:

npm run watch

清理生成目录:

npm run clean

安全

  • 服务器仅响应来自配置的聊天ID的消息
  • 环境变量用于敏感配置
  • 消息ID用于跟踪问题/答案对
  • 机器人忽略没有适当上下文的消息

许可证

国际协调委员会

作者

qpd-v

版本

0.2.1#新功能的主要版本升级:notify_user、send_file和zip_project工具