Slack: Create app
Create a new app at https://api.slack.com/apps (opens in a new tab) .
Once done, grab your Signing Secret
. It's needed to verify the authenticity of callbacks later on.
ASP.NET Core host: Install NuGet
$ dotnet add package Slackbot.Net.Endpoints
ASP.NET Core host: Register depencencies
Register and configure the required Signing Secret
:
Program.cs
services.AddAuthentication()
.AddSlackbotEvents(c =>
{
c.SigningSecret = Environment.GetEnvironmentVariable("SIGNING_SECRET")
});
services.AddSlackBotEvents()
ASP.NET Core host: Add callback endpoint
app.Map("/slack/event", a => a.UseSlackbot());
ASP.NET Core host: Implement an event handler:
public Task<EventHandledResponse> Handle(EventMetaData meta, AppMentionEvent @evt)
{
Console.WriteLine("App mentioned!");
return Task.FromResult(new EventHandledResponse("OK"));
}
…and register it in the container:
builder.Services.AddSlackBotEvents()
.AddAppMentionHandler<AppMentionHandler>()
Slack: Subscribe to events
- Subscribe to events (opens in a new tab), for example
app_mention
- Set the Request URL:
🔥
Hot tip! For local development & integration testing, use a tunneling tool like ngrok (opens in a new tab).