LoginSignup
8
13

More than 3 years have passed since last update.

Microsoft TeamsにC#で投稿

Last updated at Posted at 2017-09-05

1.Incoming Webhook

以下の方法に従ってPOST先のIncoming WebhookのURIを取得します。
webhookを追加します。-Officeサポート

2.コード

※サンプルです。頻繁に通信が発生する場合はHttpClientをusingで破棄しないようにしましょう。

PostToTeams.cs
using Newtonsoft.Json;


string url = "IncomingwebhookのURI";

using (HttpClient httpClient = new HttpClient())
{
  var param = new Hashtable();
  // とりあえずTextパラメータは必須
  param["Text"] = "hogehoge message";
  var json = JsonConvert.SerializeObject(param);

  var content = new StringContent(json);
  HttpResponseMessage response = await httpClient.PostAsync(url, content);
}

3.Actionable message card reference

このサイトに従いパラメータを追加すると、
よりリッチな表示を投稿することができます。

その場合、JSONの階層を深くする必要が出てくることがあるので、投稿内容に合わせたModelを作ってJSONにシリアライズすれば良いと思います。(未検証)

8
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
13