如何使用 csharp 向 Microsoft Teams 频道发送简单消息?
How to send simple message to Microsoft Teams channel using csharp?
我找不到任何东西可以向 MS Teams 频道发送简单消息,我正在使用 Csharp,不需要回复消息。
有几种方法可以实现此目的,具体取决于您的其他更广泛的要求。例如,选项是 webhooks 或机器人,但请在
查看我的回答
您可以使用 webhook 将消息发送到 Teams 频道。您可以 post 通过在频道内设置传入的网络钩子来发送消息。请查看 Post external request in Teams with incoming webhook. But you should specify your requirement you can achieve this with the Bot. A bot is also helpful to have conversation within Teams channel. Bot supported [Personal, Team, GroupChat]
scope. Please go through the Conversation basic 了解机器人如何在不同范围内工作的更多信息。
使用 C# 向团队频道发送消息的一种方法是使用网络钩子 url。下面的代码将有助于向团队发送消息。
string webhookUrl = "<enter Teams webhook url>";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(webhookUrl);
Message body = new Message();
body.text = "Hello World";
string serializeJson = JsonConvert.SerializeObject(body);
StringContent content = new StringContent(serializeJson,Encoding.UTF8,"application/json");
_ = await client.PostAsync(client.BaseAddress, content);
声明消息class
public class Message
{
public string text { get; set; }
}
Webhook url 可以通过在所需的 Teams 频道上创建 Incoming webhook
连接来设置:
我找不到任何东西可以向 MS Teams 频道发送简单消息,我正在使用 Csharp,不需要回复消息。
有几种方法可以实现此目的,具体取决于您的其他更广泛的要求。例如,选项是 webhooks 或机器人,但请在
您可以使用 webhook 将消息发送到 Teams 频道。您可以 post 通过在频道内设置传入的网络钩子来发送消息。请查看 Post external request in Teams with incoming webhook. But you should specify your requirement you can achieve this with the Bot. A bot is also helpful to have conversation within Teams channel. Bot supported [Personal, Team, GroupChat]
scope. Please go through the Conversation basic 了解机器人如何在不同范围内工作的更多信息。
使用 C# 向团队频道发送消息的一种方法是使用网络钩子 url。下面的代码将有助于向团队发送消息。
string webhookUrl = "<enter Teams webhook url>";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(webhookUrl);
Message body = new Message();
body.text = "Hello World";
string serializeJson = JsonConvert.SerializeObject(body);
StringContent content = new StringContent(serializeJson,Encoding.UTF8,"application/json");
_ = await client.PostAsync(client.BaseAddress, content);
声明消息class
public class Message
{
public string text { get; set; }
}
Webhook url 可以通过在所需的 Teams 频道上创建 Incoming webhook
连接来设置: