Microsoft Teams 作为内置插件随 OpenClaw 发布,无需单独安装。支持文本 + DM 附件;频道/群组文件发送需要 sharePointSiteId + Graph 权限。
快速配置(使用 Teams CLI)
# 安装并登录
npm install -g @microsoft/teams.cli@preview
teams login
# 创建 devtunnel(Teams 无法访问 localhost)
devtunnel create my-openclaw-bot --allow-anonymous
devtunnel port create my-openclaw-bot -p 3978 --protocol auto
devtunnel host my-openclaw-bot
# 创建 Teams app
teams app create \
--name "OpenClaw" \
--endpoint "https://<your-tunnel-url>/api/messages"配置 OpenClaw:
{
channels: {
msteams: {
enabled: true,
appId: "<CLIENT_ID>",
appPassword: "<CLIENT_SECRET>",
tenantId: "<TENANT_ID>",
webhook: { port: 3978, path: "/api/messages" },
},
},
}环境变量:MSTEAMS_APP_ID、MSTEAMS_APP_PASSWORD、MSTEAMS_TENANT_ID
访问控制
- DM:默认
dmPolicy: "pairing",使用稳定的 AAD object ID 作为allowFrom - 群组:默认
groupPolicy: "allowlist",需配置groupAllowFrom - 不建议依赖 UPN/显示名匹配(可变),默认禁用;需要时设
dangerouslyAllowNameMatching: true
联合认证(生产环境推荐)
证书认证
{
channels: {
msteams: {
appId: "<APP_ID>",
tenantId: "<TENANT_ID>",
authType: "federated",
certificatePath: "/path/to/cert.pem",
},
},
}Azure 托管标识
{
channels: {
msteams: {
appId: "<APP_ID>",
tenantId: "<TENANT_ID>",
authType: "federated",
useManagedIdentity: true,
},
},
}| 认证方式 | 优点 | 缺点 |
|---|---|---|
| 客户端密钥 | 配置简单 | 需要轮换,安全性较低 |
| 证书 | 无共享密钥 | 证书管理开销 |
| 托管标识 | 无密码,无需管理密钥 | 需要 Azure 基础设施 |
回复样式(replyStyle)
Teams 有两种频道 UI 样式,API 不暴露使用哪种:
| UI 样式 | 推荐 replyStyle |
|---|---|
| Posts(经典,带线程回复) | thread(默认) |
| Threads(类 Slack 线性) | top-level |
{
channels: {
msteams: {
replyStyle: "thread",
teams: {
"19:abc...@thread.tacv2": {
channels: {
"19:xyz...@thread.tacv2": { replyStyle: "top-level" },
},
},
},
},
},
}群组文件发送
DM 文件发送开箱即用;群组/频道文件发送需要 SharePoint:
{
channels: {
msteams: {
sharePointSiteId: "contoso.sharepoint.com,guid1,guid2",
},
},
}需要 Graph 权限:Sites.ReadWrite.All(Application)。
目标格式
| 类型 | 格式 |
|---|---|
| 用户(ID) | user:<aad-object-id> |
| 用户(名称) | user:<display-name>(需 Graph API) |
| 群组/频道 | conversation:<conversation-id> |
常见问题
- 频道图片不显示:缺少 Graph 权限或 admin consent,重装 Teams app 并完全退出重启 Teams
- 频道无响应:默认需要 @mention,设
requireMention: false或按团队/频道配置 - 401 Unauthorized:手动测试时预期行为,使用 Azure Web Chat 正确测试
相关链接
- channels-index - 所有 channel 列表
- channel-docking - DM 配对流程