openclaw/docs/zh-CN/channels/group-messages.md

92 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
read_when:
- 更改群组消息规则或提及设置时
summary: WhatsApp 群组消息处理的行为和配置mentionPatterns 在各平台间共享)
title: 群组消息
x-i18n:
generated_at: "2026-02-03T10:05:00Z"
model: claude-opus-4-5
provider: pi
source_hash: 181a72f12f5021af77c2e4c913120f711e0c0bc271d218d75cb6fe80dab675bb
source_path: channels/group-messages.md
workflow: 15
---
# 群组消息WhatsApp 网页渠道)
目标:让 Clawd 留在 WhatsApp 群组中,仅在被提及时唤醒,并将该对话线程与个人私信会话分开。
注意:`agents.list[].groupChat.mentionPatterns` 现在也被 Telegram/Discord/Slack/iMessage 使用;本文档重点介绍 WhatsApp 特定的行为。对于多智能体设置,为每个智能体设置 `agents.list[].groupChat.mentionPatterns`(或使用 `messages.groupChat.mentionPatterns` 作为全局回退)。
## 已实现的功能2025-12-03
- 激活模式:`mention`(默认)或 `always`。`mention` 需要被提及(通过 `mentionedJids` 的真实 WhatsApp @提及、正则表达式模式,或文本中任意位置的机器人 E.164 号码)。`always` 会在每条消息时唤醒智能体,但它应该只在能提供有意义价值时才回复;否则返回静默令牌 `NO_REPLY`。默认值可在配置中设置(`channels.whatsapp.groups`),并可通过 `/activation` 为每个群组单独覆盖。当设置了 `channels.whatsapp.groups` 时,它同时充当群组允许列表(包含 `"*"` 以允许所有群组)。
- 群组策略:`channels.whatsapp.groupPolicy` 控制是否接受群组消息(`open|disabled|allowlist`)。`allowlist` 使用 `channels.whatsapp.groupAllowFrom`(回退:显式的 `channels.whatsapp.allowFrom`)。默认为 `allowlist`(在你添加发送者之前被阻止)。
- 独立群组会话:会话键格式为 `agent:<agentId>:whatsapp:group:<jid>`,因此 `/verbose on``/think high`(作为独立消息发送)等命令仅作用于该群组;个人私信状态不受影响。群组线程会跳过心跳。
- 上下文注入:**仅待处理**的群组消息(默认 50 条),即*未*触发运行的消息,会以 `[Chat messages since your last reply - for context]` 为前缀注入,触发行在 `[Current message - respond to this]` 下。已在会话中的消息不会重复注入。
- 发送者显示:每个群组批次现在以 `[from: Sender Name (+E164)]` 结尾,让 Pi 知道是谁在说话。
- 阅后即焚/一次性查看:我们在提取文本/提及之前会先解包这些消息,因此其中的提及仍会触发。
- 群组系统提示:在群组会话的第一轮(以及每当 `/activation` 更改模式时),我们会向系统提示注入一段简短说明,如 `You are replying inside the WhatsApp group "<subject>". Group members: Alice (+44...), Bob (+43...), … Activation: trigger-only … Address the specific sender noted in the message context.` 如果元数据不可用,我们仍会告知智能体这是一个群聊。
## 配置示例WhatsApp
`~/.openclaw/openclaw.json` 中添加 `groupChat` 块,以便在 WhatsApp 剥离文本正文中的可视 `@` 时,显示名称提及仍能正常工作:
```json5
{
channels: {
whatsapp: {
groups: {
"*": { requireMention: true },
},
},
},
agents: {
list: [
{
id: "main",
groupChat: {
historyLimit: 50,
mentionPatterns: ["@?openclaw", "\\+?15555550123"],
},
},
],
},
}
```
注意:
- 正则表达式不区分大小写;它们涵盖了像 `@openclaw` 这样的显示名称提及,以及带或不带 `+`/空格的原始号码。
- 当有人点击联系人时WhatsApp 仍会通过 `mentionedJids` 发送规范的提及,因此号码回退很少需要,但作为安全网很有用。
### 激活命令(仅所有者)
使用群聊命令:
- `/activation mention`
- `/activation always`
只有所有者号码(来自 `channels.whatsapp.allowFrom`,或未设置时使用机器人自己的 E.164)可以更改此设置。在群组中发送 `/status` 作为独立消息以查看当前激活模式。
## 使用方法
1. 将你的 WhatsApp 账号(运行 OpenClaw 的账号)添加到群组。
2.`@openclaw …`(或包含号码)。只有允许列表中的发送者才能触发,除非你设置 `groupPolicy: "open"`
3. 智能体提示将包含最近的群组上下文以及尾部的 `[from: …]` 标记,以便它能够回应正确的人。
4. 会话级指令(`/verbose on`、`/think high`、`/new` 或 `/reset`、`/compact`)仅适用于该群组的会话;将它们作为独立消息发送以使其生效。你的个人私信会话保持独立。
## 测试/验证
- 手动冒烟测试:
- 在群组中发送 `@openclaw` 提及,确认收到引用发送者名称的回复。
- 发送第二次提及,验证历史记录块被包含,然后在下一轮清除。
- 检查 Gateway 网关日志(使用 `--verbose` 运行)以查看 `inbound web message` 条目,显示 `from: <groupJid>``[from: …]` 后缀。
## 已知注意事项
- 群组有意跳过心跳以避免嘈杂的广播。
- 回声抑制使用组合的批次字符串;如果你发送两次相同的文本但没有提及,只有第一次会得到响应。
- 会话存储条目将在会话存储中显示为 `agent:<agentId>:whatsapp:group:<jid>`(默认为 `~/.openclaw/agents/<agentId>/sessions/sessions.json`);缺失条目只是意味着该群组尚未触发运行。
- 群组中的输入指示器遵循 `agents.defaults.typingMode`(默认:未被提及时为 `message`)。