slack
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseslack
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.
-
Check forin the environment before making Slack API calls.
SLACK_BOT_TOKEN- If is missing or empty, stop and tell the user to set up Slack at https://superwall.ai/integrations.
SLACK_BOT_TOKEN - Do not ask the user to paste the token into chat.
- If
-
Use Bun's built-into call Slack Web API endpoints.
fetch- Send the token with .
Authorization: Bearer ${process.env.SLACK_BOT_TOKEN} - Send JSON requests with unless the endpoint requires multipart form data.
Content-Type: application/json; charset=utf-8 - Check both the HTTP status and Slack's JSON field.
ok - Report Slack API errors by method name and value.
error
- Send the token with
-
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;
}-
Use Slack cursor pagination whenever the response includes.
response_metadata.next_cursor- Keep page sizes conservative for reads.
- Stop when is absent or empty.
next_cursor
-
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"
]
}
}-
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.
-
Use common Slack Web API methods according to the task:
- to verify the token and identify the workspace/app context.
auth.test - to list public channels and private channels permitted by scopes.
conversations.list - to read channel or group history.
conversations.history - to send messages.
chat.postMessage - or
users.listto inspect users.users.info - to inspect workspace details.
team.info - ,
files.uploadV2, and related file methods for file operations.files.info
-
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。
-
在调用Slack API之前,检查环境中是否存在。
SLACK_BOT_TOKEN- 如果缺失或为空,请停止操作并告知用户前往https://superwall.ai/integrations配置Slack。
SLACK_BOT_TOKEN - 不要要求用户在聊天中粘贴令牌。
- 如果
-
使用Bun内置的调用Slack Web API端点。
fetch- 通过发送令牌。
Authorization: Bearer ${process.env.SLACK_BOT_TOKEN} - 除非端点要求多部分表单数据,否则使用发送JSON请求。
Content-Type: application/json; charset=utf-8 - 同时检查HTTP状态和Slack返回的JSON中的字段。
ok - 通过方法名称和值报告Slack API错误。
error
- 通过
-
优先使用小型、针对特定任务的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;
}-
当响应包含时,使用Slack的游标分页功能。
response_metadata.next_cursor- 读取操作时保持页面大小适中。
- 当不存在或为空时停止分页。
next_cursor
-
至少默认拥有以下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"
]
}
}-
未来可能会添加更多权限范围。
- 当权限范围的可用性很重要时,请在判定操作无法执行之前,先查看Slack API获取应用可用的最新权限范围。
- 如果API报告缺少权限范围,请明确说明Slack所需的具体权限范围以及需要该权限的操作。
-
根据任务使用常用的Slack Web API方法:
- :验证令牌并确定工作区/应用上下文。
auth.test - :列出权限范围内允许的公开频道和私有频道。
conversations.list - :读取频道或群组历史记录。
conversations.history - :发送消息。
chat.postMessage - 或
users.list:查看用户信息。users.info - :查看工作区详情。
team.info - 、
files.uploadV2及相关文件方法:处理文件操作。files.info
-
写入操作需谨慎。
- 发送消息或上传文件时,除非用户已明确指定目标频道/用户和内容,否则请确认相关信息。
- 除非明确要求,否则不要删除、覆盖或广泛广播内容。