跳转到内容

Microsoft Teams

Microsoft Teams provider 将你的数字员工集成到 Teams 频道和聊天中。它支持:

  • 频道消息
  • 私人聊天
  • 群聊
  • Adaptive Cards
  • 交互组件
  • 文件附件
  • Microsoft 365 tenant
  • 支持 device-code OAuth 的 public Microsoft Entra application client id
  • 可授予或同意 setup 所需 Graph scopes 的权限
  • 当你希望 setup 创建缺失的 desired channel 时,需要在所选 Team 中创建 channel 的权限

Teams setup 支持两种配置形式:

模式使用场景主要字段
Graph channel 模式你需要基于 Graph 的频道发送和订阅。这是默认 setup 模式。tenant_id, client_id, team_id, team_name, channel_id, channel_name, desired_channel_name
Bot Framework 模式你已有用于入站 Bot Framework 消息的 Azure Bot 和 Teams app manifest。ms_bot_app_id, ms_bot_app_password, bot_display_name, messaging_endpoint
  1. 配置 setup 提示

    你可以只使用默认 public client id 运行 setup,也可以提供自己的 client_id。当你希望 setup 查找或创建特定 standard channel 时,请添加 desired_channel_name

    answers.json
    {
    "setup_answers": {
    "messaging-teams": {
    "client_id": "6c115a7a-f656-49c4-975a-5e831efae833",
    "desired_channel_name": "hr onboarding"
    }
    }
    }
  2. 启动 Teams setup

    Terminal window
    gtc setup --answers answers.json ./my-bundle
  3. 完成 device-code OAuth

    setup 会启动 Microsoft device-code flow。复制代码,打开 verification URL,使用可访问目标 Team 的 Microsoft 365 account 登录,并批准请求的 Graph scopes。

    返回 terminal,并在 setup 要求验证 Microsoft Teams setup 时继续。随后 Greentic 会轮询 Microsoft Graph,将 delegated tokens 存为 secrets,并运行登录后的 discovery。

  4. 选择或验证 Team 和 channel

    setup 调用 Microsoft Graph 列出已登录 user 加入的 teams 和 channels。按提示选择 Team 和 channel,或让 desired_channel_name 引导 create-if-missing flow。

    setup 会保存 identifiers 和 labels:

    • team_idteam_name
    • channel_idchannel_name

    IDs 供 runtime sends 和 subscription setup 使用。display names 供 operators 和 setup UIs 使用。

  5. 在 Teams 中检查 channel

    打开 Microsoft Teams,进入所选 Team 和 channel。如果 setup 创建了 desired_channel_name,请确认 channel 存在且已登录 account 有权访问。

    如果所选 Team 尚无该 channel,setup 可以创建 standard channel,然后保存生成的 channel_idchannel_name。ID 仍是 runtime sends 和 subscriptions 的权威值。

  6. 启动或重启 runtime

    Terminal window
    gtc start ./my-bundle

    Teams pack 会声明所需 subscription metadata,包括 Graph resource template、component config fields、notification URL template 和 lifecycle notification URL template。hosts 应使用这些 metadata,而不是硬编码 Teams resource paths。

  7. 测试目标 channel

    在所选 Teams channel 中发送消息,或触发发送到 Teams 的 flow。如果消息未出现,请重新运行 setup,并检查保存的 team_idchannel_id 仍与在 Teams 中打开的 channel 匹配。

选项必需描述
client_idGraph setup 需要用于 device-code OAuth 的 public Microsoft application client id
tenant_id已生成从 Microsoft Graph 发现的 tenant id
team_id已生成或已选择用于 channel sends 和 subscriptions 的 Teams team id
team_name已生成或已选择所选 Team 的 display name
channel_id已生成或已选择用于 sends 和 subscriptions 的 channel id
channel_name已生成或已选择所选 channel 的 display name
desired_channel_name默认/搜索提示;支持创建时也作为 channel creation name
chat_id适用时用于 chat subscriptions 的 chat id
ms_bot_app_idBot Framework 模式Microsoft Bot Framework app id
ms_bot_app_passwordBot Framework 模式Bot Framework app password
bot_display_nameBot Framework 模式Teams app manifest workflows 中使用的 display name
messaging_endpointBot Framework 模式public Bot Framework messaging endpoint
- id: reply
type: reply
config:
message: "Hello! How can I help you today?"

Teams 支持部分 Markdown:

- id: formatted
type: reply
config:
message: |
**Bold** *Italic*
- Bullet 1
- Bullet 2
[Link](https://example.com)

Teams 通过 Bot Framework attachments 原生支持 Adaptive Card。请使用目标 Teams 客户端和操作模型支持的版本;Universal Actions 等 Adaptive Cards 1.4 功能仅适用于受支持的机器人场景。

- id: send_card
type: adaptive-card
config:
card:
type: AdaptiveCard
version: "1.4"
body:
- type: TextBlock
text: "Welcome!"
size: Large
weight: Bolder
- type: TextBlock
text: "How can I assist you today?"
- type: ActionSet
actions:
- type: Action.Submit
title: "Get Help"
data:
action: "help"
- type: Action.Submit
title: "Create Ticket"
data:
action: "ticket"
- id: hero_card
type: reply
config:
hero_card:
title: "Support Bot"
subtitle: "Your AI Assistant"
text: "I can help with technical issues, billing questions, and more."
images:
- url: "https://example.com/bot-image.png"
buttons:
- type: messageBack
title: "Get Started"
text: "get started"
displayText: "Getting started..."
- id: suggestions
type: reply
config:
message: "What would you like to do?"
suggested_actions:
- title: "Check Status"
value: "status"
- title: "Create Ticket"
value: "ticket"
- title: "Contact Human"
value: "human"
- id: send_file
type: reply
config:
message: "Here's your report"
attachments:
- contentType: "application/pdf"
contentUrl: "https://example.com/report.pdf"
name: "report.pdf"
flows/on_card_action.ygtc
name: handle_card_action
version: "1.0"
nodes:
- id: route_action
type: branch
config:
conditions:
- expression: "data.action == 'help'"
to: show_help
- expression: "data.action == 'ticket'"
to: create_ticket
default: unknown_action
- id: show_help
type: reply
config:
message: "Here's how I can help..."
triggers:
- type: invoke
name: "adaptiveCard/action"
target: route_action
greentic.demo.yaml
tenants:
demo:
teams:
support:
channels:
teams:
provider: messaging-teams
config:
team_id: "19:xxx@thread.tacv2"
channel_id: "19:yyy@thread.tacv2"

对于 1:1 私人聊天,不需要额外的频道配置。谁给 bot 发消息,bot 就回复谁。

无需用户先发起也可以发送消息:

- id: proactive
type: reply
config:
message: "Reminder: Your ticket #123 needs attention"
conversation_reference:
conversation_id: "{{stored_conversation_id}}"
service_url: "{{stored_service_url}}"
  1. 在 Azure Bot Service 中检查 endpoint 配置
  2. 确认 SSL 证书有效
  3. 检查 app 凭证是否正确
  4. 在 Azure 中查看 activity logs
  • 确认 App ID 和 Password
  • 检查单租户 app 的 tenant ID
  • 确保 bot 已在 Teams channel 中启用
  • 使用 Adaptive Cards Designer 校验 card JSON
  • 检查 Teams 是否支持该 card 版本
  • 确认所有必填字段都已提供
  • Teams 可能会批量处理消息;这是正常现象
  • 检查你的服务器性能
  • 确认没有触发速率限制

Greentic 会自动校验:

  • JWT 签名
  • Issuer 和 audience claims
  • Token 过期时间