Skip to content

Microsoft Teams (插件)

"进入此地者,放弃一切希望。"

更新日期:2026-01-21

状态:支持文本 + DM附件;频道/群组文件发送需要 sharePointSiteId + Graph权限(参见在群组聊天中发送文件)。投票通过 Adaptive Cards 发送。

插件要求

Microsoft Teams 作为插件提供,不包含在核心安装中。

重大变更(2026.1.15): MS Teams 已从核心中移出。如果您使用它,必须安装插件。

解释:保持核心安装更轻量,让 MS Teams 依赖项可以独立更新。

通过 CLI 安装(npm 注册表):

bash
openclaw plugins install @openclaw/msteams

本地检出(从 git 仓库运行时):

bash
openclaw plugins install ./extensions/msteams

如果在配置/引导期间选择 Teams 并检测到 git 检出, openclaw 将自动提供本地安装路径。

详情:插件

快速设置(初学者)

  1. 安装 Microsoft Teams 插件。
  2. 创建 Azure Bot(应用 ID + 客户端密钥 + 租户 ID)。
  3. 使用这些凭据配置 openclaw。
  4. 通过公共 URL 或隧道暴露 /api/messages(默认端口 3978)。
  5. 安装 Teams 应用包并启动网关。

最小配置:

json5
{
  channels: {
    msteams: {
      enabled: true,
      appId: "<APP_ID>",
      appPassword: "<APP_PASSWORD>",
      tenantId: "<TENANT_ID>",
      webhook: { port: 3978, path: "/api/messages" }
    }
  }
}

注意:群组聊天默认被阻止(channels.msteams.groupPolicy: "allowlist")。要允许群组回复,设置 channels.msteams.groupAllowFrom(或使用 groupPolicy: "open" 允许任何成员,提及门控)。

Goals

  • Talk to openclaw via Teams DMs, group chats, or channels.
  • Keep routing deterministic: replies always go back to the channel they arrived on.
  • Default to safe channel behavior (mentions required unless configured otherwise).

Config writes

By default, Microsoft Teams is allowed to write config updates triggered by /config set|unset (requires commands.config: true).

Disable with:

json5
{
  channels: { msteams: { configWrites: false } }
}

Access control (DMs + groups)

DM access

  • Default: channels.msteams.dmPolicy = "pairing". Unknown senders are ignored until approved.
  • channels.msteams.allowFrom accepts AAD object IDs, UPNs, or display names. The wizard resolves names to IDs via Microsoft Graph when credentials allow.

Group access

  • Default: channels.msteams.groupPolicy = "allowlist" (blocked unless you add groupAllowFrom). Use channels.defaults.groupPolicy to override the default when unset.
  • channels.msteams.groupAllowFrom controls which senders can trigger in group chats/channels (falls back to channels.msteams.allowFrom).
  • Set groupPolicy: "open" to allow any member (still mention‑gated by default).
  • To allow no channels, set channels.msteams.groupPolicy: "disabled".

Example:

json5
{
  channels: {
    msteams: {
      groupPolicy: "allowlist",
      groupAllowFrom: ["user@org.com"]
    }
  }
}

Teams + channel allowlist

  • Scope group/channel replies by listing teams and channels under channels.msteams.teams.
  • Keys can be team IDs or names; channel keys can be conversation IDs or names.
  • When groupPolicy="allowlist" and a teams allowlist is present, only listed teams/channels are accepted (mention‑gated).
  • The configure wizard accepts Team/Channel entries and stores them for you.
  • On startup, openclaw resolves team/channel and user allowlist names to IDs (when Graph permissions allow) and logs the mapping; unresolved entries are kept as typed.

Example:

json5
{
  channels: {
    msteams: {
      groupPolicy: "allowlist",
      teams: {
        "My Team": {
          channels: {
            "General": { requireMention: true }
          }
        }
      }
    }
  }
}

How it works

  1. Install the Microsoft Teams plugin.
  2. Create an Azure Bot (App ID + secret + tenant ID).
  3. Build a Teams app package that references the bot and includes the RSC permissions below.
  4. Upload/install the Teams app into a team (or personal scope for DMs).
  5. Configure msteams in ~/.clawdbot/openclaw.json (or env vars) and start the gateway.
  6. The gateway listens for Bot Framework webhook traffic on /api/messages by default.

