加入我们的 Telegram 社群 (clawdbotCN) 学习分享和了解更多 →
渠道集成
Telegram

Telegram 配置

Telegram 通常是设置最快的渠道,通过 grammY 库集成。

快速开始

1. 创建 Bot

  1. 在 Telegram 中找到 @BotFather (opens in a new tab)
  2. 发送 /newbot 命令
  3. 按提示设置 Bot 名称和用户名
  4. 复制 Bot Token

2. 配置

{
  channels: {
    telegram: {
      enabled: true,
      botToken: "YOUR_BOT_TOKEN"
    }
  }
}

或使用环境变量:

export TELEGRAM_BOT_TOKEN="YOUR_BOT_TOKEN"

3. 启动

clawdbot gateway run

访问控制

私聊策略

{
  channels: {
    telegram: {
      // 配对模式 (默认) - 新用户需要配对码
      dmPolicy: "pairing",
 
      // 白名单模式
      dmPolicy: "allowlist",
      allowFrom: ["123456789", "987654321"],
 
      // 开放模式
      dmPolicy: "open"
    }
  }
}

群聊策略

{
  channels: {
    telegram: {
      // 默认需要 @提及
      groups: {
        "*": {
          requireMention: true
        }
      },
 
      // 特定群组配置
      groups: {
        "-1001234567890": {
          requireMention: false  // 总是响应
        }
      }
    }
  }
}

功能特性

流式传输

支持实时流式响应:

{
  channels: {
    telegram: {
      streamMode: "partial",  // 定期更新消息
      textChunkLimit: 4000    // 每条消息最大字符数
    }
  }
}

内联按钮

支持交互式内联按钮:

{
  channels: {
    telegram: {
      inlineButtons: true
    }
  }
}

语音笔记

支持发送和接收语音消息。

草稿流式传输

在私聊中启用草稿流式传输:

{
  channels: {
    telegram: {
      draftStreaming: true  // 仅私聊支持
    }
  }
}

回复模式

{
  channels: {
    telegram: {
      replyToMode: "first",  // 只回复第一条消息
      // 或
      replyToMode: "all",    // 回复所有消息
      // 或
      replyToMode: "off"     // 不使用回复功能
    }
  }
}

论坛主题支持

在超级群组中支持论坛主题:

{
  channels: {
    telegram: {
      groups: {
        "-1001234567890": {
          // 按主题隔离对话
          forumTopics: true
        }
      }
    }
  }
}

隐私模式

要接收所有群组消息:

  1. 在 @BotFather 中禁用隐私模式,或
  2. 将 Bot 添加为群组管理员

完整配置示例

{
  channels: {
    telegram: {
      enabled: true,
      botToken: "YOUR_BOT_TOKEN",
 
      dmPolicy: "pairing",
      groupPolicy: "open",
 
      streamMode: "partial",
      textChunkLimit: 4000,
 
      replyToMode: "first",
      typingIndicator: true,
      inlineButtons: true,
 
      groups: {
        "*": {
          requireMention: true,
          historyCount: 50
        }
      }
    }
  }
}

下一步