soxtoby / SlackNet

A comprehensive Slack API client for .NET
MIT License
211 stars 67 forks source link

PostToWebhook should allow for JSON building blocks #186

Closed sebastienlabine closed 8 months ago

sebastienlabine commented 10 months ago

I love strong typing, but I feel like we could benefit from sending raw json instead of a strongly typed message when using PostToWebhook.

Task PostToWebhook(string webhookUrl, Message message, CancellationToken? cancellationToken = null);

I am actually in a progress of migrating lots of precompiled json message blocks and I would pretty much prefer just to copy the raw json.

Task PostToWebhook(string webhookUrl, Message message, CancellationToken? cancellationToken = null);
Task PostToWebhook(string webhookUrl, string json, CancellationToken? cancellationToken = null);
soxtoby commented 10 months ago

Thanks for the suggestion @sebastienlabine, but once you take the typing and serialization out of PostToWebhook, I'm not sure what value SlackNet would be providing. Webhooks don't require authentication, and they don't return anything in the response, so there isn't anything Slack-specific left.

I'd suggest making with request with HttpClient directly:

using var httpClient = new HttpClient();
await httpClient.PostAsync("<webhook URL>", new StringContent("<JSON>", Encoding.UTF8, "application/json"));

Hope this helps.

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.