群(群聊天)
OpenClaw 在各平台对群聊的处理一致:WhatsApp、Telegram、Discord、Slack、Signal、iMessage、Microsoft Teams。新手简介(2 分钟)
OpenClaw 运行在你自己的消息账号上。没有单独的 WhatsApp bot 用户。 如果 你 在一个群里,OpenClaw 就能看到该群并在那里回复。 默认行为:- 群聊受限(
groupPolicy: "allowlist")。 - 回复需要被 mention,除非你显式禁用 mention gating。
TL;DR快速流程(群消息会发生什么):
- DM 访问 由
*.allowFrom控制。- 群访问 由
*.groupPolicy+ allowlists(*.groups、*.groupAllowFrom)控制。- 触发回复 由 mention gating 控制(
requireMention、/activation)。
| 目标 | 需要设置 |
|---|---|
| 允许所有群,但只在 @mentions 时回复 | groups: { "*": { requireMention: true } } |
| 禁用所有群回复 | groupPolicy: "disabled" |
| 只允许指定群 | groups: { "<group-id>": { ... } }(不含 "*") |
| 只有你能在群中触发 | groupPolicy: "allowlist", groupAllowFrom: ["+1555..."] |
Session keys
- 群会话使用
agent:<agentId>:<channel>:group:<id>session key(房间/频道使用agent:<agentId>:<channel>:channel:<id>)。 - Telegram forum topic 会在 group id 后追加
:topic:<threadId>,每个话题有独立会话。 - 私聊使用 main 会话(或按发送者配置)。
- 群会话跳过心跳。
模式:个人 DMs + 公共群(单 agent)
可以 —— 当你的“个人”流量是 DMs,“公开”流量是 群聊 时非常合适。 原因:在单 agent 模式下,DM 通常进入 main session key(agent:main:main),而群聊总是使用 非 main session key(agent:main:<channel>:group:<id>)。如果启用 mode: "non-main" 的 sandbox,那么群会话在 Docker 中运行,main DM 会话仍在主机上运行。
这让你拥有一个 agent “大脑”(共享 workspace + memory),但有两种执行姿态:
- DMs:完整工具(主机)
- Groups:sandbox + 受限工具(Docker)
如果你需要真正独立的 workspace/persona(“personal” 与 “public” 不能混),请使用第二个 agent + bindings。见 Multi-Agent Routing。示例(DMs 在主机、群聊 sandbox + 仅消息工具):
workspaceAccess: "none",并只挂载允许的路径到 sandbox:
- 配置键与默认值:Gateway configuration
- 排查工具被阻止原因:Sandbox vs Tool Policy vs Elevated
- Bind mounts 细节:Sandboxing
显示标签
- UI 标签优先使用
displayName,格式为<channel>:<token>。 #room保留给房间/频道;群聊使用g-<slug>(小写,空格 ->-,保留#@+._-)。
群策略
按频道控制群/房间消息的处理:| Policy | 行为 |
|---|---|
"open" | 群聊绕过 allowlist;仍受 mention gating 约束。 |
"disabled" | 完全阻止所有群消息。 |
"allowlist" | 仅允许匹配 allowlist 的群/房间。 |
groupPolicy与 mention gating 分离(后者要求 @mentions)。- WhatsApp/Telegram/Signal/iMessage/Microsoft Teams:使用
groupAllowFrom(回退到显式allowFrom)。 - Discord:allowlist 使用
channels.discord.guilds.<id>.channels。 - Slack:allowlist 使用
channels.slack.channels。 - Matrix:allowlist 使用
channels.matrix.groups(房间 ID、别名或名称)。可用channels.matrix.groupAllowFrom限制发送者;也支持按房间的usersallowlist。 - Group DMs 单独控制(
channels.discord.dm.*、channels.slack.dm.*)。 - Telegram allowlist 可匹配 user IDs(
"123456789"、"telegram:123456789"、"tg:123456789")或用户名("@alice"或"alice");前缀不区分大小写。 - 默认
groupPolicy: "allowlist";若 group allowlist 为空,群消息会被阻止。
groupPolicy(open/disabled/allowlist)- group allowlists(
*.groups、*.groupAllowFrom、频道特定 allowlist) - mention gating(
requireMention、/activation)
Mention gating(默认)
群消息默认需要 mention,除非对单群覆盖。默认值在各子系统的*.groups."*" 下。
回复 bot 消息也算隐式 mention(当频道支持回复元数据时)。适用于 Telegram、WhatsApp、Slack、Discord、Microsoft Teams。
mentionPatterns是不区分大小写的正则。- 有原生 mention 的平台仍会通过;patterns 仅作兜底。
- 每 agent 覆盖:
agents.list[].groupChat.mentionPatterns(多 agent 共用群时很有用)。 - mention gating 仅在可检测 mention 时生效(原生 mentions 或配置了
mentionPatterns)。 - Discord 默认值在
channels.discord.guilds."*"下(可对 guild/channel 覆盖)。 - 群历史上下文在各频道统一封装,且 仅 pending(因 mention gating 被跳过的消息);全局默认使用
messages.groupChat.historyLimit,覆盖使用channels.<channel>.historyLimit(或channels.<channel>.accounts.*.historyLimit)。设为0可禁用。
群/频道工具限制(可选)
部分频道支持在 特定群/房间/频道内 限制可用工具。tools:对整个群的 allow/deny。toolsBySender:群内按发送者覆盖(键为发送者 ID/用户名/邮箱/手机号,取决于频道)。使用"*"作为通配符。
- 群/频道
toolsBySender命中 - 群/频道
tools - 默认(
"*")toolsBySender命中 - 默认(
"*")tools
- 群/频道工具限制会叠加在全局/agent 工具策略之上(deny 仍优先)。
- 不同频道对房间/频道的嵌套层级不同(如 Discord
guilds.*.channels.*、Slackchannels.*、MS Teamsteams.*.channels.*)。
群 allowlists
当配置channels.whatsapp.groups、channels.telegram.groups 或 channels.imessage.groups 时,键会作为群 allowlist。使用 "*" 可允许所有群,同时保留默认 mention 行为。
常见意图(可直接复制):
- 禁用所有群回复
- 仅允许特定群(WhatsApp)
- 允许所有群但必须 mention(显式)
- 仅 owner 可在群中触发(WhatsApp)
Activation(仅 owner)
群 owner 可切换每个群的激活模式:/activation mention/activation always
channels.whatsapp.allowFrom 决定(未设置时使用机器人自身 E.164)。请以独立消息发送该命令。其他平台目前忽略 /activation。
Context fields
群入站 payload 会设置:ChatType=groupGroupSubject(若已知)GroupMembers(若已知)WasMentioned(mention gating 结果)- Telegram forum 话题还包含
MessageThreadId与IsForum。
\n 序列。
iMessage 特性
- 路由或 allowlist 时优先使用
chat_id:<id>。 - 列出聊天:
imsg chats --limit 20。 - 群回复始终回到同一
chat_id。