关于 configure-notifications
configure-notifications 是用于设置 OMC 通知集成的交互式技能,可配置 Telegram、Discord 或 Slack,在会话结束、需要输入等事件发生时发送提醒。它会引导收集服务凭据、选择通知事件,并将设置写入 OMC 配置文件。
主要功能
- 01配置 Telegram、Discord 或 Slack
- 02引导收集服务凭据
- 03选择通知触发事件
- 04写入 OMC 配置文件
- 05可选择发送测试通知
适用场景
- 01接收会话结束提醒
- 02任务等待输入时获取通知
- 03在后台任务完成时收到提醒
- 04重新配置现有通知集成
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ yeachan-heo/ oh-my-claudecode --skill configure-notifications安装后在 Claude Code 中输入/configure-notifications确认已加载。
详细介绍
配置通知
设置 OMC 通知集成,以便在会话结束、需要输入或完成后台任务时收到提醒。
路由
根据用户的请求或参数判断他们想要哪个提供商:
- 如果触发条件或参数中包含 "telegram" → 按照 Telegram 部分操作
- 如果触发条件或参数中包含 "discord" → 按照 Discord 部分操作
- 如果触发条件或参数中包含 "slack" → 按照 Slack 部分操作
- 如果未指定提供商,使用 AskUserQuestion:
问题: "你想配置哪个通知服务?"
选项:
- Telegram - 机器人 token + chat ID。支持移动端和桌面端。
- Discord - Webhook 或机器人 token + channel ID。
- Slack - Incoming webhook URL。
Telegram 设置
设置 Telegram 通知,以便 OMC 在会话结束、需要输入或完成后台任务时向你发送消息。
此 Skill 的工作原理
这是一个交互式的自然语言配置 Skill。通过 AskUserQuestion 提问,引导用户完成设置。将结果写入 ${CLAUDE_CONFIG_DIR:-~/.claude}/.omc-config.json。
第 1 步:检测现有配置
CONFIG_FILE="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-config.json"
if [ -f "$CONFIG_FILE" ]; then
HAS_TELEGRAM=$(jq -r '.notifications.telegram.enabled // false' "$CONFIG_FILE" 2>/dev/null)
CHAT_ID=$(jq -r '.notifications.telegram.chatId // empty' "$CONFIG_FILE" 2>/dev/null)
PARSE_MODE=$(jq -r '.notifications.telegram.parseMode // "Markdown"' "$CONFIG_FILE" 2>/dev/null)
if [ "$HAS_TELEGRAM" = "true" ]; then
echo "EXISTING_CONFIG=true"
echo "CHAT_ID=$CHAT_ID"
echo "PARSE_MODE=$PARSE_MODE"
else
echo "EXISTING_CONFIG=false"
fi
else
echo "NO_CONFIG_FILE"
fi
如果找到现有配置,向用户显示当前已配置的内容,并询问他们是要更新还是重新配置。
第 2 步:创建 Telegram 机器人
如果用户还没有机器人,引导他们创建一个:
To set up Telegram notifications, you need a Telegram bot token and your chat ID.
CREATE A BOT (if you don't have one):
1. Open Telegram and search for @BotFather
2. Send /newbot
3. Choose a name (e.g., "My OMC Notifier")
4. Choose a username (e.g., "my_omc_bot")
5. BotFather will give you a token like: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz
GET YOUR CHAT ID:
1. Start a chat with your new bot (send /start)
2. Visit: https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
3. Look for "chat":{"id":YOUR_CHAT_ID}
- Personal chat IDs are positive numbers (e.g., 123456789)
- Group chat IDs are negative numbers (e.g., -1001234567890)
第 3 步:收集机器人 token
使用 AskUserQuestion:
问题: "粘贴你的 Telegram 机器人 token(来自 @BotFather)"
用户将在 "Other" 字段中输入他们的 token。
验证 token:
- 必须匹配模式:
digits:alphanumeric(例如123456789:ABCdefGHI...) - 如果无效,说明格式并再次询问
第 4 步:收集 chat ID
使用 AskUserQuestion:
问题: "粘贴你的 Telegram chat ID(来自 getUpdates API 的数字)"
用户将在 "Other" 字段中输入他们的 chat ID。
验证 chat ID:
- 必须是数字(个人为正数,群组为负数)
- 如果无效,主动帮助他们找到它:
# Help user find their chat ID
BOT_TOKEN="USER_PROVIDED_TOKEN"
echo "Fetching recent messages to find your chat ID..."
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getUpdates" | jq '.result[-1].message.chat.id // .result[-1].message.from.id // "No messages found - send /start to your bot first"'
第 5 步:选择解析模式
使用 AskUserQuestion:
问题: "你更喜欢哪种消息格式?"
选项:
- Markdown(推荐) - 使用 Markdown 语法的粗体、斜体、代码块
- HTML - 使用 HTML 标签的粗体、斜体、代码
第 6 步:配置事件
使用带 multiSelect 的 AskUserQuestion:
问题: "哪些事件应触发 Telegram 通知?"
选项(multiSelect: true):
- 会话结束(推荐) - 当 Claude 会话结束时
- 需要输入 - 当 Claude 等待你的回复时(非常适合长时间运行的任务)
- 会话开始 - 当新会话开始时
- 会话继续 - 当持久模式保持会话存活时
默认选择:session-end + ask-user-question。
第 7 步:写入配置
读取现有配置,合并新的 Telegram 设置,然后写回:
CONFIG_FILE="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"
if [ -f "$CONFIG_FILE" ]; then
EXISTING=$(cat "$CONFIG_FILE")
else
EXISTING='{}'
fi
# BOT_TOKEN, CHAT_ID, PARSE_MODE are collected from user
echo "$EXISTING" | jq \
--arg token "$BOT_TOKEN" \
--arg chatId "$CHAT_ID" \
--arg parseMode "$PARSE_MODE" \
'.notifications = (.notifications // {enabled: true}) |
.notifications.enabled = true |
.notifications.telegram = {
enabled: true,
botToken: $token,
chatId: $chatId,
parseMode: $parseMode
}' > "$CONFIG_FILE"
如果用户未选择所有事件,添加特定事件的配置:
对于每个未选择的事件,禁用它:
# Example: disable session-start if not selected
echo "$(cat "$CONFIG_FILE")" | jq \
'.notifications.events = (.notifications.events // {}) |
.notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
第 8 步:测试配置
写入配置后,主动提出发送测试通知:
使用 AskUserQuestion:
问题: "发送测试通知以验证设置?"
选项:
- 是,立即测试(推荐) - 向你的 Telegram 聊天发送一条测试消息
- 否,我稍后测试 - 跳过测试
如果要测试:
BOT_TOKEN="USER_PROVIDED_TOKEN"
CHAT_ID="USER_PROVIDED_CHAT_ID"
PARSE_MODE="Markdown"
RESPONSE=$(curl -s -w "\n%{http_code}" \
"https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
-d "parse_mode=${PARSE_MODE}" \
-d "text=OMC test notification - Telegram is configured!")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | head -1)
if [ "$HTTP_CODE" = "200" ]; then
echo "Test notification sent successfully!"
else
echo "Failed (HTTP $HTTP_CODE):"
echo "$BODY" | jq -r '.description // "Unknown error"' 2>/dev/null || echo "$BODY"
fi
报告成功或失败。常见问题:
- 401 Unauthorized:机器人 token 无效
- 400 Bad Request: chat not found:chat ID 错误,或用户尚未向机器人发送
/start - 网络错误:检查到 api.telegram.org 的连接
第 9 步:确认
显示最终配置摘要:
Telegram Notifications Configured!
Bot: @your_bot_username
Chat ID: 123456789
Format: Markdown
Events: session-end, ask-user-question
Config saved to: ~/.claude/.omc-config.json
You can also set these via environment variables:
OMC_TELEGRAM_BOT_TOKEN=123456789:ABCdefGHI...
OMC_TELEGRAM_CHAT_ID=123456789
To reconfigure: /oh-my-claudecode:configure-notifications telegram
To configure Discord: /oh-my-claudecode:configure-notifications discord
To configure Slack: /oh-my-claudecode:configure-notifications slack
环境变量替代方案
用户可以在 shell 配置文件中设置环境变量,完全跳过此向导:
export OMC_TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
export OMC_TELEGRAM_CHAT_ID="123456789"
通知系统会自动检测环境变量,无需 .omc-config.json。
Discord 设置
设置 Discord 通知,让 OMC 可以在会话结束、需要输入或完成后台任务时提醒你。
本技能如何工作
这是一个交互式、自然语言配置技能。通过使用 AskUserQuestion 提问,引导用户完成设置。将结果写入 ${CLAUDE_CONFIG_DIR:-~/.claude}/.omc-config.json。
第 1 步:检测现有配置
CONFIG_FILE="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-config.json"
if [ -f "$CONFIG_FILE" ]; then
# Check for existing discord config
HAS_DISCORD=$(jq -r '.notifications.discord.enabled // false' "$CONFIG_FILE" 2>/dev/null)
HAS_DISCORD_BOT=$(jq -r '.notifications["discord-bot"].enabled // false' "$CONFIG_FILE" 2>/dev/null)
WEBHOOK_URL=$(jq -r '.notifications.discord.webhookUrl // empty' "$CONFIG_FILE" 2>/dev/null)
MENTION=$(jq -r '.notifications.discord.mention // empty' "$CONFIG_FILE" 2>/dev/null)
if [ "$HAS_DISCORD" = "true" ] || [ "$HAS_DISCORD_BOT" = "true" ]; then
echo "EXISTING_CONFIG=true"
echo "WEBHOOK_CONFIGURED=$HAS_DISCORD"
echo "BOT_CONFIGURED=$HAS_DISCORD_BOT"
[ -n "$WEBHOOK_URL" ] && echo "WEBHOOK_URL=$WEBHOOK_URL"
[ -n "$MENTION" ] && echo "MENTION=$MENTION"
else
echo "EXISTING_CONFIG=false"
fi
else
echo "NO_CONFIG_FILE"
fi
如果找到现有配置,向用户展示当前已配置的内容,并询问他们是要更新还是重新配置。
第 2 步:选择 Discord 方式
使用 AskUserQuestion:
问题: “你希望如何发送 Discord 通知?”
选项:
- Webhook(推荐) - 在你的 Discord 频道中创建一个 webhook。简单,无需 bot。只需粘贴 URL。
- Bot API - 使用 Discord bot token + channel ID。更灵活,但需要创建一个 bot 应用。
第 3A 步:Webhook 设置
如果用户选择了 Webhook:
使用 AskUserQuestion:
问题: “粘贴你的 Discord webhook URL。创建方法:Server Settings > Integrations > Webhooks > New Webhook > Copy URL”
用户将在 “Other” 字段中输入他们的 webhook URL。
验证 URL:
- 必须以
https://discord.com/api/webhooks/或https://discordapp.com/api/webhooks/开头 - 如果无效,说明格式并再次询问
第 3B 步:Bot API 设置
如果用户选择了 Bot API:
询问两个问题:
- “粘贴你的 Discord bot token” - 来自 discord.com/developers > Your App > Bot > Token
- “粘贴 channel ID” - 右键点击频道 > Copy Channel ID(需要开启开发者模式)
第 4 步:配置提及(用户提醒)
使用 AskUserQuestion:
问题: “你希望通知中提及(提醒)某人吗?”
选项:
- 是,提及某个用户 - 通过其 Discord user ID 标记特定用户
- 是,提及某个角色 - 通过其 role ID 标记某个角色
- 不提及 - 只发布消息,不提醒任何人
如果用户想要提及某个用户:
询问:“要提及的 Discord user ID 是什么?(右键点击用户 > Copy User ID,需要开启开发者模式)”
提及格式为:<@USER_ID>(例如 <@1465264645320474637>)
如果用户想要提及某个角色:
询问:“要提及的 Discord role ID 是什么?(Server Settings > Roles > 右键点击角色 > Copy Role ID)”
提及格式为:<@&ROLE_ID>(例如 <@&123456789>)
第 5 步:配置事件
使用带 multiSelect 的 AskUserQuestion:
问题: “哪些事件应触发 Discord 通知?”
选项(multiSelect: true):
- 会话结束(推荐) - 当 Claude 会话完成时
- 需要输入 - 当 Claude 正在等待你的回复时(非常适合长时间运行的任务)
- 会话开始 - 当新会话开始时
- 会话继续 - 当持久模式保持会话存活时
默认选择:session-end + ask-user-question。
第 6 步:可选用户名覆盖
使用 AskUserQuestion:
问题: “自定义 bot 显示名称?(在 Discord 中显示为 webhook 发送者名称)”
选项:
- OMC(默认) - 显示为 “OMC”
- Claude Code - 显示为 “Claude Code”
- 自定义 - 输入自定义名称
第 7 步:写入配置
读取现有配置,合并新的 Discord 设置,然后写回:
CONFIG_FILE="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"
if [ -f "$CONFIG_FILE" ]; then
EXISTING=$(cat "$CONFIG_FILE")
else
EXISTING='{}'
fi
对于 Webhook 方式:
使用收集到的值构建 notifications 对象,并使用 jq 合并到 .omc-config.json:
# WEBHOOK_URL, MENTION, USERNAME are collected from user
# EVENTS is the list of enabled events
echo "$EXISTING" | jq \
--arg url "$WEBHOOK_URL" \
--arg mention "$MENTION" \
--arg username "$USERNAME" \
'.notifications = (.notifications // {enabled: true}) |
.notifications.enabled = true |
.notifications.discord = {
enabled: true,
webhookUrl: $url,
mention: (if $mention == "" then null else $mention end),
username: (if $username == "" then null else $username end)
}' > "$CONFIG_FILE"
对于 Bot API 方式:
echo "$EXISTING" | jq \
--arg token "$BOT_TOKEN" \
--arg channel "$CHANNEL_ID" \
--arg mention "$MENTION" \
'.notifications = (.notifications // {enabled: true}) |
.notifications.enabled = true |
.notifications["discord-bot"] = {
enabled: true,
botToken: $token,
channelId: $channel,
mention: (if $mention == "" then null else $mention end)
}' > "$CONFIG_FILE"
如果用户未选择所有事件,添加特定事件配置:
对于每个未选择的事件,将其禁用:
# Example: disable session-start if not selected
echo "$(cat "$CONFIG_FILE")" | jq \
'.notifications.events = (.notifications.events // {}) |
.notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
第 8 步:测试配置
写入配置后,询问是否发送测试通知:
使用 AskUserQuestion:
问题: “发送测试通知以验证设置?”
选项:
- 是,立即测试(推荐) - 向你的 Discord 频道发送一条测试消息
- 否,我稍后测试 - 跳过测试
如果进行测试:
# For webhook:
curl -s -o /dev/null -w "%{http_code}" \
-H "Content-Type: application/json" \
-d "{\"content\": \"${MENTION:+$MENTION\\n}OMC test notification - Discord is configured!\"}" \
"$WEBHOOK_URL"
报告成功或失败。如果失败,帮助用户调试(检查 URL、权限等)。
第 9 步:确认
显示最终配置摘要:
Discord Notifications Configured!
Method: Webhook / Bot API
Mention: <@1465264645320474637> (or "none")
Events: session-end, ask-user-question
Username: OMC
Config saved to: ~/.claude/.omc-config.json
You can also set these via environment variables:
OMC_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
OMC_DISCORD_MENTION=<@1465264645320474637>
To reconfigure: /oh-my-claudecode:configure-notifications discord
To configure Telegram: /oh-my-claudecode:configure-notifications telegram
To configure Slack: /oh-my-claudecode:configure-notifications slack
环境变量替代方案
用户可以在 shell 配置文件中设置环境变量,从而完全跳过此向导:
Webhook 方式:
export OMC_DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
export OMC_DISCORD_MENTION="<@1465264645320474637>" # optional
Bot API 方式:
export OMC_DISCORD_NOTIFIER_BOT_TOKEN="your-bot-token"
export OMC_DISCORD_NOTIFIER_CHANNEL="your-channel-id"
export OMC_DISCORD_MENTION="<@1465264645320474637>" # optional
通知系统会自动检测环境变量,无需 .omc-config.json。
Slack 设置
设置 Slack 通知,以便 OMC 在会话结束、需要输入或完成后台任务时向你发送消息。
此 Skill 的工作原理
这是一个交互式的自然语言配置 Skill。通过 AskUserQuestion 提问,引导用户完成设置。将结果写入 ${CLAUDE_CONFIG_DIR:-~/.claude}/.omc-config.json。
第 1 步:检测现有配置
CONFIG_FILE="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-config.json"
if [ -f "$CONFIG_FILE" ]; then
HAS_SLACK=$(jq -r '.notifications.slack.enabled // false' "$CONFIG_FILE" 2>/dev/null)
WEBHOOK_URL=$(jq -r '.notifications.slack.webhookUrl // empty' "$CONFIG_FILE" 2>/dev/null)
MENTION=$(jq -r '.notifications.slack.mention // empty' "$CONFIG_FILE" 2>/dev/null)
CHANNEL=$(jq -r '.notifications.slack.channel // empty' "$CONFIG_FILE" 2>/dev/null)
if [ "$HAS_SLACK" = "true" ]; then
echo "EXISTING_CONFIG=true"
[ -n "$WEBHOOK_URL" ] && echo "WEBHOOK_URL=$WEBHOOK_URL"
[ -n "$MENTION" ] && echo "MENTION=$MENTION"
[ -n "$CHANNEL" ] && echo "CHANNEL=$CHANNEL"
else
echo "EXISTING_CONFIG=false"
fi
else
echo "NO_CONFIG_FILE"
fi
如果找到现有配置,向用户显示当前已配置的内容,并询问他们是要更新还是重新配置。
第 2 步:创建 Slack Incoming Webhook
如果用户还没有 webhook,引导他们创建一个:
To set up Slack notifications, you need a Slack incoming webhook URL.
CREATE A WEBHOOK:
1. Go to https://api.slack.com/apps
2. Click "Create New App" > "From scratch"
3. Name your app (e.g., "OMC Notifier") and select your workspace
4. Go to "Incoming Webhooks" in the left sidebar
5. Toggle "Activate Incoming Webhooks" to ON
6. Click "Add New Webhook to Workspace"
7. Select the channel where notifications should be posted
8. Copy the webhook URL (starts with https://hooks.slack.com/services/...)
第 3 步:收集 Webhook URL
使用 AskUserQuestion:
问题:“粘贴你的 Slack incoming webhook URL(以 https://hooks.slack.com/services/... 开头)”
用户将在“Other”字段中输入他们的 webhook URL。
验证该 URL:
- 必须以
https://hooks.slack.com/services/开头 - 如果无效,说明格式并再次询问
第 4 步:配置提及(用户/群组 ping)
使用 AskUserQuestion:
问题:“你希望通知中提及(ping)某人吗?”
选项:
- 是,提及某个用户 - 通过其 Slack 成员 ID 标记特定用户
- 是,提及某个频道 - 使用 @channel 通知频道中的所有人
- 是,提及 @here - 仅通知频道中的活跃成员
- 不提及 - 仅发布消息,不 ping 任何人
如果用户想要提及某个用户:
询问:“要提及的 Slack 成员 ID 是什么?(点击用户个人资料 > 更多 (⋯) > 复制成员 ID)”
提及格式为:<@MEMBER_ID>(例如 <@U1234567890>)
如果用户想要 @channel:
提及格式为:<!channel>
如果用户想要 @here:
提及格式为:<!here>
第 5 步:配置事件
使用带 multiSelect 的 AskUserQuestion:
问题:“哪些事件应触发 Slack 通知?”
选项(multiSelect: true):
- 会话结束(推荐) - 当 Claude 会话结束时
- 需要输入 - 当 Claude 正在等待你的回复时(非常适合长时间运行的任务)
- 会话开始 - 当新会话开始时
- 会话继续 - 当持久模式使会话保持活跃时
默认选择:session-end + ask-user-question。
第 6 步:可选的频道覆盖
使用 AskUserQuestion:
问题:“要覆盖默认通知频道吗?(webhook 已有默认频道)”
选项:
- 使用 webhook 默认值(推荐) - 发布到 webhook 设置期间选择的频道
- 覆盖频道 - 指定其他频道(例如 #alerts)
如果要覆盖,询问频道名称(例如 #alerts)。
第 7 步:可选的用户名覆盖
使用 AskUserQuestion:
问题:“自定义机器人显示名称?(在 Slack 中显示为 webhook 发送者名称)”
选项:
- OMC(默认) - 显示为“OMC”
- Claude Code - 显示为“Claude Code”
- 自定义 - 输入自定义名称
第 8 步:写入配置
读取现有配置,合并新的 Slack 设置,然后写回:
CONFIG_FILE="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/.omc-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"
if [ -f "$CONFIG_FILE" ]; then
EXISTING=$(cat "$CONFIG_FILE")
else
EXISTING='{}'
fi
# WEBHOOK_URL, MENTION, USERNAME, CHANNEL are collected from user
echo "$EXISTING" | jq \
--arg url "$WEBHOOK_URL" \
--arg mention "$MENTION" \
--arg username "$USERNAME" \
--arg channel "$CHANNEL" \
'.notifications = (.notifications // {enabled: true}) |
.notifications.enabled = true |
.notifications.slack = {
enabled: true,
webhookUrl: $url,
mention: (if $mention == "" then null else $mention end),
username: (if $username == "" then null else $username end),
channel: (if $channel == "" then null else $channel end)
}' > "$CONFIG_FILE"
如果用户未选择所有事件,添加特定于事件的配置:
对于每个未选择的事件,将其禁用:
# Example: disable session-start if not selected
echo "$(cat "$CONFIG_FILE")" | jq \
'.notifications.events = (.notifications.events // {}) |
.notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
第 9 步:测试配置
写入配置后,提供发送测试通知的选项:
使用 AskUserQuestion:
问题:“要发送测试通知以验证设置吗?”
选项:
- 是,立即测试(推荐) - 向你的 Slack 频道发送一条测试消息
- 否,稍后再测试 - 跳过测试
如果进行测试:
# For webhook:
MENTION_PREFIX=""
if [ -n "$MENTION" ]; then
MENTION_PREFIX="${MENTION}\n"
fi
curl -s -o /dev/null -w "%{http_code}" \
-H "Content-Type: application/json" \
-d "{\"text\": \"${MENTION_PREFIX}OMC test notification - Slack is configured!\"}" \
"$WEBHOOK_URL"
报告成功或失败。常见问题:
- 403 Forbidden:Webhook URL 无效或已被撤销
- 404 Not Found:Webhook URL 不正确
- channel_not_found:频道覆盖无效
- Network error:检查与 hooks.slack.com 的连接
第 10 步:确认
显示最终配置摘要:
Slack Notifications Configured!
Webhook: https://hooks.slack.com/services/T00/B00/xxx...
Mention: <@U1234567890> (or "none")
Channel: #alerts (or "webhook default")
Events: session-end, ask-user-question
Username: OMC
Config saved to: ~/.claude/.omc-config.json
You can also set these via environment variables:
OMC_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
OMC_SLACK_MENTION=<@U1234567890>
To reconfigure: /oh-my-claudecode:configure-notifications slack
To configure Discord: /oh-my-claudecode:configure-notifications discord
To configure Telegram: /oh-my-claudecode:configure-notifications telegram
环境变量替代方案
用户可以在 shell 配置文件中设置环境变量,从而完全跳过此向导:
export OMC_SLACK_WEBHOOK_URL="https://hooks.slack.com/services/T00/B00/xxx"
export OMC_SLACK_MENTION="<@U1234567890>" # optional
通知系统会自动检测环境变量,无需 .omc-config.json。
Slack 提及格式
| 类型 | 格式 | 示例 |
|---|---|---|
| 用户 | <@MEMBER_ID> | <@U1234567890> |
| 频道 | <!channel> | <!channel> |
| 此处 | <!here> | <!here> |
| 所有人 | <!everyone> | <!everyone> |
| 用户组 | <!subteam^GROUP_ID> | <!subteam^S1234567890> |
平台激活标志
所有通知平台都需要通过每次会话的 CLI 标志来激活:
omc --telegram— 激活 Telegram 通知(设置OMC_TELEGRAM=1)omc --discord— 激活 Discord 通知(设置OMC_DISCORD=1)omc --slack— 激活 Slack 通知(设置OMC_SLACK=1)omc --webhook— 激活 webhook 通知(设置OMC_WEBHOOK=1)omc --openclaw— 激活 OpenClaw 网关集成(设置OMC_OPENCLAW=1)
如果没有这些标志,已配置的平台将保持休眠状态。这可以防止在开发期间收到不需要的通知,同时保持配置持久化。
示例:
omc --telegram --discord— Telegram + Discord 激活omc --telegram --slack --webhook— Telegram + Slack + Webhook 激活omc --telegram --openclaw— Telegram + OpenClaw 激活omc— 不发送通知(所有平台都需要显式激活)
Hook 事件模板
使用 omc_config.hook.json 按事件和平台自定义通知消息。
路由
如果触发条件或参数包含 "hook"、"template" 或 "customize messages" → 请遵循本节。
第 1 步:检测现有的 Hook 配置
检查 ${CLAUDE_CONFIG_DIR:-~/.claude}/omc_config.hook.json 是否存在。如果存在,显示当前配置。如果不存在,说明其作用。
Hook event templates let you customize the notification messages sent to each platform.
You can set different messages for Discord vs Telegram vs Slack, and control which
events fire on which platform.
Config file: ~/.claude/omc_config.hook.json
第 2 步:选择要配置的事件
使用 AskUserQuestion:
问题:"您想为哪个事件配置模板?"
选项:
- session-end - 当 Claude 会话结束时(最常见)
- ask-user-question - 当 Claude 等待输入时
- session-idle - 当 Claude 结束并等待输入时
- session-start - 当新会话开始时
第 3 步:显示可用变量
显示所选事件可用的模板变量:
Available template variables:
RAW FIELDS:
{{sessionId}} - Session identifier
{{timestamp}} - ISO timestamp
{{tmuxSession}} - tmux session name
{{projectPath}} - Full project directory path
{{projectName}} - Project directory basename
{{reason}} - Stop/end reason
{{activeMode}} - Active OMC mode name
{{question}} - Question text (ask-user-question only)
{{agentName}} - Agent name (agent-call only)
{{agentType}} - Agent type (agent-call only)
COMPUTED (smart formatting):
{{duration}} - Human-readable duration (e.g., "5m 23s")
{{time}} - Locale time string
{{modesDisplay}} - Comma-separated modes or empty
{{iterationDisplay}} - "3/10" format or empty
{{agentDisplay}} - "2/5 completed" or empty
{{projectDisplay}} - Project name with fallbacks
{{footer}} - tmux + project info line
{{tmuxTailBlock}} - Recent output in code fence or empty
{{reasonDisplay}} - Reason with "unknown" fallback
CONDITIONALS:
{{#if variableName}}content shown when truthy{{/if}}
第 4 步:收集模板
使用 AskUserQuestion:
问题:"输入此事件的消息模板(使用 {{variables}} 表示动态内容)"
选项:
- 使用默认模板 - 保留内置消息格式
- 简单摘要 - 简短的单行格式
- 自定义 - 输入您自己的模板
如果选择"简单摘要",使用预构建的紧凑模板:
- session-end:
{{projectDisplay}} session ended ({{duration}}) — {{reasonDisplay}} - ask-user-question:
Input needed on {{projectDisplay}}: {{question}} - session-idle:
{{projectDisplay}} is idle. {{#if reason}}Reason: {{reason}}{{/if}} - session-start:
Session started: {{projectDisplay}} at {{time}}
第 5 步:按平台覆盖
使用 AskUserQuestion:
问题:"您想为特定平台设置不同的消息吗?"
选项:
- 否,全部相同(推荐) - 在所有地方使用相同的模板
- 是,按平台自定义 - 为 Discord、Telegram、Slack 设置不同的模板
如果选择按平台:分别为每个已启用的平台询问模板。
第 6 步:写入配置
读取或创建 ${CLAUDE_CONFIG_DIR:-~/.claude}/omc_config.hook.json 并合并新设置:
{
"version": 1,
"enabled": true,
"events": {
"<event-name>": {
"enabled": true,
"template": "<user-provided-template>",
"platforms": {
"discord": { "template": "<discord-specific>" },
"telegram": { "template": "<telegram-specific>" }
}
}
}
}
步骤 7:验证与测试
使用 validateTemplate() 验证模板,检查是否存在未知变量。如果发现任何未知变量,警告用户并提供修正选项。
提供使用新模板发送测试通知的选项。
示例配置
{
"version": 1,
"enabled": true,
"events": {
"session-end": {
"enabled": true,
"template": "Session {{sessionId}} ended after {{duration}}. Reason: {{reasonDisplay}}",
"platforms": {
"discord": {
"template": "**Session Complete** | `{{projectDisplay}}` | {{duration}} | {{reasonDisplay}}"
},
"telegram": {
"template": "Done: {{projectDisplay}} ({{duration}})\n{{#if contextSummary}}Summary: {{contextSummary}}{{/if}}"
}
}
},
"ask-user-question": {
"enabled": true,
"template": "{{#if question}}{{question}}{{/if}}\nWaiting for input on {{projectDisplay}}"
}
}
}
相关
/oh-my-claudecode:configure-openclaw— 配置 OpenClaw 网关集成
自定义集成(OpenClaw、n8n、CLI 等)
为原生 Discord/Telegram/Slack 集成之外的服务配置自定义 webhook 和 CLI 命令。
路由
如果用户提到 "custom integration"、"openclaw"、"n8n"、"webhook"、"cli command" 或类似内容 → 遵循本节。
从 OpenClaw 迁移
如果 ~/.claude/omc_config.openclaw.json 存在,检测并提供迁移选项:
步骤 1:检测旧版配置
LEGACY_CONFIG="${CLAUDE_CONFIG_DIR:-$HOME/.claude}/omc_config.openclaw.json"
if [ -f "$LEGACY_CONFIG" ]; then
echo "LEGACY_FOUND=true"
# Check if already migrated
if jq -e '.customIntegrations.integrations[] | select(.preset == "openclaw")' "$CONFIG_FILE" >/dev/null 2>&1; then
echo "ALREADY_MIGRATED=true"
else
echo "ALREADY_MIGRATED=false"
fi
else
echo "LEGACY_FOUND=false"
fi
步骤 2:提供迁移选项 如果发现旧版配置且尚未迁移:
问题: "检测到现有的 OpenClaw 配置。是否要将其迁移到新格式?"
选项:
- 是,立即迁移 - 将旧版配置转换为自定义集成
- 否,全新配置 - 跳过迁移并重新开始
- 先让我看看旧版配置 - 显示当前的 OpenClaw 设置
如果选择迁移:
- 读取
omc_config.openclaw.json - 转换为自定义集成格式
- 保存到
.omc-config.json - 将旧版备份到
omc_config.openclaw.json.bak - 显示成功消息
自定义集成向导
步骤 1:选择集成类型
问题: "您想配置哪种类型的自定义集成?"
选项:
- OpenClaw Gateway - 唤醒外部自动化和 AI Agent
- n8n Webhook - 触发 n8n 工作流
- 自定义 Agent Gateway - 向自定义 Agent webhook 发送通知
- 通用 Webhook - 自定义 HTTPS webhook
- 通用 CLI 命令 - 在事件发生时执行 shell 命令
OpenClaw/n8n/自定义 Agent Gateway 预设流程
步骤 2:Gateway URL
问题: "您的 gateway/webhook URL 是什么?"
验证:
- 必须为 HTTPS(开发用的 localhost 除外)
- 必须为有效的 URL 格式
步骤 3:身份验证(可选)
问题: "您的 gateway 是否需要身份验证?"
选项:
- Bearer token - Authorization: Bearer
- 自定义 header - 名称和值
- 不进行身份验证
如果选择 Bearer:询问 token 如果选择自定义:询问 header 名称和值
步骤 4:事件
使用 AskUserQuestion 并启用 multiSelect:
问题: "哪些事件应触发此集成?"
选项(含预设默认值):
- session-start
- session-end
- session-stop
- session-idle
- ask-user-question
OpenClaw 默认值:session-start、session-end、stop n8n 默认值:session-end、ask-user-question
步骤 5:测试
问题: "是否发送测试通知以验证配置?"
选项:
- 是,立即测试 - 发送测试 webhook
- 否,跳过测试
如果选择测试:
# For webhook integrations
curl -X POST \
-H "Content-Type: application/json" \
${AUTH_HEADER:+"-H \"$AUTH_HEADER\""} \
-d '{"event":"test","instruction":"OMC test notification","timestamp":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' \
"$WEBHOOK_URL"
显示结果(HTTP 状态、任何错误)。
步骤 6:写入配置
合并到 .omc-config.json:
{
"notifications": { /* existing native configs */ },
"customIntegrations": {
"enabled": true,
"integrations": [
{
"id": "my-openclaw",
"type": "webhook",
"preset": "openclaw",
"enabled": true,
"config": {
"url": "https://my-gateway.example.com/wake",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer ..."
},
"bodyTemplate": "{\\"event\\":\\"{{event}}\\",\\"instruction\\":\\"Session {{sessionId}} {{event}}\\",\\"timestamp\\":\\"{{timestamp}}\\"}",
"timeout": 10000
},
"events": ["session-start", "session-end"]
}
]
}
}
通用 Webhook 流程
步骤 2:URL 询问 webhook URL(需要 HTTPS)。
步骤 3:方法 询问 HTTP 方法(GET、POST、PUT、PATCH、DELETE)。默认:POST。
步骤 4:Headers 以 "Name: Value" 格式询问 headers,每行一个。默认:Content-Type: application/json
步骤 5:请求体模板 显示可用的模板变量并询问请求体模板(JSON 或其他格式)。
默认:
{
"event": "{{event}}",
"sessionId": "{{sessionId}}",
"projectName": "{{projectName}}",
"timestamp": "{{timestamp}}"
}
步骤 6:超时 询问超时时间(毫秒,1000-60000)。默认:10000。
步骤 7:事件 多选事件。
步骤 8:测试并保存 与预设流程相同。
通用 CLI 命令流程
第 2 步:命令
问题: "应执行什么命令?(单个可执行文件,无参数)"
示例: curl、/usr/local/bin/my-script、notify-send
校验:
- 无空格
- 无 shell 元字符
第 3 步:参数
问题: "命令参数(使用 {{variable}} 表示动态值)。每行输入一个。"
示例:
-X
POST
-d
{"event":"{{event}}","session":"{{sessionId}}"}
https://my-api.com/notify
显示可用模板变量参考。
第 4 步:超时 询问超时时间(1000-60000ms)。默认:5000。
第 5 步:事件 多选事件。
第 6 步:测试并保存
测试时,使用测试值执行命令:
$COMMAND "${ARGS[@]//{{event}}/test}"
显示 stdout/stderr 和退出代码。
管理自定义集成
列出已有:
jq '.customIntegrations.integrations[] | {id, type, preset, enabled, events}' "$CONFIG_FILE"
禁用/启用:
# Disable
jq '.customIntegrations.integrations = [.customIntegrations.integrations[] | if .id == "my-integration" then .enabled = false else . end]' "$CONFIG_FILE"
# Enable
jq '.customIntegrations.integrations = [.customIntegrations.integrations[] | if .id == "my-integration" then .enabled = true else . end]' "$CONFIG_FILE"
移除:
jq '.customIntegrations.integrations = [.customIntegrations.integrations[] | select(.id != "my-integration")]' "$CONFIG_FILE"
模板变量参考
所有自定义集成均支持以下模板变量:
| 变量 | 描述 | 示例 |
|---|---|---|
{{sessionId}} | 唯一会话 ID | sess_abc123 |
{{projectPath}} | 完整项目路径 | /home/user/my-project |
{{projectName}} | 项目目录名称 | my-project |
{{timestamp}} | ISO 8601 时间戳 | 2026-03-05T14:30:00Z |
{{event}} | 事件名称 | session-end |
{{duration}} | 人类可读的持续时间 | 45s |
{{durationMs}} | 以毫秒为单位的持续时间 | 45000 |
{{reason}} | 停止/结束原因 | completed |
{{tmuxSession}} | tmux 会话名称 | claude:my-project |
仅 session-end:
{{agentsSpawned}}、{{agentsCompleted}}、{{modesUsed}}、{{contextSummary}}
仅 ask-user-question:
{{question}}
相关
- 模板变量:
src/notifications/template-variables.ts - 校验:
src/notifications/validation.ts - 预设:
src/notifications/presets.ts