/Slack.Webhooks

Even simpler integration with Slack's Incoming and Outgoing webhooks

Primary LanguageC#MIT LicenseMIT

Slack.Webhooks Build status NuGet Version

Even simpler integration with Slack's Incoming/Outgoing webhooks API for .net

Outgoing Webhooks

http://nerdfury.redrabbits.co.uk/2015/04/07/slack-outgoing-webhooks/

Incoming Webhooks

Requirements:

  1. You must first enable the Webhooks integration for your Slack Account to get the Token. You can enable it here: https://slack.com/services/new/incoming-webhook
  2. Slack.Webhooks depends on RestSharp

Download:

Package is hosted on Nuget and can be installed from the package manager:

PM> Install-Package Slack.Webhooks

Then, create a SlackClient with your Webhook URL.

var slackClient = new SlackClient("[YOUR_WEBHOOK_URL]");

Create a new SlackMessage

var slackMessage = new SlackMessage
{
    Channel = "#random",
    Text = "Your message",
    IconEmoji = Emoji.Ghost,
    Username = "nerdfury"
};

By default the text can contain Markdown but this default behaviour can be disabled:

slackMessage.Mrkdwn = false;

More info on message formatting can be found in the Docs

Attachments can be added to a message:

var slackAttachment = new SlackAttachment
    {
        Fallback = "New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>",
        Text = "New open task *[Urgent]*: <http://url_to_task|Test out Slack message attachments>",
        Color = "#D00000",
        Fields =
            new List<SlackField>
                {
                    new SlackField
                        {
                            Title = "Notes",
                            Value = "This is much *easier* than I thought it would be."
                        }
                }
    };
slackMessage.Attachments = new List<SlackAttachment> {slackAttachment};

Please see the Docs for further info on attachments.

And Post it to Slack

slackClient.Post(slackMessage);