Post to Slack when Umbraco content is published

February 03, 2015

This is an old archived post, content maybe out of date, links may be broken and layout may be broken.

Slack is very of the moment isn’t it? Thanks to damianwalsh we were early adopters at Moriyama and use it as our main internal communication tool.

One of the joys of Slack is just how easy it is to add your own integration. Here is ours that shows you how to post to a slack channel when an Umbraco document is published.

Note: You’ll need the wonderful RestSharp library from nuget.

using RestSharp;
void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs e)
  foreach (var entity in e.PublishedEntities)
    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var url = umbracoHelper.Url(entity.Id, UrlProviderMode.Relative);
    var urls = string.Format("{0} or{0}", url);
    var t = "New publish : " + entity.Name + " " + urls;
    var hash = "[email protected]".HashEmailForGravatar();
    var client = new RestClient("");
    var request = new RestRequest("/chat.postMessage", Method.POST);
    request.AddParameter("token", "");
    request.AddParameter("channel", "#mychannel");
    request.AddParameter("username", "Moriyama Bot");
    request.AddParameter("text", t);
    request.AddParameter("icon_url", string.Format("{0}", hash));
    var response = client.Execute(request);

The code is also available as a github gist.

I’d be interested to hear if anyone out there is doing any other interesting slack integrations, particularly Umbraco related.


Warren Buckley - February 16, 2015

Hi Darren, This is a handy snippet to have in your arsenal. So thanks for sharing, there is a few more ideas up my sleeves for using Slack & Umbraco, but as always time is never on my side.

We have been using Slack for a little while as well and I have written a Contour/Forms Umbraco Workflow Item so you can be notified when a form submission has been posted. As Email sucks & I never read them, so this may be of you use to you & the gang.

Link-tastic below :-)

Cheers, Warren :)

Laurence Gillian - February 20, 2015

Nice! This sparks lots of nice ideas! :-)

About the Author

About Darren

Leave a Comment

Comments are manually moderated and added once reviewed.