Distributed Slack apps
If you want your app to be Distributed, there's a little more work to be done than in the Single workspace scenario. A distributed app includes anyone being able to install the app from a install_url, and you keeping track of Slack tokens on behalf of the workspaces.
In Slackbot.NET, that means implementing a ITokenStore
and exposing certain OAuth endpoints:
Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication()
.AddSlackbotEvents(c => c.
SigningSecret = Environment.GetEnvironmentVariable("SIGNING_SECRET")
);
builder.Services.AddSlackbotDistribution(c => {
c.CLIENT_ID = Environment.GetEnvironmentVariable("CLIENT_ID");
c.CLIENT_SECRET = Environment.GetEnvironmentVariable("CLIENT_SECRET");
});
// Setup event handlers
builder.Services.AddSlackBotEvents<MyTokenStore>()
.AddAppMentionHandler<DoStuff>()
var app = builder.Build();
app.Map("/authorize", a => a.UseSlackbotDistribution()); // OAuth callback endpoint
app.Map("/events", a => a.UseSlackbot()); // event endpoint
app.Run();
/// Bring-your-own-token-store:
class MyTokenStore : ITokenStore
{
// _db is some persistance technology you choose (sql, mongo, whatever)
public Task<Workspace Delete(string teamId) => _db.DeleteByTeamId(teamId);
public Task Insert(Workspace slackTeam) => _db.Insert(slackTeam);
}
Install URL
A shareable link to install your slack app can be generated by filling in the blanks:
https://slack.com/oauth/v2/authorize?
&user_scope=
&scope={SCOPES}
&client_id={CLIENT_ID}
&redirect_uri={REDIRECT_URI}