Code Monkey home page Code Monkey logo

slack.webhooks's Introduction

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

slack.webhooks's People

Contributors

mrb0nj avatar jhofker avatar jchannon avatar benelliottbv avatar asizikov avatar jimmic avatar mteper avatar

Watchers

 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.