基于源码
src/agents/tools/message-tool.ts分析,经 claude2 review 确认。
基本信息
- 工具名:
message - 描述(动态构建,典型值):
Send, delete, and manage messages across configured channels. - 调用方:Agent 在 turn 内自主调用,无需人工介入
- 底层实现:
runMessageAction(与 CLIopenclaw message命令共用同一路径)
核心参数
| 参数 | 类型 | 说明 |
|---|---|---|
action | string(必填) | 操作类型(见下方列表) |
channel | string | channel 名,配置多个 channel 时必填 |
target | string | 消息目标(用户/频道/群 ID) |
targets | string[] | 广播时传多个目标 |
message | string | 消息文本内容 |
media | string | 媒体 URL 或本地路径 |
buffer | string | Base64 附件内容(支持 data: URL) |
contentType | string | 媒体 MIME 类型 |
caption | string | 媒体标题 |
presentation | object | 语义化富文本 payload(按钮/选项等) |
accountId | string | 多账号时指定账号 |
replyTo | string | 回复目标消息 ID |
threadId | string | 指定线程 |
asVoice | boolean | 以语音形式发送音频 |
silent | boolean | 静默发送(Telegram/Discord) |
forceDocument | boolean | 强制作为文件发送,避免压缩(Telegram) |
bestEffort | boolean | 失败时降级处理 |
dryRun | boolean | 模拟执行,不实际发送 |
支持的 action
发送类
| action | 说明 | 典型场景 |
|---|---|---|
send | 发送消息/媒体 | 主动发、跨 channel 投递 |
reply | 回复当前或指定消息 | 引用回复 |
thread-reply | 线程回复 | Slack/Discord 线程 |
sendWithEffect | 带特效发送 | iMessage invisible ink、balloons 等 |
sendAttachment | 发送附件 | 文件投递 |
upload-file | 上传文件获取 file_id | 先上传再引用 |
broadcast | 广播到多个 target | targets 传多个,或 --channel all |
互动类
| action | 说明 |
|---|---|
react | 表情回应 |
poll | 发起投票 |
vote | 投票(参与已有投票) |
管理类
| action | 说明 |
|---|---|
edit | 编辑已发消息 |
delete / unsend | 删除/撤回消息 |
pin / unpin | 置顶/取消置顶 |
read | 读取历史消息 |
renameGroup | 重命名群 |
setGroupIcon | 设置群图标 |
完整 action 列表 50+ 个,以上为常用子集。具体 channel 支持哪些 action 由插件能力声明决定,schema 会动态过滤。
presentation 富文本 payload
presentation 实现跨 channel 的语义化富文本,OpenClaw 自动渲染为各 channel 原生组件。
{
"title": "标题(可选)",
"tone": "success",
"blocks": [
{ "type": "text", "text": "正文内容" },
{ "type": "context", "text": "小字说明" },
{ "type": "divider" },
{
"type": "buttons",
"buttons": [
{ "label": "确认", "value": "confirm", "style": "success" },
{ "label": "取消", "value": "cancel", "style": "danger" },
{ "label": "打开链接", "url": "https://example.com" }
]
},
{
"type": "select",
"placeholder": "请选择",
"options": [
{ "label": "选项A", "value": "a" },
{ "label": "选项B", "value": "b" }
]
}
]
}tone 可选值:info | success | warning | danger | neutral
tone是否生效取决于 channel 能力,部分 channel 会忽略 tone 只渲染 blocks。
各 channel 渲染映射:
| channel | 渲染方式 |
|---|---|
| 飞书 | 飞书交互卡片 |
| Slack | Block Kit |
| Discord | Components |
| Telegram | Inline buttons |
| Teams | Adaptive Cards |
NO_REPLY 机制
当 Agent 已经通过 message(action=send)向当前对话发送了用户可见回复时,最终文本答复必须只输出 NO_REPLY,避免重复发送。
# 系统提示约定:
If you use `message` (`action=send`) to deliver your user-visible reply,
respond with ONLY: NO_REPLY (avoid duplicate replies).
channel 支持范围
系统提示中的内置枚举:
telegram | whatsapp | discord | googlechat | slack | signal | imessage | feishu
外部插件注册后自动扩展(wecom、qqbot、ddingtalk 等)。channel 列表与 CLI 命令共用同一动态发现机制。
inline buttons 限制
webchat 默认不支持 inline buttons。需要时在配置中开启:
{
"channels": {
"webchat": {
"capabilities": {
"inlineButtons": "dm"
}
}
}
}inlineButtons 可选值:"dm" | "group" | "all" | "allowlist"
与 CLI 命令对比
| 维度 | openclaw message(CLI) | message tool(Agent) |
|---|---|---|
| 调用方 | 人工/脚本 | Agent 自主调用 |
| 触发方式 | 命令行执行 | turn 内 function call |
| 底层函数 | runMessageAction | 同一个 runMessageAction |
| 参数形式 | CLI flags | TypeBox JSON schema |
| channel 范围 | 内置 + 外部插件(动态) | 同上 |
| schema 裁剪 | 固定 | 动态(按当前 channel 能力过滤) |
相关链接
- message-send-channels — 五个 channel(飞书/微信/企业微信/QQ/钉钉)使用指南
- docs/cli/message — openclaw message CLI 参考
- docs/tools/agent-send — openclaw agent CLI(触发 Agent turn)