【发布时间】:2019-01-02 10:41:48
【问题描述】:
基本上我想将本地图像文件发布到 slack 中。该方法只接受 URL 参数,但我想传递文件的路径。有没有办法使用格式化的消息来实现这一点? 顺便说一下,我有这个网站的例子:
public class SlackAttachment
{
public string fallback { get; set; }
...
public string author_name { get; set; }
public string image_url { get; set; }
}
public static void SendMessageToSlack()
{
string token= "myTokenHere";
var sampleAttachment = new SlackAttachment[]
{
new SlackAttachment {
fallback = "this did not work",
text = "text here",
color = "0b7c1e",
pretext = "",
author_name = "myName",
author_icon = @"https://i.imgur.com/02sddfQMt9p.png",
author_link = "",
title = "no title",
title_link = "Title link here",
//image_url = @"https://i.imgur.com/U9S0CDG.png",
// cannot replace this with
// C:\Users\Public\image.png
thumb_url = @"",
footer = "footer here",
footer_icon = migrationIcon
},
};
var attachmentsJson = JsonConvert.SerializeObject(sampleAttachment);
var data = new NameValueCollection();
data["token"] = token;
data["channel"] = channelName;
data["as_user"] = "true";
data["text"] = "";
data["attachments"] = attachmentsJson;
var client = new WebClient();
var response = client.UploadValues("https://slack.com/api/chat.postMessage", "POST", data);
string responseInString = Encoding.UTF8.GetString(response);
Console.WriteLine(responseInString);
}
【问题讨论】:
标签: c# image post slack slack-api