GithubHelp home page GithubHelp logo

james---- / slack.webhooks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrb0nj/slack.webhooks

1.0 2.0 0.0 103 KB

Even simpler integration with Slack's Incoming and Outgoing webhooks

License: MIT License

C# 100.00%

slack.webhooks's Introduction

Slack.Webhooks Build status NuGet Version

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

*** v1.0.0 BREAKING CHANGES ***

We no longer use RestSharp in favour of HttpClient - this however means that .NET 4.0 and below are no longer supported.

Also, the PostAsync method signature has changed. The return type is now Task<bool> in place of Task<IRestResponse> which was tied directly to RestSharp.

Outgoing Webhooks

Blog Post

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 JSON.net
  3. Compatible with .NET 4.5+ and .NET Core. If you need .NET 3.5/4 you can use an older release, but this may be out of date.

Download:

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

PM> Install-Package Slack.Webhooks

For older .NET framework support:

PM> Install-Package Slack.Webhooks -Version 0.1.8

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);

slack.webhooks's People

Contributors

mrb0nj avatar jhofker avatar jchannon avatar benelliottbv avatar asizikov avatar domwilliamsredweb avatar james---- avatar jlnpinheiro avatar synthetik avatar mteper avatar pmacca avatar wattsk09 avatar

Stargazers

Sheing Ng avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.