SuperAPI AI 工具集

configure-notifications

办公与效率

查看项目

更新于 10-15 14:56

技能介绍

用途

configure-notifications 是 oh-my-claudecode(OMC)中的一项交互式、自然语言配置技能,用于设置 OMC 的通知集成,使用户在会话结束、需要输入或后台任务完成时收到提醒。

主要能力

  • 支持三种通知渠道:Telegram、Discord、Slack。
  • 根据用户请求或参数中的关键词(telegram / discord / slack)自动路由到对应配置流程;若未指定,则通过 AskUserQuestion 询问用户选择。
  • 通过 AskUserQuestion 逐步收集配置信息,并将结果写入 ${CLAUDE_CONFIG_DIR:-~/.claude}/.omc-config.json。
  • 支持检测已有配置,并询问用户是更新还是重新配置。
  • 支持配置触发事件(多选):session end(推荐)、input needed、session start、session continuing;默认选择 session-end + ask-user-question。
  • 配置完成后可发送测试通知验证设置。
  • 支持通过环境变量替代向导,通知系统会自动检测环境变量,无需 .omc-config.json。

使用方式

Telegram

需要 Telegram bot token 和 chat ID。创建 bot:在 Telegram 搜索 @BotFather,发送 /newbot,设置名称和用户名,BotFather 会返回形如 123456789:ABCdefGHIjklMNOpqrsTUVwxyz 的 token。获取 chat ID:与 bot 开始对话(发送 /start),访问 https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates,查找 "chat":{"id":YOUR_CHAT_ID};个人 chat ID 为正数,群组为负数。

配置步骤:检测已有配置 → 创建 bot → 收集 bot token(校验格式 digits:alphanumeric)→ 收集 chat ID(校验为数字)→ 选择解析模式(Markdown 推荐 / HTML)→ 配置事件 → 写入配置 → 测试 → 确认。

写入配置示例:

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

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"

测试通知:

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!")

环境变量替代:

export OMC_TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
export OMC_TELEGRAM_CHAT_ID="123456789"

Discord

可选择 Webhook(推荐,无需 bot,粘贴 URL 即可)或 Bot API(bot token + channel ID)。Webhook URL 需以 https://discord.com/api/webhooks/ 或 https://discordapp.com/api/webhooks/ 开头。可配置提及(mention)用户或角色:用户格式 <@USER_ID>,角色格式 <@&ROLE_ID>。可设置自定义 bot 显示名(默认 OMC,可选 Claude Code 或自定义)。

Webhook 写入配置示例:

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"

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"

环境变量替代(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

Slack

需要创建 Slack Incoming Webhook。配置流程包括检测已有配置、创建 webhook、收集 webhook URL、配置提及与频道、配置事件、写入配置、测试与确认。

适用场景

  • 长时间运行的任务:当 Claude 等待用户响应时通过通知提醒。
  • 会话结束时希望收到提醒。
  • 后台任务完成时希望收到提醒。
  • 希望将 OMC 通知接入团队协作工具(Telegram / Discord / Slack)。

限制

  • 资料中 Slack 部分内容在 "To set up Slack notifications, you ne" 处截断,Slack 的完整配置步骤、写入配置示例、测试命令及环境变量名称暂未提供。
  • 各渠道的具体可用性、收费、价格、平台支持范围等资料未提供。
  • 通知的实际送达效果、延迟等资料未提供。