コード例 #1
0
        public static IEnumerator PostMessage(
            PostMessageData data,
            Action onSuccess        = null,
            Action <string> onError = null
            )
        {
            var form = new WWWForm();

            form.AddField("token", data.token);
            form.AddField("channel", data.channel);
            form.AddField("text", data.text);
            form.AddField("parse", data.parse);
            form.AddField("link_names", data.link_names);
            form.AddField("username", data.username);
            form.AddField("icon_url", data.icon_url);
            form.AddField("icon_emoji", data.icon_emoji);

            var url = "https://slack.com/api/chat.postMessage"; //※社内ネットワークからだとproxyが邪魔してアクセスできない
            var www = new WWW(url, form);

            yield return(www);

            var error = www.error;

            Debug.Log(System.Text.Encoding.ASCII.GetString(www.bytes)); //->json取ってくる

            if (!string.IsNullOrEmpty("postMessage: " + error))
            {
                Debug.Log(error);

                if (onError != null)
                {
                    onError(error);
                }
                yield break;
            }

            if (onSuccess != null)
            {
                onSuccess();
            }
        }
コード例 #2
0
        public static IEnumerator PostMessage(
            PostMessageData data,
            Action onSuccess        = null,
            Action <string> onError = null
            )
        {
            var form = new WWWForm();

            form.AddField("token", data.token);
            form.AddField("channel", data.channel);
            form.AddField("text", data.text);
            form.AddField("parse", data.parse);
            form.AddField("link_names", data.link_names);
            form.AddField("username", data.username);
            form.AddField("icon_url", data.icon_url);
            form.AddField("icon_emoji", data.icon_emoji);

            var url = "https://slack.com/api/chat.postMessage";
            var www = new WWW(url, form);

            yield return(www);

            var error = www.error;

            if (!string.IsNullOrEmpty(error))
            {
                if (onError != null)
                {
                    onError(error);
                }
                yield break;
            }

            if (onSuccess != null)
            {
                onSuccess();
            }
        }