Skip to content

Cake AddIn that extends Cake with Slack messaging features

License

Notifications You must be signed in to change notification settings

nmbro/Cake.Slack

 
 

Repository files navigation

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

About

Cake AddIn that extends Cake with Slack messaging features

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 96.6%
  • PowerShell 3.4%