Cake AddIn that extends Cake with Slack messaging features
Clone or download
devlead Merge branch 'release/0.12.0'
* release/0.12.0:
  Fix build script for release
Latest commit 3b26629 Jul 3, 2018
Permalink
Failed to load latest commit information.
nuspec/nuget Updated to Cake 0.26.0 Feb 28, 2018
src Fixes authorization issue posting to chat api. #25. Jun 27, 2018
tools Fix build script for release Jul 3, 2018
.gitattributes
.gitignore
LICENSE Initial commit Jan 9, 2015
README.md Fixed README formatting. Dec 10, 2015
ReleaseNotes.md Changed to use Cake Contrib icon in NuGet package Nov 23, 2017
appveyor.yml Added Cake.Recipe Dec 2, 2017
build.cake
build.ps1 Added Cake.Recipe Dec 2, 2017
samplemessage.png Initial version Jan 10, 2015
samplemessageattachment.png
setup.cake Fix build script for release Jul 3, 2018

README.md

Cake.Slack

Cake AddIn that extends Cake with Slack messaging features Build status

Usage

Post message

Using token

#addin "Cake.Slack"
var slackToken = EnvironmentVariable("SLACK_TOKEN");
var slackChannel = "#cake";
var postMessageResult = Slack.Chat.PostMessage(
            token:slackToken,
            channel:slackChannel,
            text:"This _is_ a `message` from *CakeBuild* :thumbsup:\r\n```Here is some code```"
    );

if (postMessageResult.Ok)
{
    Information("Message {0} successfully sent", postMessageResult.TimeStamp);
}
else
{
    Error("Failed to send message: {0}", postMessageResult.Error);
}

Cake output will be similar to below:

Message 1420896696.000057 successfully sent

This will result in an message in your Slack channel similar to below:

Sample message

Using incoming web hook url

#addin "Cake.Slack"
var slackhookuri = EnvironmentVariable("slackhookuri");
var slackChannel = "#cake";
var postMessageResult = Slack.Chat.PostMessage(
            channel:slackChannel,
            text:"This _is_ a `message` from *CakeBuild* :thumbsup:\r\n```Here is some code```",
            messageSettings:new SlackChatMessageSettings { IncomingWebHookUrl = slackhookuri }
    );

if (postMessageResult.Ok)
{
    Information("Message successfully sent");
}
else
{
    Error("Failed to send message: {0}", postMessageResult.Error);
}

Cake output will be similar to below:

Message successfully sent

This will result in an message in your Slack channel similar to below:

Sample message

Using message attachments

#addin "Cake.Slack"
var slackWebHookUrl = EnvironmentVariable("slackWebHookUrl");
var slackChannel = "#cake";
var slackAssemblyFieldAttachment = new SlackChatMessageAttachmentField[]
{
            new SlackChatMessageAttachmentField
            {
                Title =  "Message Attachment Title",
            	Value =  "Message Attachment Value"
            }
};
var postMessageResult = Slack.Chat.PostMessage(
	channel:slackChannel,
	text:"Starting Cake Build...",
	messageAttachments:new SlackChatMessageAttachment[]
	{
	            new SlackChatMessageAttachment
	            {
	                        Text = "Cake Text",
	                        Pretext = "Cake Pretext",
	                        Color = "#67A0E1",
	                        Fields = slackAssemblyFieldAttachment
	            }
     },
	messageSettings:new SlackChatMessageSettings { IncomingWebHookUrl = slackWebHookUrl });

if (postMessageResult.Ok)
{
    Information("Message successfully sent");
}
else
{
    Error("Failed to send message: {0}", postMessageResult.Error);
}

This will result in a message in your Slack channel similar to below:

Sample message attachment