mcpField
S
slack-notifications

slack-notifications

github.com/oimiragieo生产力44288 次安装17 周前更新
代码仓库

关于 slack-notifications

slack-notifications 是通过 Agent 上下文按需调用 Slack API 操作的提示驱动技能,无需独立工具脚本。它覆盖消息、频道、用户、文件和表情回应,并要求确认消息变更与文件上传。

主要功能

  1. 01发送、更新和删除消息
  2. 02浏览频道及频道历史
  3. 03查询用户资料与在线状态
  4. 04上传和列出文件
  5. 05添加和查看表情回应

适用场景

  1. 01发送部署或事件通知
  2. 02查看频道历史与用户信息
  3. 03分享报告并回应消息

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/oimiragieo/agent-studio --skill slack-notifications

安装后在 Claude Code 中输入/slack-notifications确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

commands/
slack-notifications.md
hooks/
post-execute.cjs
pre-execute.cjs
references/
research-requirements.md
rules/
slack-notifications.md
schemas/
input.schema.json
output.schema.json
scripts/
main.cjs
templates/
implementation-template.md

详细介绍

模式:认知/提示词驱动 — 无独立实用脚本;请在 Agent 上下文中使用。

Slack 通知技能

概述

此技能提供 Slack API 操作,并采用渐进式披露,以优化上下文使用。

上下文节省:约减少 90%

  • MCP 模式:始终加载约 15,000 个 token(30 多个工具)
  • 技能模式:约 500 个 token 的元数据 + 按需加载

要求

  • SLACK_BOT_TOKEN 环境变量(必需)
  • SLACK_SIGNING_SECRET 环境变量(可选,用于事件验证)
  • SLACK_APP_TOKEN 环境变量(可选,用于 Socket Mode)
设置 Slack Bot Token
  1. 在 https://api.slack.com/apps 创建 Slack App
  2. 前往“OAuth & Permissions”
  3. 添加所需的 bot token 权限范围:
    • chat:write - 发送消息
    • channels:read - 列出频道
    • channels:history - 读取频道历史记录
    • users:read - 列出用户
    • files:write - 上传文件
    • reactions:write - 添加表情回应
  4. 将应用安装到工作区
  5. 将“Bot User OAuth Token”复制到 SLACK_BOT_TOKEN 环境变量

工具

该技能提供 5 个类别中的 14 个工具:

类别工具是否需要确认
消息post-message、post-thread、update-message、delete-message是(全部)
频道list-channels、get-channel、channel-history否
用户list-users、get-user、user-presence否
文件upload-file、list-files是(仅上传)
表情回应add-reaction、get-reactions否

快速参考

# Post message to channel
curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel": "C1234567890", "text": "Hello from Claude!"}'

# List channels
curl -X GET "https://slack.com/api/conversations.list" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

# Upload file
curl -X POST https://slack.com/api/files.upload \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -F "channels=C1234567890" \
  -F "[email protected]" \
  -F "title=Weekly Report"

工具详情

消息工具(需要确认)
post-message

向 Slack 频道发送消息。

参数:

  • channel(必需):频道 ID 或名称(例如,“C1234567890”或“#general”)
  • text(必需):消息文本(支持 Slack Markdown)
  • thread_ts(可选):用于线程回复的父消息时间戳
  • blocks(可选):富消息块(JSON 数组)

示例:

curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "C1234567890",
    "text": "Deployment successful!",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Deployment Status*\n:white_check_mark: Production deployed successfully"
        }
      }
    ]
  }'
post-thread

在线程中回复消息。

参数:

  • channel(必需):频道 ID
  • thread_ts(必需):父消息时间戳
  • text(必需):回复文本

示例:

curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "C1234567890",
    "thread_ts": "1234567890.123456",
    "text": "Thread reply here"
  }'
update-message

更新现有消息。

参数:

  • channel(必需):频道 ID
  • ts(必需):消息时间戳
  • text(必需):新消息文本

示例:

curl -X POST https://slack.com/api/chat.update \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "C1234567890",
    "ts": "1234567890.123456",
    "text": "Updated message"
  }'
delete-message

删除消息。

参数:

  • channel(必需):频道 ID
  • ts(必需):消息时间戳

示例:

curl -X POST https://slack.com/api/chat.delete \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "C1234567890",
    "ts": "1234567890.123456"
  }'
频道工具
list-channels

列出工作区中的所有频道。

参数:

  • types(可选):以逗号分隔的频道类型(默认值:“public_channel”)
    • 选项:“public_channel”、“private_channel”、“mpim”、“im”
  • limit(可选):返回的频道数上限(默认值:100)

示例:

curl -X GET "https://slack.com/api/conversations.list?types=public_channel,private_channel" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"
get-channel

获取频道信息。

参数:

  • channel(必需):频道 ID

示例:

curl -X GET "https://slack.com/api/conversations.info?channel=C1234567890" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"
channel-history

获取频道消息历史记录。

参数:

  • channel(必需):频道 ID
  • limit(可选):返回的消息数上限(默认值:100)
  • oldest(可选):时间范围的起始时间(Unix 时间戳)
  • latest(可选):时间范围的结束时间(Unix 时间戳)

示例:

curl -X GET "https://slack.com/api/conversations.history?channel=C1234567890&limit=50" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

安全提示:频道历史记录可能包含敏感信息。请谨慎使用。

