slack

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

slack

slack

Use this skill when a task requires reading from Slack, posting to Slack, uploading or downloading Slack files, inspecting Slack users/channels/teams, or otherwise interacting with Slack data.
当任务需要读取Slack内容、发布消息到Slack、上传或下载Slack文件、查看Slack用户/频道/团队信息,或者以其他方式与Slack数据交互时,使用此技能。

When to use

适用场景

  • The user asks to read, search, summarize, or inspect Slack channels, groups, mentions, messages, users, teams, or files.
  • The user asks to send, draft, or post a Slack message.
  • The user asks to upload, fetch, or inspect Slack files.
  • The user asks to build or debug Slack automation that should use the Slack REST API.
  • 用户要求读取、搜索、汇总或查看Slack频道、群组、提及内容、消息、用户、团队或文件。
  • 用户要求发送、草拟或发布Slack消息。
  • 用户要求上传、获取或查看Slack文件。
  • 用户要求构建或调试应使用Slack REST API的Slack自动化流程。

Instructions

使用说明

Use the Slack REST API directly from Bun.
  1. Check for
    SLACK_BOT_TOKEN
    in the environment before making Slack API calls.
    • If
      SLACK_BOT_TOKEN
      is missing or empty, stop and tell the user to set up Slack at https://superwall.ai/integrations.
    • Do not ask the user to paste the token into chat.
  2. Use Bun's built-in
    fetch
    to call Slack Web API endpoints.
    • Send the token with
      Authorization: Bearer ${process.env.SLACK_BOT_TOKEN}
      .
    • Send JSON requests with
      Content-Type: application/json; charset=utf-8
      unless the endpoint requires multipart form data.
    • Check both the HTTP status and Slack's JSON
      ok
      field.
    • Report Slack API errors by method name and
      error
      value.
  3. Prefer small, task-specific Bun scripts for Slack work.
ts
const token = process.env.SLACK_BOT_TOKEN;

if (!token) {
  throw new Error(
    "SLACK_BOT_TOKEN is not set. Set up Slack at https://superwall.ai/integrations."
  );
}

async function slack(method: string, body: Record<string, unknown> = {}) {
  const response = await fetch(`https://slack.com/api/${method}`, {
    method: "POST",
    headers: {
      authorization: `Bearer ${token}`,
      "content-type": "application/json; charset=utf-8",
    },
    body: JSON.stringify(body),
  });

  const data = await response.json();

  if (!response.ok || !data.ok) {
    throw new Error(`${method} failed: ${data.error ?? response.statusText}`);
  }

  return data;
}
  1. Use Slack cursor pagination whenever the response includes
    response_metadata.next_cursor
    .
    • Keep page sizes conservative for reads.
    • Stop when
      next_cursor
      is absent or empty.
  2. Treat the following bot scopes as available at minimum:
json
{
  "scopes": {
    "bot": [
      "app_mentions:read",
      "channels:read",
      "channels:history",
      "chat:write",
      "chat:write.public",
      "files:write",
      "files:read",
      "team:read",
      "users:read",
      "groups:history"
    ]
  }
}
  1. More scopes may be added over time.
    • When scope availability matters, check the Slack API for the up-to-date scopes available to the app before deciding an operation is impossible.
    • If the API reports a missing scope, state the exact scope Slack requires and the operation that needs it.
  2. Use common Slack Web API methods according to the task:
    • auth.test
      to verify the token and identify the workspace/app context.
    • conversations.list
      to list public channels and private channels permitted by scopes.
    • conversations.history
      to read channel or group history.
    • chat.postMessage
      to send messages.
    • users.list
      or
      users.info
      to inspect users.
    • team.info
      to inspect workspace details.
    • files.uploadV2
      ,
      files.info
      , and related file methods for file operations.
  3. Be careful with writes.
    • For sending messages or uploading files, confirm the target channel/user and content unless the user has already made both explicit.
    • Do not delete, overwrite, or broadly broadcast content unless explicitly requested.
直接通过Bun使用Slack REST API。
  1. 在调用Slack API之前,检查环境中是否存在
    SLACK_BOT_TOKEN
  2. 使用Bun内置的
    fetch
    调用Slack Web API端点。
    • 通过
      Authorization: Bearer ${process.env.SLACK_BOT_TOKEN}
      发送令牌。
    • 除非端点要求多部分表单数据,否则使用
      Content-Type: application/json; charset=utf-8
      发送JSON请求。
    • 同时检查HTTP状态和Slack返回的JSON中的
      ok
      字段。
    • 通过方法名称和
      error
      值报告Slack API错误。
  3. 优先使用小型、针对特定任务的Bun脚本处理Slack相关工作。
ts
const token = process.env.SLACK_BOT_TOKEN;

if (!token) {
  throw new Error(
    "SLACK_BOT_TOKEN is not set. Set up Slack at https://superwall.ai/integrations."
  );
}

async function slack(method: string, body: Record<string, unknown> = {}) {
  const response = await fetch(`https://slack.com/api/${method}`, {
    method: "POST",
    headers: {
      authorization: `Bearer ${token}`,
      "content-type": "application/json; charset=utf-8",
    },
    body: JSON.stringify(body),
  });

  const data = await response.json();

  if (!response.ok || !data.ok) {
    throw new Error(`${method} failed: ${data.error ?? response.statusText}`);
  }

  return data;
}
  1. 当响应包含
    response_metadata.next_cursor
    时,使用Slack的游标分页功能。
    • 读取操作时保持页面大小适中。
    • next_cursor
      不存在或为空时停止分页。
  2. 至少默认拥有以下bot权限范围:
json
{
  "scopes": {
    "bot": [
      "app_mentions:read",
      "channels:read",
      "channels:history",
      "chat:write",
      "chat:write.public",
      "files:write",
      "files:read",
      "team:read",
      "users:read",
      "groups:history"
    ]
  }
}
  1. 未来可能会添加更多权限范围。
    • 当权限范围的可用性很重要时,请在判定操作无法执行之前,先查看Slack API获取应用可用的最新权限范围。
    • 如果API报告缺少权限范围,请明确说明Slack所需的具体权限范围以及需要该权限的操作。
  2. 根据任务使用常用的Slack Web API方法:
    • auth.test
      :验证令牌并确定工作区/应用上下文。
    • conversations.list
      :列出权限范围内允许的公开频道和私有频道。
    • conversations.history
      :读取频道或群组历史记录。
    • chat.postMessage
      :发送消息。
    • users.list
      users.info
      :查看用户信息。
    • team.info
      :查看工作区详情。
    • files.uploadV2
      files.info
      及相关文件方法:处理文件操作。
  3. 写入操作需谨慎。
    • 发送消息或上传文件时,除非用户已明确指定目标频道/用户和内容,否则请确认相关信息。
    • 除非明确要求,否则不要删除、覆盖或广泛广播内容。