我有一个 MS 团队机器人。现在,我需要向用户介绍这一点。因此,机器人应该能够向在 Microsoft Teams 中介绍自己的特定用户集发送消息。我有数据库中的人员列表。现在,是否可以向团队中的所有人发送消息。如果是,如何?
问问题
654 次
1 回答
1
我没有尝试过,但大概管理员可以为用户安装该应用程序。此时机器人应该收到 aconversationUpdate
并且机器人应该能够在事件处理程序中向用户发送消息。
正如评论中提到的@Abhijit-MSFT,这是使用 Graph 为用户添加应用程序的示例:https ://github.com/microsoftgraph/contoso-airlines-teams-sample/blob/283523d45f5ce416111dfc34b8e49728b5012739/project/Models/ GraphService.cs#L176
public async Task InstallAppToAllUsers()
{
string appid = "f46ad259-0fe5-4f12-872d-c737b174bcb4"; // Adobe
var graph = GetAuthenticatedClient();
var users = await graph.Users.Request().Select("id,displayName").GetAsync();
foreach (User user in users)
{
if (user.DisplayName.StartsWith("Megan"))
{
// Check if the app is already installed for that user.
// Use $expand to populate the teamsAppDefinition property,
// and $filter to search for the one app we care about
TeamsAppInstallation[] installs = await HttpGetList<TeamsAppInstallation>(
$"/users/{user.Id}/teamwork/installedApps?$expand=teamsAppDefinition&$filter=teamsAppDefinition/teamsAppId eq '{appid}'",
endpoint: graphBetaEndpoint);
if (installs.Length == 0)
{
// install app
await HttpPost($"/users/{user.Id}/teamwork/installedApps",
new TeamsAppInstallation()
{
AdditionalData = new Dictionary<string, object>() { ["teamsApp@odata.bind"] = $"{graphBetaEndpoint}/appCatalogs/teamsApps/{appid}" }
},
endpoint: graphBetaEndpoint);
// Bot will get a notification about the new user and the chat thread ID for that user
}
// If you've forgotten the chat thread ID for that user, you can find it again:
var chats = await HttpGetList<Chat>($"/users/{user.Id}/chats?$filter=installedApps/any(a:a/teamsApp/id eq '{appid}')", endpoint: graphBetaEndpoint);
string threadId = chats[0].Id;
// Wait a little before installing the next app to avoid throttling
Thread.Sleep(1000);
}
}
}
于 2019-12-12T17:14:26.480 回答