返回

oh-my-claudecode 教程 9:通知集成与 HUD 状态栏

oh-my-claudecode 支持多种通知渠道集成,包括 Telegram、Discord、Slack 和 OpenClaw。本文详解通知配置、HUD 状态栏设置和实时监控。

教程概述

oh-my-claudecode 的通知系统让你不错过任何重要事件。无论是长时间任务完成、会话状态变化,还是需要人工介入,都能通过你选择的渠道及时通知。

你将学到

  • ✅ 通知系统架构
  • ✅ Telegram 集成配置
  • ✅ Discord/Slack 集成
  • ✅ OpenClaw 自动化响应
  • ✅ HUD 状态栏自定义

通知系统概述

支持的通知渠道

flowchart TD
    A[OMC 事件] --> B{通知渠道}
    B --> C[Telegram]
    B --> D[Discord]
    B --> E[Slack]
    B --> F[OpenClaw]
    B --> G[Webhook]

    C --> H[Bot 消息]
    D --> I[Webhook 消息]
    E --> J[Slack Bot]
    F --> K[自动化响应]
    G --> L[自定义处理]

    style A fill:#e1f5ff
    style F fill:#fff3e0

Hook 事件类型

事件 触发时机 用途
session-start 会话开始 了解工作开始
stop 会话停止 任务完成/需要输入
keyword-detector 检测到关键词 监控特定触发
ask-user-question 需要用户输入 及时响应请求
pre-tool-use 工具调用前 调试监控
post-tool-use 工具调用后 执行跟踪

Telegram 集成

创建 Telegram Bot

步骤 1:与 BotFather 对话

1. 打开 Telegram,搜索 @BotFather
2. 发送 /newbot
3. 按提示命名你的 bot
4. 获取 API Token

步骤 2:获取 Chat ID

# 方法 1:通过 API
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates"

# 方法 2:使用 @userinfobot
# 向 @userinfobot 发送消息,获取你的 Chat ID

配置 Telegram 通知

# 使用配置命令
omc config-stop-callback telegram \
  --enable \
  --token "YOUR_BOT_TOKEN" \
  --chat "YOUR_CHAT_ID"

配置文件格式

// ~/.claude/omc_config.telegram.json
{
  "enabled": true,
  "token": "YOUR_BOT_TOKEN",
  "chat_id": "YOUR_CHAT_ID",
  "events": ["session-start", "stop", "ask-user-question"]
}

标签和提及

# 设置标签列表
omc config-stop-callback telegram --tag-list "@alice,bob,charlie"

# 添加标签
omc config-stop-callback telegram --add-tag dave

# 移除标签
omc config-stop-callback telegram --remove-tag @alice

# 清除所有标签
omc config-stop-callback telegram --clear-tags

通知效果

📢 OMC Session Update

🔄 Session started for: my-project
📍 Path: /home/user/projects/my-project
🆔 Session: abc123

---
Powered by oh-my-claudecode

Discord 集成

创建 Webhook

步骤 1:在 Discord 中创建 Webhook

1. 打开目标频道设置
2. 选择「整合」→「Webhook」
3. 点击「新建 Webhook」
4. 复制 Webhook URL

配置 Discord 通知

omc config-stop-callback discord \
  --enable \
  --webhook "https://discord.com/api/webhooks/..."

Discord 标签格式

# 支持的格式
@here              # 提及所有在线用户
@everyone          # 提及所有用户
123456789012345678  # 用户 ID
role:987654321098765432  # 角色 ID

配置示例

// ~/.claude/omc_config.discord.json
{
  "enabled": true,
  "webhook": "https://discord.com/api/webhooks/.../...",
  "tag_list": ["@here", "role:123456789"],
  "events": ["stop", "ask-user-question"]
}

Slack 集成

创建 Slack Webhook

1. 访问 https://api.slack.com/apps
2. 创建新 App
3. 启用 Incoming Webhooks
4. 添加到工作区并获取 Webhook URL

配置 Slack 通知

omc config-stop-callback slack \
  --enable \
  --webhook "https://hooks.slack.com/services/..."

Slack 提及格式

<!here>              # @here
<!channel>           # @channel
<!everyone>          # @everyone
<@U1234567890>       # 用户提及
<!subteam^GROUP_ID>  # 用户组提及

OpenClaw 集成

什么是 OpenClaw?

OpenClaw 是一个自动化响应平台,可以接收 OMC 事件并触发自动化的 AI 响应。

工作流程

sequenceDiagram
    participant OMC
    participant OpenClaw
    participant AI
    participant Discord

    OMC->>OpenClaw: Session start event
    OpenClaw->>AI: Generate response
    AI->>OpenClaw: Response content
    OpenClaw->>Discord: Send to Discord
    Discord->>User: Display message

快速配置

