Skip to content

Commit

Permalink
Adds docs link
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkors committed Jul 9, 2023
1 parent dfc5234 commit 3e0212c
Showing 1 changed file with 2 additions and 86 deletions.
88 changes: 2 additions & 86 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,6 @@ An opinionated ASP.NET Core middleware to create simple Slackbots using the Slac
### Install
Download it from NuGet:[![NuGet](https://img.shields.io/nuget/dt/slackbot.net.endpoints.svg)](https://www.nuget.org/packages/slackbot.net.endpoints/)

`$ dotnet add package slackbot.net.endpoints`
### Docs

### Supported events
- `challenge`
- `app_mention`
- `view_submission`
- `member_joined_channel`



## Configuration

A slack app can be distributed either as a single-workspace application (1 single Slack token), or as a _distributed_ Slack application where other workspaces can install it them self either via a web page, or via the Slack App Store.
### Single workspace Slack app


```csharp
var builder = WebApplication.CreateBuilder(args);

// Needed to verify that incoming event payloads are from Slack
builder.Services.AddAuthentication()
.AddSlackbotEvents(c =>
c.SigningSecret = Environment.GetEnvironmentVariable("SIGNING_SECRET")
);

// Setup event handlers
builder.Services.AddSlackBotEvents()
.AddAppMentionHandler<DoStuff>()


var app = builder.Build();
app.UseSlackbot(); // event endpoint
app.Run();

class DoStuff : IHandleAppMentions
{
public bool ShouldHandle(AppMentionEvent slackEvent) => slackEvent.Text.Contains("hi");

public Task<EventHandledResponse> Handle(EventMetaData meta, AppMentionEvent @evt)
{
Console.WriteLine("Doing stuff!");
return Task.FromResult(new EventHandledResponse("yolo"));
}
}
```

### Advanced: Distributed Slack app

Implement the `ITokenStore` to store/remote on install/uninstall flows.

```csharp
var builder = WebApplication.CreateBuilder(args);

// Needed to verify that incoming event payloads are from Slack
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);
}
```

### Samples

Check the [samples](/Samples/).
Check the docs: https://slackbot-net.vercel.app/

0 comments on commit 3e0212c

Please sign in to comment.