Azure Bot Setup (Prerequisites)

Before configuring openclaw, you need to create an Azure Bot resource.

Step 1: Create Azure Bot

  1. Go to Create Azure Bot

  2. Fill in the Basics tab:

    FieldValue
    Bot handleYour bot name, e.g., openclaw-msteams (must be unique)
    SubscriptionSelect your Azure subscription
    Resource groupCreate new or use existing
    Pricing tierFree for dev/testing
    Type of AppSingle Tenant (recommended - see note below)
    Creation typeCreate new Microsoft App ID

Deprecation notice: Creation of new multi-tenant bots was deprecated after 2025-07-31. Use Single Tenant for new bots.

  1. Click Review + createCreate (wait ~1-2 minutes)

Step 2: Get Credentials

  1. Go to your Azure Bot resource → Configuration
  2. Copy Microsoft App ID → this is your appId
  3. Click Manage Password → go to the App Registration
  4. Under Certificates & secretsNew client secret → copy the Value → this is your appPassword
  5. Go to Overview → copy Directory (tenant) ID → this is your tenantId

Step 3: Configure Messaging Endpoint

  1. In Azure Bot → Configuration
  2. Set Messaging endpoint to your webhook URL:
    • Production: https://your-domain.com/api/messages
    • Local dev: Use a tunnel (see Local Development below)

Step 4: Enable Teams Channel

  1. In Azure Bot → Channels
  2. Click Microsoft Teams → Configure → Save
  3. Accept the Terms of Service

Local Development (Tunneling)

Teams can't reach localhost. Use a tunnel for local development:

Option A: ngrok

bash
ngrok http 3978
# Copy the https URL, e.g., https://abc123.ngrok.io
# Set messaging endpoint to: https://abc123.ngrok.io/api/messages

Option B: Tailscale Funnel

bash
tailscale funnel 3978
# Use your Tailscale funnel URL as the messaging endpoint

Teams Developer Portal (Alternative)

Instead of manually creating a manifest ZIP, you can use the Teams Developer Portal:

  1. Click + New app
  2. Fill in basic info (name, description, developer info)
  3. Go to App featuresBot
  4. 选择 手动输入机器人 ID 并粘贴您的 Azure 机器人应用 ID
  5. 检查范围:个人团队群聊
  6. 点击 分发下载应用包
  7. 在 Teams 中:应用管理您的应用上传自定义应用 → 选择 ZIP 文件

这通常比手动编辑 JSON 清单更容易。

测试机器人

选项 A:Azure Web Chat(先验证 webhook)

  1. 在 Azure 门户 → 您的 Azure 机器人资源 → 在 Web Chat 中测试
  2. 发送消息 - 您应该会看到响应
  3. 这确认您的 webhook 端点在 Teams 设置之前正常工作

选项 B:Teams(应用安装后)

  1. 安装 Teams 应用(侧加载或组织目录)
  2. 在 Teams 中找到机器人并发送私信
  3. 检查网关日志以查看传入活动

设置(最小文本模式)

  1. 安装 Microsoft Teams 插件

    • 从 npm:openclaw plugins install @openclaw/msteams
    • 从本地检出:openclaw plugins install ./extensions/msteams
  2. 机器人注册

    • 创建 Azure 机器人(见上文)并记录:
      • 应用 ID
      • 客户端密钥(应用密码)
      • 租户 ID(单租户)
  3. Teams 应用清单

    • 包含一个 bot 条目,其中 botId = <应用 ID>
    • 范围:personalteamgroupChat
    • supportsFiles: true(个人范围文件处理必需)。
    • 添加 RSC 权限(见下文)。
    • 创建图标:outline.png(32x32)和 color.png(192x192)。
    • 将所有三个文件一起压缩:manifest.jsonoutline.pngcolor.png
  4. 配置 openclaw

    json
    {
      "msteams": {
        "enabled": true,
        "appId": "<APP_ID>",
        "appPassword": "<APP_PASSWORD>",
        "tenantId": "<TENANT_ID>",
        "webhook": { "port": 3978, "path": "/api/messages" }
      }
    }

    您也可以使用环境变量代替配置键:

    • MSTEAMS_APP_ID
    • MSTEAMS_APP_PASSWORD
    • MSTEAMS_TENANT_ID
  5. 机器人端点

    • 将 Azure 机器人消息端点设置为:
      • https://<主机>:3978/api/messages(或您选择的路径/端口)。
  6. 运行网关

    • 当插件已安装且 msteams 配置存在凭据时,Teams 通道会自动启动。

历史上下文

  • channels.msteams.historyLimit 控制有多少最近的频道/群组消息被包装到提示中。
  • 回退到 messages.groupChat.historyLimit。设置为 0 以禁用(默认 50)。
  • 私信历史可以通过 channels.msteams.dmHistoryLimit(用户轮次)限制。每个用户的覆盖:channels.msteams.dms["<用户ID>"].historyLimit

当前 Teams RSC 权限(清单)

这些是我们 Teams 应用清单中的 现有资源特定权限。它们仅适用于安装应用的团队/聊天内部。

对于频道(团队范围):

  • ChannelMessage.Read.Group(应用程序)- 无需 @提及即可接收所有频道消息
  • ChannelMessage.Send.Group(应用程序)
  • Member.Read.Group(应用程序)
  • Owner.Read.Group(应用程序)
  • ChannelSettings.Read.Group(应用程序)
  • TeamMember.Read.Group(应用程序)
  • TeamSettings.Read.Group(应用程序)

对于群聊:

  • ChatMessage.Read.Chat(应用程序)- 无需 @提及即可接收所有群聊消息

Teams 清单示例(已编辑)

最小、有效的示例,包含必需字段。替换 ID 和 URL。

json
{
  "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.23/MicrosoftTeams.schema.json",
  "manifestVersion": "1.23",
  "version": "1.0.0",
  "id": "00000000-0000-0000-0000-000000000000",
  "name": { "short": "openclaw" },
  "developer": {
    "name": "您的组织",
    "websiteUrl": "https://example.com",
    "privacyUrl": "https://example.com/privacy",
    "termsOfUseUrl": "https://example.com/terms"
  },
  "description": { "short": "Teams 中的 openclaw", "full": "Teams 中的 openclaw" },
  "icons": { "outline": "outline.png", "color": "color.png" },
  "accentColor": "#5B6DEF",
  "bots": [
    {
      "botId": "11111111-1111-1111-1111-111111111111",
      "scopes": ["personal", "team", "groupChat"],
      "isNotificationOnly": false,
      "supportsCalling": false,
      "supportsVideo": false,
      "supportsFiles": true
    }
  ],
  "webApplicationInfo": {
    "id": "11111111-1111-1111-1111-111111111111"
  },
  "authorization": {
    "permissions": {
      "resourceSpecific": [
        { "name": "ChannelMessage.Read.Group", "type": "Application" },
        { "name": "ChannelMessage.Send.Group", "type": "Application" },
        { "name": "Member.Read.Group", "type": "Application" },
        { "name": "Owner.Read.Group", "type": "Application" },
        { "name": "ChannelSettings.Read.Group", "type": "Application" },
        { "name": "TeamMember.Read.Group", "type": "Application" },
        { "name": "TeamSettings.Read.Group", "type": "Application" },
        { "name": "ChatMessage.Read.Chat", "type": "Application" }
      ]
    }
  }
}

清单注意事项(必需字段)

  • bots[].botId 必须 匹配 Azure 机器人应用 ID。
  • webApplicationInfo.id 必须 匹配 Azure 机器人应用 ID。
  • bots[].scopes 必须包含您计划使用的界面(personalteamgroupChat)。
  • bots[].supportsFiles: true 是个人范围文件处理所必需的。
  • authorization.permissions.resourceSpecific 必须包含频道读取/发送权限,如果您想要频道流量。

更新现有应用