# 使用配置向导
/oh-my-claudecode:configure-notifications
# 选择 OpenClaw Gateway

手动配置

// ~/.claude/omc_config.openclaw.json
{
  "enabled": true,
  "gateways": {
    "my-gateway": {
      "url": "https://your-gateway.example.com/wake",
      "headers": {
        "Authorization": "Bearer YOUR_TOKEN"
      },
      "method": "POST",
      "timeout": 10000
    }
  },
  "hooks": {
    "session-start": {
      "gateway": "my-gateway",
      "instruction": "Session started for {{projectName}}",
      "enabled": true
    },
    "stop": {
      "gateway": "my-gateway",
      "instruction": "Session stopping for {{projectName}}",
      "enabled": true
    }
  }
}

模板变量

变量 说明
{{sessionId}} 会话 ID
{{projectName}} 项目名称
{{projectPath}} 项目路径
{{prompt}} 用户提示词
{{question}} 问题内容
{{toolName}} 工具名称

环境变量

export OMC_OPENCLAW=1                    # 启用 OpenClaw
export OMC_OPENCLAW_DEBUG=1              # 调试模式
export OMC_OPENCLAW_CONFIG=/path/to/config.json  # 自定义配置路径

HUD 状态栏

什么是 HUD?

HUD(Heads-Up Display)在状态栏中显示实时编排指标,让你随时了解 OMC 的工作状态。

配置 HUD

# 设置 HUD
/oh-my-claudecode:hud setup

预设配置

// ~/.claude/settings.json
{
  "omcHud": {
    "preset": "focused"
  }
}

可用预设

预设 显示内容
minimal 仅当前模式
focused 模式 + 任务数
detailed 完整状态信息
debug 所有调试信息

HUD 显示示例

[OMC: ralph] Tasks: 3/5 | Phase: verification | Tokens: 12.5k

自定义 HUD

{
  "omcHud": {
    "elements": [
      "mode",
      "taskProgress",
      "currentPhase",
      "tokenUsage",
      "elapsedTime"
    ],
    "refreshIntervalMs": 1000
  }
}

CLI HUD

# 在终端中查看 HUD
omc hud

# 持续监控
watch omc hud

会话监控

查看会话状态

# 当前会话状态
omc status

# 会话历史
omc sessions

# 特定会话详情
omc session show <session-id>

会话文件

会话记录保存在 .omc/sessions/

# 列出会话文件
ls .omc/sessions/

# 查看会话内容
cat .omc/sessions/session-2026-03-25-abc123.json

重放日志

# 查看重放日志
cat .omc/state/agent-replay-*.jsonl

# 分析重放数据
omc replay analyze <session-id>

最佳实践

1. 选择合适的渠道

flowchart TD
    A{使用场景?}
    A -->|个人使用| B[Telegram]
    A -->|团队协作| C[Discord/Slack]
    A -->|自动化响应| D[OpenClaw]
    A -->|自定义集成| E[Webhook]

2. 合理设置事件

{
  "events": [
    "session-start",      // 了解工作开始
    "stop",               // 任务完成/需要输入
    "ask-user-question"   // 及时响应
  ]
}

避免过度通知

  • pre-tool-usepost-tool-use 频率极高
  • 仅在调试时启用这些事件

3. 标签策略

# 团队项目:使用角色标签
omc config-stop-callback discord --tag-list "role:backend-team,role:frontend-team"

# 个人项目:使用个人提及
omc config-stop-callback telegram --tag-list "@me"

常见问题

Q1:Telegram 消息发送失败?

# 检查 Token
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getMe"

# 检查 Chat ID
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates"

# 确认 Bot 有发送权限
# 向 Bot 发送一条消息后再尝试

Q2:Discord Webhook 不工作?

# 测试 Webhook
curl -X POST "YOUR_WEBHOOK_URL" \
  -H "Content-Type: application/json" \
  -d '{"content": "Test message"}'

Q3:如何禁用通知?

# 临时禁用
omc config-stop-callback telegram --disable

# 永久移除配置
rm ~/.claude/omc_config.telegram.json

Q4:HUD 显示异常?

# 运行诊断
/omc-doctor

# 重置 HUD 配置
/oh-my-claudecode:hud setup --reset

小结

通知系统和 HUD 让 OMC 的工作状态可视化、可追踪

关键要点

  • ✅ 选择合适的通知渠道
  • ✅ 合理配置事件类型
  • ✅ 使用标签确保相关人员收到通知
  • ✅ HUD 提供实时状态监控

配置速查

渠道 配置命令
Telegram omc config-stop-callback telegram --enable --token --chat
Discord omc config-stop-callback discord --enable --webhook
Slack omc config-stop-callback slack --enable --webhook
OpenClaw 编辑 omc_config.openclaw.json

系列导航