Microsoft Graph API:Teams 应用程序 - "List members of a channel" 使用 "team id" 时出现问题

Microsoft Graph API: Teams App - Problem with "List members of a channel" using "team id"

我有一个带机器人的 Teams 应用程序,我正在尝试使用 Microsoft Graph API 检索频道对话的所有成员。

根据 Microsoft 文档 here,GET URL 是...

GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/members

当我在频道中发送机器人提及时,它提供了一个事件上下文字典,其中包含如下所示的“channelData”参数(用“X”略微编辑):

  channelData: {
    teamsChannelId: '19:9b9d91fb85ec4146972XXXXXXXXXXXXX.tacv2',
    teamsTeamId: '19:B9zDXPWNaGn03wB8iifYw6XXXXXXXXXXXXXX@thread.tacv2',
    channel: { id: '19:9b9d91fb85ec414XXXXXXXXXXXXXXXXa@thread.tacv2' },
    team: {
      id: '19:B9zDXPWNaGn03wB8iifYw6XXXXXXXXXXXXXX@thread.tacv2'
    },
    tenant: { id: 'b06932a5-6eed-4e9a-XXXX-XXXXXXXXX' }

但是,当我使用 teams-id = team{id} 或 tenant{id} 和 channel-id = channel{id} 调用 GET 端点时,它 returns 如下:

{
    "error": {
        "code": "NotFound",
        "message": "No Team found with Group id: b06932a5-6eed-4e9a-XXXX-XXXXXXXXX",
        "innerError": {
            "message": "No Team found with Group id: b06932a5-6eed-4e9a-XXXX-XXXXXXXXX",
            "code": "ItemNotFound",
            "innerError": {},
            "date": "2022-05-30T21:13:42",
            "request-id": "d8e2dfc5-0410-422b-b79d-96b73f38196b",
            "client-request-id": "d8e2dfc5-0410-422b-b79d-96b73f38196b"
        }
    }
}

我认为 API 真正想要的是 team-id = "groupID",因为当我进入 Teams 桌面应用程序并“获取 link 频道”时,它会给我以下信息。 ..

https://teams.microsoft.com/l/channel/19%3a3ca3a04e49c447XXXXXXXXXXXXXXXXXXthread.tacv2/Test%2520Channel%25201?groupId=8325270c-856a-4271-XXXXXXXXXXXXXX&tenantId=b06932a5-6eed-4e9a-XXXX-XXXXXXXX

...然后如果我在同一个 GET 调用中使用“groupId”,它会给出预期的响应,其中列出了对话的所有成员。

现在,这完全没问题,除了...我无法在 bot 消息转向上下文中的任何地方调整“groupId”...即使在“onMembersAdded”上" 首次添加机器人时发生的事件。

我已经阅读了我能找到的每篇文章/论坛列表,但到目前为止我完全被难住了......希望我遗漏了一些简单的东西,有人可以指出!

好的,终于弄明白了...link here 展示了如何为机器人获取额外的上下文。

您必须调用 TeamsInfo.getTeamDetails(turnContext) 来检索 aadGroupID:

export class MyBot extends TeamsActivityHandler {
    constructor() {
        super();

        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
        this.onMessage(async (turnContext, next) => {
            const teamDetails = await TeamsInfo.getTeamDetails(turnContext);
            if (teamDetails) {
                await turnContext.sendActivity(`The group ID is: ${teamDetails.aadGroupId}`);
            } else {
                await turnContext.sendActivity('This message did not come from a channel in a team.');
            }

            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });
    }
}