LoginSignup
2
1

More than 3 years have passed since last update.

Unityメモ:UnityでMicrosoft TeamsにIncoming Webhookを使って自動投稿したい

Last updated at Posted at 2020-01-07

コードだけバーン

sample.cs
////////////////////////////////////////////////////////////////////////////////
//
// Light Wings GameProject
//
// (C) 2009 Light Wings GameProject.
//
// https://github.com/LightWings-GameProject
//
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Text;
using UniRx;
using UnityEngine;

/// <summary>
/// Microsoft Teams の Incoming Webhook
/// </summary>
public class MicrosoftTeamsIncomingWebhook
{
    class PostData
    {
        public string text; // 投稿内容
        public string username; // user名
    }

    /// <summary>
    /// Webhook に対してメッセージを送信する
    /// </summary>
    /// <param name="url">IncomingWebhookで取得したURL</param>
    /// <param name="username">ユーザ名</param>
    /// <param name="text">投稿文</param>
    /// <returns>投稿リクエストのストリーム</returns>
    public static IObservable<string> Post(string url, string username, string text)
    {
        PostData data = new PostData();
        data.username = username;
        data.text = text;
        string json_data = JsonUtility.ToJson(data);
        byte[] postBytes = Encoding.UTF8.GetBytes(json_data);

        return ObservableWWW.Post(url, postBytes);
    }
}
The MIT License (MIT)
Copyright (C) 2009 Light Wings GameProject.

不満な点

参照

UnityからSlack投稿する
Microsoft TeamsにC#で投稿
【MS Teams】Incoming Webhook経由で画像を送信する方法
Microsoft Teams に PowerShell で投稿してみる

2
1
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
2
1