在 Ms Teams 的 Bot Framework 中识别 "Owner"(TeamsChannelAccount UserRole 属性 只说 "user")

Identifying "Owner" in Bot Framework for Ms Teams (TeamsChannelAccount UserRole property only ever says "user")

我已经使用 Bot Framework 和 .Net 编写了一个 Ms Teams Bot,我想确定安装了 Bot 的团队的 所有者(例如发送他们是一张具有更多特权功能的自适应卡片,而不是让整个团队都看到它)。

bot 框架的 V4.9 release note 声明:

The TeamsChannelAccount object has been updated to include userRole (one of owner, member, or guest) and tenantId (for the user's tenantId)

但这似乎是不正确的。当使用 TeamsInfo.GetMemberAsync 或 TeamsInfo.GetPagedMembersAsync 检索成员信息(所有 return 上面提到的 TeamsChannelAccount 对象)时,UserRole 属性 只显示“用户”作为值 - 从不“所有者”或其他方式。

如何识别团队的所有者?谢谢。

您可以尝试使用 MSGraph APIs 来识别组的所有者。假设您拥有必要的权限,您可以对适当的 Graph 端点进行 GET 调用,它会 return 向您提供所有者的 ID 和姓名等信息。然后,您可以使用该 ID 来识别 Teams 中的所有者。 MSGraph API 获取成员的调用也有一个 roles 字段,其中也可以有所有者。

如果此解决方案适合您,Teams Auth sample 是一个不错的起点。

这里还有一些可能有用的文档页面: