Skip to content

Instantly share code, notes, and snippets.

@andrewserong
Created April 19, 2016 01:35
Show Gist options
  • Save andrewserong/e533234d93a149d36fe78116b1edd7f2 to your computer and use it in GitHub Desktop.
Save andrewserong/e533234d93a149d36fe78116b1edd7f2 to your computer and use it in GitHub Desktop.
ACMI's version of "Post to Slack when Umbraco content is published"
private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
// Slack integration based on: http://blog.darren-ferguson.com/2015/02/03/post-to-slack-when-umbraco-content-is-published/
var slackUrl = SiteSettings.Settings.SlackHookPublishUrl;
var slackLinksPrefix = SiteSettings.Settings.SlackHookLinksPrefix;
if (slackUrl != null && slackLinksPrefix != null)
{
foreach (var entity in e.PublishedEntities)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var url = umbracoHelper.Url(entity.Id, Umbraco.Web.Routing.UrlProviderMode.Relative);
var urls = slackLinksPrefix + url;
var publisherUserName = entity.GetWriterProfile();
var t = "{\"text\" : \"Page published : " + entity.Name + "\n<" + urls + ">\nUpdated by: " + publisherUserName.Name + "\"}";
var client = new RestClient("https://hooks.slack.com");
var request = new RestRequest(slackUrl, Method.POST);
request.AddParameter("payload", t);
var response = client.Execute(request);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment