Mattermost 是一款开源的自托管团队即时通讯平台,是企业内部替代 Slack 的热门选择。通过 OpenClaw 的 Mattermost 插件,你可以在内部 Mattermost 实例中部署 AI Agent,提供智能对话服务。
支持功能
- ✅ 频道消息(Channels)
- ✅ 群组消息(Groups)
- ✅ 私信(Direct Messages)
- ✅ 消息反应(Reactions)
- ✅ 多账号管理
- ✅ 消息目标发送(频道/用户)
第一步:安装 Mattermost 插件
openclaw plugins install @openclaw/mattermost本地开发:
openclaw plugins install ./extensions/mattermost第二步:创建 Bot 账号
在 Mattermost 管理面板中:
- 进入 System Console → Integrations → Bot Accounts
- 创建一个新 Bot,保存生成的 Bot Token
- 将 Bot 添加到需要的频道或团队
- 记录 Mattermost 实例的 Base URL(如
https://chat.yourcompany.com)
第三步:配置 OpenClaw
最简配置
{
"channels": {
"mattermost": {
"enabled": true,
"botToken": "your-mm-bot-token",
"baseUrl": "https://chat.example.com",
"dmPolicy": "pairing"
}
}
}使用环境变量
export MATTERMOST_BOT_TOKEN="your-token"
export MATTERMOST_URL="https://chat.example.com"注意:环境变量只对默认账号生效,多账号配置必须使用配置文件。
聊天模式(Chat Modes)
Mattermost 支持三种频道聊天模式:
| 模式 | 说明 |
|---|---|
oncall(默认) | 只在被 @提及 时响应 |
onmessage | 响应所有频道消息 |
onchar | 消息以指定前缀开头时响应 |
{
"channels": {
"mattermost": {
"chatmode": "onchar",
"oncharPrefixes": [">", "!"]
}
}
}onchar 模式仍然响应显式的 @提及。
访问控制
私信访问
{
"channels": {
"mattermost": {
"dmPolicy": "pairing"
}
}
}审批未知用户:
openclaw pairing list mattermost
openclaw pairing approve mattermost <CODE>开放私信
{
"channels": {
"mattermost": {
"dmPolicy": "open",
"allowFrom": ["*"]
}
}
}频道(群组)访问控制
默认采用 allowlist 策略(@提及限制):
{
"channels": {
"mattermost": {
"groupPolicy": "allowlist",
"groupAllowFrom": ["user-id-1", "user-id-2"]
}
}
}建议使用 User ID 而不是用户名(用户名可变,而 dangerouslyAllowNameMatching 默认关闭)。
消息反应配置
{
"channels": {
"mattermost": {
"actions": {
"reactions": true
}
}
}
}使用 message 工具发送反应:
message action=react channel=mattermost target=channel:<channelId> messageId=<postId> emoji=thumbsup
# 移除反应
message action=react channel=mattermost target=channel:<channelId> messageId=<postId> emoji=thumbsup remove=true
emoji 接受 thumbsup 或 :+1: 格式(冒号可选)。
外发消息目标格式
使用 openclaw message send 或 Cron 发送消息时:
| 格式 | 说明 |
|---|---|
channel:<id> | 发送到频道 |
user:<id> | 发送到用户私信 |
@username | 通过 API 解析用户名后发送 |
| 裸 ID | 默认视为频道 ID |
多账号配置
同时管理多个 Mattermost 实例:
{
"channels": {
"mattermost": {
"accounts": {
"internal": {
"botToken": "token-1",
"baseUrl": "https://internal.company.com"
},
"customer": {
"botToken": "token-2",
"baseUrl": "https://support.company.com"
}
}
}
}
}常见问题
Bot 没有收到消息? 确认 Bot 已加入对应频道或团队,且 Bot Token 权限包含读写频道消息。
chatmode 没有生效?
旧版配置中的 requireMention 字段仍然兼容,但推荐迁移到 chatmode 字段。
群组策略不生效?
如果 channels.mattermost 配置完全缺失,运行时会回退到 groupPolicy="allowlist",即使 channels.defaults.groupPolicy 有其他设置。
原文:Mattermost - OpenClaw | 来源:OpenClaw 官方文档