Example #1
0
        /// <summary>
        /// Post a message using a Payload object
        /// </summary>
        /// <param name="payload"></param>
        protected void PostMessage(JandiPayload payload)
        {
            //建立 HttpClient
            HttpClient client = new HttpClient()
            {
                BaseAddress = new Uri(_Url)
            };

            // 將 data 轉為 json
            string json = JsonConvert.SerializeObject(payload);
            // 將轉為 string 的 json 依編碼並指定 content type 存為 httpcontent
            HttpContent contentPost = new StringContent(json, Encoding.UTF8, "application/json");

            // 發出 post 並取得結果
            HttpResponseMessage response = client.PostAsync(new Uri(_Url), contentPost).GetAwaiter().GetResult();

            // 將回應結果內容取出並轉為 string 再透過 linqpad 輸出
            response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
        }
Example #2
0
        /// <summary>
        /// Post a message using simple strings
        /// </summary>
        /// <param name="text"></param>
        /// <param name="title"></param>
        protected void PostMessage(string text, string title)
        {
            List <connectInfo> info_ = new List <connectInfo>()
            {
                new connectInfo()
                {
                    title       = title,
                    description = text,
                    imageUrl    = ""
                }
            };

            JandiPayload payload = new JandiPayload()
            {
                body         = "你有一個通知",
                connectColor = "#FAC11B",
                connectInfo  = info_
            };

            PostMessage(payload);
        }