跳到主要内容

Slack 设置

概述

Slack channel 把 Anyy 连接到 Slack DM、channel 和 thread。Adapter 支持 inbound media、thread context、lifecycle startup 和 live-smoke 检查。

如果配置了 app token,Slack 接收侧使用 Socket Mode。发送仍需要 bot token。

前提条件

  • 一个 Slack app 和 bot token。
  • 如果 Anyy 要接收消息,需要 app-level token。
  • App 已安装到 workspace。
  • Bot 已加入需要响应的 channel。
  • 如果要显式过滤自己消息,准备 bot user id。

配置

创建凭据

创建 Slack bot token。Resident 接收消息时,还需要 app-level token。两个值都应通过 Anyy secrets 保存。

配置 Anyy

anyy setup channels slack \
--secret bot_token='xoxb-...' \
--secret app_token='xapp-...' \
--write-config

app_token 在 helper 中是可选 secret,但没有它时 resident Slack adapter 没有 Socket Mode receiver。

setup 默认值:

字段默认值
account_idwork
dm_policypairing
group_policymention
media_max_bytes5242880

可选运行字段:

channels:
slack:
bot_user_id: "U0123456789"
send_chunk_chars: 3800

启动 Gateway

anyy gateway start
anyy channels reload

运行 Doctor 检查

anyy channels doctor slack

访问策略

私信

setup 默认 dm_policy: pairing。如果只允许特定 Slack 用户,使用 allowlistallow_from

群组

setup 默认 group_policy: mention。Slack channel 里默认只有提到 bot 才会响应。

使用 allowlist 时,在 allow_groups 中写 channel id。

管理员

Slack access policy 决定消息能否进入 Anyy。管理类命令由共享 messaging command 权限控制。

Sessions

Anyy 会按 Slack DM、channel 或 thread 分开保存 session。Thread timestamp 会保留,回复可以留在 thread 中。

媒体支持

入站媒体

Slack 声明支持 inbound media。文件受 media_max_bytes 限制。

出站媒体

这个 adapter 没有声明原生 outbound media。生成 artifact 仍保留在 session 中。

命令

在 Slack 中使用普通 messaging commands。Channel 中如策略要求 mention,需要提到 bot。

Cron 投递

anyy cron create \
--name "Slack digest" \
--schedule "0 9 * * *" \
--prompt "Post the daily digest" \
--delivery-target current_user_default \
--delivery-channel slack

故障排查

  • 收不到消息:确认 Socket Mode 已开启,且 app_token_ref 可解析。
  • 无法回复:确认 bot token 和 channel membership。
  • Channel 消息被忽略:提到 bot 或调整 group_policy
  • 不该访问的人被接受:使用 dm_policy: allowlistallow_from