要更新已安装的 Teams 应用(例如,添加 RSC 权限):

  1. 使用新设置更新您的 manifest.json
  2. 递增 version 字段(例如,1.0.01.1.0
  3. 重新压缩 清单和图标(manifest.jsonoutline.pngcolor.png
  4. 上传新的 zip 文件:
    • 选项 A(Teams 管理中心): Teams 管理中心 → Teams 应用 → 管理应用 → 找到您的应用 → 上传新版本
    • 选项 B(侧加载): 在 Teams 中 → 应用 → 管理您的应用 → 上传自定义应用
  5. 对于团队频道: 在每个团队中重新安装应用以使新权限生效
  6. 完全退出并重新启动 Teams(不仅仅是关闭窗口)以清除缓存的应用程序元数据

功能:仅 RSC 与 Graph

使用 仅 Teams RSC(应用已安装,无 Graph API 权限)

有效:

  • 读取频道消息 文本 内容。
  • 发送频道消息 文本 内容。
  • 接收 个人(私信) 文件附件。

无效:

  • 频道/群组 图像或文件内容(有效负载仅包含 HTML 存根)。
  • 下载存储在 SharePoint/OneDrive 中的附件。
  • 读取消息历史记录(超出实时 webhook 事件)。

使用 Teams RSC + Microsoft Graph 应用程序权限

添加:

  • 下载托管内容(粘贴到消息中的图像)。
  • 下载存储在 SharePoint/OneDrive 中的文件附件。
  • 通过 Graph 读取频道/聊天消息历史记录。

RSC 与 Graph API

功能RSC 权限Graph API
实时消息是(通过 webhook)否(仅轮询)
历史消息是(可以查询历史记录)
设置复杂性仅应用清单需要管理员同意 + 令牌流程
离线工作否(必须运行)是(随时查询)

底线: RSC 用于实时监听;Graph API 用于历史访问。要捕获离线时错过的消息,您需要具有 ChannelMessage.Read.All 的 Graph API(需要管理员同意)。

Graph 启用的媒体 + 历史记录(频道必需)

如果您需要 频道 中的图像/文件或想要获取 消息历史记录,您必须启用 Microsoft Graph 权限并授予管理员同意。

  1. 在 Entra ID(Azure AD)应用注册中,添加 Microsoft Graph 应用程序权限
    • ChannelMessage.Read.All(频道附件 + 历史记录)
    • Chat.Read.AllChatMessage.Read.All(群聊)
  2. 授予管理员同意 给租户。
  3. 提升 Teams 应用 清单版本,重新上传,并在 Teams 中 重新安装应用
  4. 完全退出并重新启动 Teams 以清除缓存的应用程序元数据。

已知限制

Webhook 超时

Teams 通过 HTTP webhook 传递消息。如果处理时间过长(例如,慢速 LLM 响应),您可能会看到:

  • 网关超时
  • Teams 重试消息(导致重复)
  • 丢弃的回复

openclaw 通过快速返回并主动发送回复来处理此问题,但非常慢的响应仍可能导致问题。

格式化

Teams markdown 比 Slack 或 Discord 更有限:

  • 基本格式化有效:粗体斜体代码、链接
  • 复杂 markdown(表格、嵌套列表)可能无法正确渲染
  • 支持 Adaptive Cards 用于投票和任意卡片发送(见下文)

配置

关键设置(有关共享通道模式,请参见 /gateway/configuration):

  • channels.msteams.enabled:启用/禁用通道。
  • channels.msteams.appIdchannels.msteams.appPasswordchannels.msteams.tenantId:机器人凭据。
  • channels.msteams.webhook.port(默认 3978
  • channels.msteams.webhook.path(默认 /api/messages
  • channels.msteams.dmPolicypairing | allowlist | open | disabled(默认:pairing)
  • channels.msteams.allowFrom:私信允许列表(AAD 对象 ID、UPN 或显示名称)。当 Graph 访问可用时,向导在设置期间将名称解析为 ID。
  • channels.msteams.textChunkLimit:出站文本块大小。
  • channels.msteams.chunkModelength(默认)或 newline 以在长度分块之前按空行(段落边界)拆分。
  • channels.msteams.mediaAllowHosts:入站附件主机允许列表(默认为 Microsoft/Teams 域)。
  • channels.msteams.requireMention:在频道/群组中需要 @提及(默认 true)。
  • channels.msteams.replyStylethread | top-level(见回复样式)。
  • channels.msteams.teams.<teamId>.replyStyle:每个团队的覆盖。
  • channels.msteams.teams.<teamId>.requireMention:每个团队的覆盖。
  • channels.msteams.teams.<teamId>.tools:当缺少通道覆盖时使用的默认每个团队工具策略覆盖(allow/deny/alsoAllow)。
  • channels.msteams.teams.<teamId>.toolsBySender:默认每个团队每个发送者工具策略覆盖(支持 "*" 通配符)。
  • channels.msteams.teams.<teamId>.channels.<conversationId>.replyStyle:每个通道的覆盖。
  • channels.msteams.teams.<teamId>.channels.<conversationId>.requireMention:每个通道的覆盖。
  • channels.msteams.teams.<teamId>.channels.<conversationId>.tools:每个通道工具策略覆盖(allow/deny/alsoAllow)。
  • channels.msteams.teams.<teamId>.channels.<conversationId>.toolsBySender:每个通道每个发送者工具策略覆盖(支持 "*" 通配符)。
  • channels.msteams.sharePointSiteId:用于群聊/频道中文件上传的 SharePoint 站点 ID(见在群聊中发送文件)。

路由和会话

  • 会话键遵循标准代理格式(见 /concepts/session):
    • 直接消息共享主会话(agent:<agentId>:<mainKey>)。
    • 频道/群组消息使用对话 ID:
      • agent:<agentId>:msteams:channel:<conversationId>
      • agent:<agentId>:msteams:group:<conversationId>

回复样式:Threads 与 Posts

Teams 最近在同一底层数据模型上引入了两种频道 UI 样式:

样式描述推荐的 replyStyle
Posts(经典)消息显示为卡片,下面有线程回复thread(默认)
Threads(类似 Slack)消息线性流动,更像 Slacktop-level

问题: Teams API 不公开频道使用哪种 UI 样式。如果您使用错误的 replyStyle

  • 在 Threads 样式频道中使用 thread → 回复嵌套显示,显得尴尬
  • 在 Posts 样式频道中使用 top-level → 回复显示为单独的顶级帖子,而不是在线程内

解决方案: 根据频道的设置方式配置每个频道的 replyStyle

json
{
  "msteams": {
    "replyStyle": "thread",
    "teams": {
      "19:abc...@thread.tacv2": {
        "channels": {
          "19:xyz...@thread.tacv2": {
            "replyStyle": "top-level"
          }
        }
      }
    }
  }
}

附件和图像

当前限制:

  • 私信: 图像和文件附件通过 Teams 机器人文件 API 工作。
  • 频道/群组: 附件存储在 M365 存储(SharePoint/OneDrive)中。webhook 有效负载仅包含 HTML 存根,而不是实际的文件字节。需要 Graph API 权限 才能下载频道附件。

没有 Graph 权限,带有图像的频道消息将仅作为纯文本接收(图像内容对机器人不可访问)。 默认情况下,openclaw 仅从 Microsoft/Teams 主机名下载媒体。使用 channels.msteams.mediaAllowHosts 覆盖(使用 ["*"] 允许任何主机)。

在群聊中发送文件

机器人可以在私信中使用 FileConsentCard 流程(内置)发送文件。然而,在群聊/频道中发送文件需要额外的设置:

上下文文件发送方式所需设置
私信FileConsentCard → 用户接受 → 机器人上传开箱即用
群聊/频道上传到 SharePoint → 共享链接需要 sharePointSiteId + Graph 权限
图像(任何上下文)Base64 编码内联开箱即用

为什么群聊需要 SharePoint

机器人没有个人 OneDrive 驱动器(/me/drive Graph API 端点不适用于应用程序身份)。要在群聊/频道中发送文件,机器人上传到 SharePoint 站点 并创建共享链接。

设置

  1. 在 Entra ID(Azure AD)→ 应用注册中添加 Graph API 权限:

    • Sites.ReadWrite.All(应用程序)- 上传文件到 SharePoint
    • Chat.Read.All(应用程序)- 可选,启用每个用户的共享链接
  2. 授予管理员同意 给租户。

  3. 获取您的 SharePoint 站点 ID:

    bash
    # 通过 Graph Explorer 或带有有效令牌的 curl:
    curl -H "Authorization: Bearer $TOKEN" \
      "https://graph.microsoft.com/v1.0/sites/{hostname}:/{site-path}"
    
    # 示例:对于位于 "contoso.sharepoint.com/sites/BotFiles" 的站点
    curl -H "Authorization: Bearer $TOKEN" \
      "https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/BotFiles"
    
    # 响应包括:"id": "contoso.sharepoint.com,guid1,guid2"
  4. 配置 openclaw:

    json5
    {
      channels: {
        msteams: {
          // ... 其他配置 ...
          sharePointSiteId: "contoso.sharepoint.com,guid1,guid2"
        }
      }
    }

共享行为

权限共享行为
Sites.ReadWrite.All组织范围共享链接(组织中的任何人都可以访问)
Sites.ReadWrite.All + Chat.Read.All每个用户的共享链接(仅聊天成员可以访问)

每个用户的共享更安全,因为只有聊天参与者可以访问文件。如果缺少 Chat.Read.All 权限,机器人将回退到组织范围共享。

回退行为

场景结果
群聊 + 文件 + 配置了 sharePointSiteId上传到 SharePoint,发送共享链接
群聊 + 文件 + 没有 sharePointSiteId尝试 OneDrive 上传(可能失败),仅发送文本
个人聊天 + 文件FileConsentCard 流程(无需 SharePoint)
任何上下文 + 图像Base64 编码内联(无需 SharePoint)

文件存储位置

上传的文件存储在配置的 SharePoint 站点默认文档库中的 /openclawShared/ 文件夹中。

投票(Adaptive Cards)

openclaw 将 Teams 投票作为 Adaptive Cards 发送(没有本机 Teams 投票 API)。

  • CLI:openclaw message poll --channel msteams --target conversation:<id> ...
  • 投票记录在网关的 ~/.clawdbot/msteams-polls.json 中。
  • 网关必须保持在线以记录投票。
  • 投票尚不自动发布结果摘要(如果需要,请检查存储文件)。

Adaptive Cards(任意)

使用 message 工具或 CLI 向 Teams 用户或对话发送任何 Adaptive Card JSON。

card 参数接受 Adaptive Card JSON 对象。当提供 card 时,消息文本是可选的。

代理工具:

json
{
  "action": "send",
  "channel": "msteams",
  "target": "user:<id>",
  "card": {
    "type": "AdaptiveCard",
    "version": "1.5",
    "body": [{"type": "TextBlock", "text": "Hello!"}]
  }
}

CLI:

bash
openclaw message send --channel msteams \
  --target "conversation:19:abc...@thread.tacv2" \
  --card '{"type":"AdaptiveCard","version":"1.5","body":[{"type":"TextBlock","text":"Hello!"}]}'

有关卡片模式和示例,请参见 Adaptive Cards 文档。有关目标格式详细信息,请参见下面的目标格式

目标格式

MSTeams 目标使用前缀来区分用户和对话:

目标类型格式示例
用户(按 ID)user:<aad-object-id>user:40a1a0ed-4ff2-4164-a219-55518990c197
用户(按名称)user:<display-name>user:John Smith(需要 Graph API)
群组/频道conversation:<conversation-id>conversation:19:abc123...@thread.tacv2
群组/频道(原始)<conversation-id>19:abc123...@thread.tacv2(如果包含 @thread

CLI 示例:

bash
# 按 ID 发送给用户
openclaw message send --channel msteams --target "user:40a1a0ed-..." --message "Hello"

# 按显示名称发送给用户(触发 Graph API 查找)
openclaw message send --channel msteams --target "user:John Smith" --message "Hello"

# 发送到群聊或频道
openclaw message send --channel msteams --target "conversation:19:abc...@thread.tacv2" --message "Hello"

# 发送 Adaptive Card 到对话
openclaw message send --channel msteams --target "conversation:19:abc...@thread.tacv2" \
  --card '{"type":"AdaptiveCard","version":"1.5","body":[{"type":"TextBlock","text":"Hello"}]}'

代理工具示例:

json
{
  "action": "send",
  "channel": "msteams",
  "target": "user:John Smith",
  "message": "Hello!"
}
json
{
  "action": "send",
  "channel": "msteams",
  "target": "conversation:19:abc...@thread.tacv2",
  "card": {"type": "AdaptiveCard", "version": "1.5", "body": [{"type": "TextBlock", "text": "Hello"}]}
}

注意:没有 user: 前缀时,名称默认为群组/团队解析。当按显示名称定位人员时,始终使用 user:

主动消息

  • 主动消息仅在用户交互后可能,因为我们在那时存储对话引用。
  • 有关 dmPolicy 和允许列表门控,请参见 /gateway/configuration

团队和频道 ID(常见陷阱)

Teams URL 中的 groupId 查询参数 不是 用于配置的团队 ID。从 URL 路径中提取 ID:

团队 URL:

https://teams.microsoft.com/l/team/19%3ABk4j...%40thread.tacv2/conversations?groupId=...
                                    └────────────────────────────┘
                                    团队 ID(URL 解码此部分)

频道 URL:

https://teams.microsoft.com/l/channel/19%3A15bc...%40thread.tacv2/ChannelName?groupId=...
                                      └─────────────────────────┘
                                      频道 ID(URL 解码此部分)

用于配置:

  • 团队 ID = /team/ 之后的路径段(URL 解码,例如 19:Bk4j...@thread.tacv2
  • 频道 ID = /channel/ 之后的路径段(URL 解码)
  • 忽略 groupId 查询参数

私有频道

机器人在私有频道中的支持有限:

功能标准频道私有频道
机器人安装有限
实时消息(webhook)可能不工作
RSC 权限可能行为不同
@提及如果机器人可访问
Graph API 历史记录是(具有权限)

如果私有频道不工作的解决方法:

  1. 使用标准频道进行机器人交互
  2. 使用私信 - 用户始终可以直接向机器人发送消息
  3. 使用 Graph API 进行历史访问(需要 ChannelMessage.Read.All

故障排除

常见问题

  • 频道中图像不显示: Graph 权限或管理员同意缺失。重新安装 Teams 应用并完全退出/重新打开 Teams。
  • 频道中没有响应: 默认需要提及;设置 channels.msteams.requireMention=false 或按团队/频道配置。
  • 版本不匹配(Teams 仍显示旧清单): 移除 + 重新添加应用并完全退出 Teams 以刷新。
  • 来自 webhook 的 401 未授权: 在没有 Azure JWT 的情况下手动测试时预期 - 表示端点可达但身份验证失败。使用 Azure Web Chat 进行正确测试。

清单上传错误

  • "图标文件不能为空": 清单引用了 0 字节的图标文件。创建有效的 PNG 图标(32x32 用于 outline.png,192x192 用于 color.png)。
  • "webApplicationInfo.Id 已在使用中": 应用仍安装在另一个团队/聊天中。首先找到并卸载它,或等待 5-10 分钟以传播。
  • 上传时出现"出现问题": 改为通过 https://admin.teams.microsoft.com 上传,打开浏览器开发者工具(F12)→ 网络选项卡,并检查响应正文以获取实际错误。
  • 侧加载失败: 尝试"将应用上传到您组织的应用目录"而不是"上传自定义应用" - 这通常绕过侧加载限制。

RSC 权限不工作

  1. 验证 webApplicationInfo.id 完全匹配您的机器人应用 ID
  2. 重新上传应用并在团队/聊天中重新安装
  3. 检查您的组织管理员是否阻止了 RSC 权限
  4. 确认您使用正确的范围:ChannelMessage.Read.Group 用于团队,ChatMessage.Read.Chat 用于群聊

参考