Posting a message
In the Chat endpoint, you can use the PostMessage
message to post a new message to a Slack channel. An instance of SlackPostMessageOptions
is used to describe the message, and in it's simplest form, you can specify a channel and the main text of the message:
@using Skybrud.Social.Slack.Models.Chat
@using Skybrud.Social.Slack.Options.Chat
@using Skybrud.Social.Slack.Responses.Chat
@inherits WebViewPage<Skybrud.Social.Slack.SlackService>
@{
// Initialize the options describing the message
SlackPostMessageOptions options = new SlackPostMessageOptions {
Channel = "#general",
Text = "Here is my message"
};
// Make the request to the API
SlackPostMessageResponse response = Model.Chat.PostMessage(options);
// Get the posted message from the response body
SlackMessage message = response.Body.Message;
}
As Slack messages isn't just limited to simple text, the SlackPostMessageOptions
class has a lot of different properties that let's you tailor the message. You can see the class on GitHub for further information.