根据 AAD ID 检索团队用户 ID

Retrieve Teams User ID based on AAD ID

我正在尝试开始预定的主动对话(机器人在预定时间启动对话)。 我设法根据 Graph API 获取了用户的 AAD ID,但它与 Teams 用户 ID 不匹配。尝试了 2 个多小时来获取正确的 ID,但我不知道如何获取。我应该采取什么最佳方法?

我很好奇你是如何尝试 "match" 这些的?无论如何,我认为它们不打算以任何方式匹配(aadObjectId Guid 和“29:...”用户 ID)。因此,您应该在您这边(数据库或类似的)存储一个映射。无论如何,您都需要存储 ServiceUrl 和 ConversationId 以进行主动消息传递,因此也只需添加 userid。

看看 Microsoft Graph api 到 get the chat thread ID

When the app is installed for the user, the bot will get receive a conversationUpdate event that will contain the necessary information for it to send the proactive message. For more information, see Bot events.

If you lose the chatThreadId, you can find it again by calling:

GET /users/{user-id}/chats?$filter=installedApps/any(a:a/teamsApp/id eq '{teamsAppid}')

不过,这只针对个人范围!我的建议是确保您捕获安装后触发的 conversationUpdate 并将用户详细信息保存在数据库中。