用户工具
list-users

列出工作区中的所有用户。

参数:

  • limit(可选):返回的用户数上限(默认值:100)

示例:

curl -X GET "https://slack.com/api/users.list" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"
get-user

获取用户个人资料信息。

参数:

  • user(必需):用户 ID

示例:

curl -X GET "https://slack.com/api/users.info?user=U1234567890" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"
user-presence

获取用户在线状态。

参数:

  • user(必填):用户 ID

示例:

curl -X GET "https://slack.com/api/users.getPresence?user=U1234567890" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"
文件工具
upload-file(需要确认)

将文件上传到 Slack 频道。

参数:

  • channels(必填):以逗号分隔的频道 ID
  • file(必填):要上传的文件路径
  • title(可选):文件标题
  • initial_comment(可选):消息文本

示例:

curl -X POST https://slack.com/api/files.upload \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -F "channels=C1234567890" \
  -F "file=@C:\reports\weekly.pdf" \
  -F "title=Weekly Report" \
  -F "initial_comment=Here is this week's report"
list-files

列出频道中的文件。

参数:

  • channel(可选):用于筛选的频道 ID
  • user(可选):用于筛选的用户 ID
  • count(可选):最多返回的文件数(默认值:100)

示例:

curl -X GET "https://slack.com/api/files.list?channel=C1234567890" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"
表情回应工具
add-reaction

为消息添加表情回应。

参数:

  • channel(必填):频道 ID
  • timestamp(必填):消息时间戳
  • name(必填):表情名称(不带冒号,例如“thumbsup”)

示例:

curl -X POST https://slack.com/api/reactions.add \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "C1234567890",
    "timestamp": "1234567890.123456",
    "name": "thumbsup"
  }'
get-reactions

获取消息的表情回应。

参数:

  • channel(必填):频道 ID
  • timestamp(必填):消息时间戳

示例:

curl -X GET "https://slack.com/api/reactions.get?channel=C1234567890&timestamp=1234567890.123456" \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN"

Agent 集成

主要 Agent
  • devops:基础设施警报、部署通知、监控
  • incident-responder:事件警报、状态更新、升级处理
次要 Agent
  • pm:冲刺通知、里程碑更新、团队公告
  • developer:构建通知、PR 警报、测试结果
  • qa:测试失败警报、质量报告
  • security-architect:安全警报、漏洞通知

常见用例

部署通知
# Notify channel of successful deployment
curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#deployments",
    "text": ":rocket: Production deployment completed",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Production Deployment*\n:white_check_mark: v1.2.3 deployed successfully\n*Duration:* 5m 23s"
        }
      }
    ]
  }'
事件警报
# Alert on-call team of incident
curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#incidents",
    "text": "<!channel> :rotating_light: High severity incident detected",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Incident INC-1234*\n:rotating_light: *Severity:* P1\n*Service:* API Gateway\n*Status:* 503 errors increasing"
        }
      }
    ]
  }'
测试结果
# Post test results
curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#qa",
    "text": "Test suite completed",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Test Results*\n:white_check_mark: 245 passed\n:x: 3 failed\n:warning: 2 skipped"
        }
      }
    ]
  }'

安全注意事项

令牌安全
  • 绝不要在日志或错误消息中暴露机器人令牌
  • 将令牌存储在环境变量中,而不是代码中
  • 为机器人令牌使用最小权限范围
  • 定期轮换令牌
消息安全
  • 所有消息操作都需要确认
  • 频道历史记录可能包含敏感信息(PII、凭据等)
  • 发布前验证频道权限
  • 敏感通信使用私有频道
数据隐私
  • 遵守工作区数据保留政策
  • 避免在消息中发布 PII 或凭据
  • 使用 Slack 的数据导出功能以满足合规要求
  • 尊重用户隐私和在线状态

错误处理

常见错误
错误原因解决方案
not_authed缺少令牌或令牌无效检查是否正确设置了 SLACK_BOT_TOKEN
channel_not_found频道 ID 无效使用 list-channels 验证频道 ID
missing_scope机器人缺少所需权限在 Slack App 设置中添加权限范围
rate_limited请求过多实施指数退避
message_not_found时间戳无效检查消息时间戳是否正确
重试策略

对于速率限制错误,请实施指数退避:

  1. 等待 1 秒后重试
  2. 等待 2 秒后重试
  3. 等待 4 秒后重试
  4. 等待 8 秒后重试
  5. 5 次尝试后放弃

速率限制

Slack API 速率限制:

  • Tier 1:每秒 1 个请求
  • Tier 2:每分钟 20 个请求
  • Tier 3:每分钟 50 个请求
  • Tier 4:每分钟 100 个请求

各级别的方法:

  • chat.postMessage:Tier 3(每分钟 50 次)
  • conversations.list:Tier 2(每分钟 20 次)
  • users.list:Tier 2(每分钟 20 次)
  • files.upload:Tier 4(每分钟 100 次)

相关链接

Memory Protocol(必须遵守)

开始前: 阅读 .claude/context/memory/learnings.md

完成后:

  • 新模式 -> .claude/context/memory/learnings.md
  • 发现的问题 -> .claude/context/memory/issues.md
  • 做出的决定 -> .claude/context/memory/decisions.md

假设工作会被中断:如果未记录在记忆中,就等于从未发生。

评论

支持 Markdown