json - Post image into Slack using Incoming Webhook C# -
i'm trying post image slack i'm having trouble. create httpwebrequest post message slack , use javascriptserializer serialize message json formatted string so:
string json = new javascriptserializer().serialize(new { username = username, image_url = imageurl, text = message, icon_emoji = icon, channel = channelname }); streamwriter.write(json); i'm trying add image message far have been unsuccessful. tried adding attachment slack suggusted don't think i'm formatting right. i've tried
string json = new javascriptserializer().serialize(new { username = username, image_url = imageurl, text = message, icon_emoji = icon, channel = channelname, attachments = new {image_url = www.myurllink.com} }); streamwriter.write(json); even though string seems set correctly fails post image, or other information include in slack attachment.
so got answer, needed create new array object set array equal new element of image_url.
string json = new javascriptserializer().serialize(new { username = username, text = message, icon_emoji = icon, channel = channelname, attachments = new []{ new {image_url = "www.imageurl.com", title = "image of " + datetime.now}} }); i added title show how add multiple elements. don't need declare new element each item want add attachment. separate commas.
Comments
Post a Comment