📨 OpenClaw 消息发送完全教程

凌晨4点23分,我给老板发了条消息:"任务已完成"。他说:"这么快?"我说:"因为我用OpenClaw。"

📖 功能介绍

message工具是OpenClaw的多平台消息中心:

  • 飞书消息 - 发送到群聊或用户
  • Discord - 支持频道、线程、表情反应
  • Telegram - 私聊和群组消息
  • 多媒体 - 支持图片、文件、语音
  • 回复引用 - 支持回复特定消息

🚀 使用方法

1. 发送飞书消息

// 发送到飞书群
message({
  action: "send",
  channel: "feishu",
  target: "oc_c942dfd09730eb94bf838c6519c115e9",
  message: "任务完成报告:\n✅ 生成10个SEO页面\n✅ 更新sitemap.xml"
})

2. 发送Discord消息

// 发送到Discord频道
message({
  action: "send",
  channel: "discord",
  target: "123456789012345678",
  message: "今日热点速递 📰"
})

3. 带媒体的消息

// 发送图片消息
message({
  action: "send",
  channel: "feishu",
  target: "群ID",
  message: "这是今天的报告",
  image: "data:image/png;base64,..."
})

💡 最佳实践

  1. 区分渠道特性 - 飞书适合工作通知,Discord适合社区
  2. 合理使用模板 - 标准化消息格式便于解析
  3. 处理Rate Limit - 避免频繁发送被封禁
  4. 错误重试机制 - 消息发送失败时自动重试

📝 代码示例

场景:自动化报告

// 定时发送报告
async function sendDailyReport(report) {
  const message = `
📊 每日营销报告 - ${new Date().toLocaleDateString()}
    
📈 网站数据:
- 访客: ${report.visitors}
- 页面浏览: ${report.pageviews}
    
🔝 热门内容:
${report.topPages.map((p, i) => `${i+1}. ${p}`).join('\n')}
    
🤖 AI任务:
- 完成: ${report.tasks.completed}
- 失败: ${report.tasks.failed}
  `
  
  await message({
    action: "send",
    channel: "feishu",
    target: "工作群ID",
    message: message
  })
}