Slack is my favourite app at the moment, and I've been obsessing about integrating it with everything lately.  This post gives you the code and simple instructions on how to create your own custom integration for slack, written in C# for .NET.

Getting started

On the slack site, go to the page to set up an incoming webhook, sign into your Slack account.  
Where it says Post to Channel, choose #general and click on 'Add Incoming WebHooks Integration'
Copy the WebHook URL and paste it in a notepad or somewhere for later.

The Code

Add this class somewhere in your project.

//Written by Paul Seal for
//Free for use by anyone however they want
//Buy me a coffee sometime, or donate on my PayPal link if you want.

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Slack.Net
    /// <summary>
    /// This is the main class for Slack Messages
    /// </summary>
    public class Message
        public string PostUrl { get; set; }
        public string Text { get; set; }
        public string Channel { get; set; }
        public string Icon_Emoji { get; set; }
        public string Username { get; set; }
        private string PostData
                StringBuilder postData = new StringBuilder();

                if (!String.IsNullOrEmpty(this.Text))
                    postData.Append("\"text\":\"" + this.Text + "\"");

                if (!String.IsNullOrEmpty(this.Channel))
                    postData.Append(",\"channel\":\"" + this.Channel + "\"");
                if (!String.IsNullOrEmpty(this.Icon_Emoji))
                    postData.Append(",\"icon_emoji\":\"" + this.Icon_Emoji + "\"");

                if (!String.IsNullOrEmpty(this.Username))
                    postData.Append(",\"username\": \"" + this.Username + "\"");
                return postData.ToString();
        /// <summary>
        /// Constructor for the Message class
        /// </summary>
        /// <param name="postUrl">The Webhook URL</param>
        /// <param name="text">The message to send</param>
        /// <param name="channel">The channel name if you want to send the message to a different channel</param>
        /// <param name="icon_emoji">The emoji to use for the icon of the BOT user</param>
        /// <param name="username">The name to use for the BOT user</param>
        public Message(string postUrl, string text, string channel = null, string icon_emoji = null, string username = null)
            PostUrl = postUrl;
            Text = text;
            Channel = channel;
            Icon_Emoji = icon_emoji;
            Username = username;

        /// <summary>
        /// Calls the method to process the web request
        /// </summary>
        /// <returns>A string value for the response from the server</returns>
        public string Send()
            return ProcessRequest(this.PostUrl, this.PostData);

        /// <summary>
        /// Simple method for processing web requests
        /// </summary>
        /// <param name="postUrl">The url to post to</param>
        /// <param name="postData">The data to post in the web request</param>
        /// <returns>A string value for the response from the server</returns>
        private string ProcessRequest(string postUrl, string postData)
            WebRequest request = WebRequest.Create(postUrl);
            request.Method = "POST";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            WebResponse response = request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            return responseFromServer;

Now to use this code you can just call it like this, remember to use your WebHook URL:

public class Program
    public static void Main()
        string webhookUrl = "";
        string text = "Testing slack integration";
        string channelName = "#general";
        string emojiIcon = ":computer:";
        string username = "";
        Slack.Net.Message message = new Slack.Net.Message(webhookUrl, text, channelName, emojiIcon, username);

In the example above you can see I entered the text of the message, channelName, emojiIcon and username. The last 3 are optional so you can set them as null or leave them off if you want. 

If you have created your webhook link you can test it out quickly here on

Try it out and let me know how you get on.

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Proudly sponsored by


  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.

  • is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.

  • More than a theme for Umbraco CMS, take full control of your content and design with a feature-rich, award-nominated & content editor focused website platform.

  • Affordable, Geo-Redundant, Umbraco hosting which gives back to the community by sponsoring an Umbraco Open Source Developer with each hosting package sold.