[英]Is it possible to send messages to microsoft team from external channel
I have a MS teams bot .我有一个 MS 团队机器人。 Now, I need to introduce this to users.
现在,我需要向用户介绍这一点。 So, the bot should be able to send messages to set of specific users introducing itself in Microsoft Teams .
因此,机器人应该能够向在 Microsoft Teams 中介绍自己的一组特定用户发送消息。 I have list of people in database.
我有数据库中的人员名单。 Now, is it possible to send messages to all of them in teams .
现在,是否可以向团队中的所有人发送消息。 If yes, how?
如果是,如何?
I haven't tried this, but presumably an Admin could install the app for the users.我还没有尝试过,但大概管理员可以为用户安装该应用程序。 At which point the bot should receive a
conversationUpdate
and the bot should be able to message the user in the event handler.此时,机器人应该收到一个
conversationUpdate
,并且机器人应该能够在事件处理程序中向用户发送消息。
As @Abhijit-MSFT mentioned in comments, here is an example of using Graph to add an App for a user: https://github.com/microsoftgraph/contoso-airlines-teams-sample/blob/283523d45f5ce416111dfc34b8e49728b5012739/project/Models/GraphService.cs#L176正如@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);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.