Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Examples

James Marcogliese edited this page Feb 27, 2019 · 9 revisions

Sending a message to a channel

using Slack.Api.CSharp.WebApi;

string accessToken = "xoxp-EXAMPLE-ACCESS-TOKEN";     
string channel = "D0PNCRP9N";
string message = "This is a test message!";

ISlackWebAPI slackWebAPI = new SlackWebAPI(); 

PostMessageOKResponse res = slackWebAPI.Chat.PostMessage(token: accessToken, text: message, channel: channel); 

Sending a message to a channel (Async)

using Slack.Api.CSharp.WebApi;

string accessToken = "xoxp-EXAMPLE-ACCESS-TOKEN";     
string channel = "D0PNCRP9N";
string message = "This is a test message!";

ISlackWebAPI slackWebAPI = new SlackWebAPI(); 

PostMessageOKResponse res = await slackWebAPI.Chat.PostMessageAsync(token: accessToken, text: message, channel: channel); 

Using the JSON SlackEvent Wrapper in a .Net Controller

using Slack.Api.CSharp.EventsApi;

namespace slackBot.Controllers
{
    [Route("events")]
    [ApiController]
    public class EventsController : ControllerBase
    {
        [HttpPost]
        public IActionResult Event([FromBody]SlackEvent request)   // JSON will automatically map to SlackEvent object.
        {
             // DoSomething();
        }
    }
}

Using the JSON SlackAction Wrapper in a .Net Controller

using Slack.Api.CSharp.EventsApi;

namespace slackBot.Controllers
{
    [Route("events")]
    [ApiController]
    public class EventsController : ControllerBase
    {
        [HttpPost]
        public IActionResult Event([FromBody]SlackAction request)   // JSON will automatically map to SlackAction object.
        {
             // DoSomething();
        }
    }
}