I am trying to get a program I wrote in C# to post to a Slack channel through a Slack App but using formatting suggested here: https://api.slack.com/tools/block-kit-builder
I have this code below which posts to the Slack channel so I know that is working.
{
static void Main(string[] args)
{
PostWebHookAsync();
Console.ReadLine();
}
static async void PostWebHookAsync()
{
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "my-webhook-link"))
{
string jsonValue = JsonConvert.SerializeObject(new
{
type = "section",
text = "Some text \n new line \t tab",
}
);
Console.WriteLine(jsonValue);
Type valueType = jsonValue.GetType();
if (valueType.IsArray)
{
jsonValue = jsonValue.ToString();
Console.WriteLine("Array Found");
}
request.Content = new StringContent(jsonValue, Encoding.UTF8, "application/json");
var response = await httpClient.SendAsync(request);
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Content);
}
}
}
}
Which returns:
{"type":"section","text":"Some text \n new line \t tab"}
Now I want to POST this
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a mrkdwn section block :ghost: *this is bold*, and ~this is crossed out~, and <https://google.com|this is a link>"
}
}
But I am struggling to understand what to change this block of code for
string jsonValue = JsonConvert.SerializeObject(new
{
type = "section",
text = "Some text \n new line \t tab",
}