The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Slack.NetStandard.Annotations, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Slack.NetStandard.Annotations@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
Library that uses method attributes to generate a Slack app
Creating an Slack App
To create an app, add Slack.NetStandard.Annotations as a NuGet reference and then you can tag a class with the SlackApp attribute. The big requirement is that the class has to be partial as the generator adds code to your class behind the scenes.
The code generated uses the attributes to match methods to incoming requests, and maps the method parameters for you
using Slack.NetStandard.Annotations.Markers;
using Slack.NetStandard.EventsApi.CallbackEvents;
using Slack.NetStandard.Interaction;
namespace ExampleApp
{
[SlackApp]
public partial class Example
{
[RespondsToEventCallback(typeof(AppHomeOpened))]
public async Task
These attributes add several Execute methods to your class which can be called from your code, and work with existing Slack.NetStandard objects
public Task Execute(SlackContext context)
public Task Execute(Envelope envelope)
public Task Execute(Slack.NetStandard.EventsApi.Event @event)
public Task Execute(InteractionPayload InteractionPayload)
public Task Execute(SlashCommand slashCommand)
What about the return value? Why does it only return object?
This is the default return value assumed by the generator if you just use the standard SlackApp attribute.
You can pass in a Type parameter if you want the return type to be something else
[SlackApp(typeof(ApiGatewayProxyResponse))]
public class ExampleApp {
[RespondsToEventCallback(typeof(AppHomeOpened))]
public async Task GenerateHome(AppHomeOpened appHome)
{
return Task.FromResult((object)null!);
}
...
What if I want a method to match more specific criteria?
In this case there is the SlackMatches attribute that you can use to point to a static method within the class.
This method must have the signature static bool MethodName(SlackContext) and it will be used as a secondary check on top of the standard attribute matching
For example
There are several attributes available right now. The method name you attach these two doesn't matter and can be called anything, they're just examples.
RespondsToEventCallback
This attribute triggers the method if a particular type of callback event (So a high level type of EventCallback and it's Event property is the type you passed in)
The first parameter is the type of callback event
[RespondsToEventCallback(typeof(AppHomeOpened))]
public async Task GenerateHome(AppHomeOpened appHome)
The callback event can then be passed in to your method as a parameter (as well as the usual SlackContext object)
RespondsToEvent
This attribute indicates that the method is to be triggered in response to a particular high level event type, the event type name is indicated by the parameter passed in.
[RespondsToEvent(typeof(UrlVerification))]
public async Task VerifyUrl(UrlVerification appHome)
The event type can then be passed in to your method as a parameter (as well as the usual SlackContext object)
RespondsToInteraction
Use this attribute when you want a particular interaction payload.
The first parameter is the type of payload.
The second optional parameter is the payload CallbackId property (or in the case of the BlockActionsPayload it's the first ActionId)
[RespondsToInteraction(typeof(BlockActionsPayload), "actionId")]
public async Task BlockActionPayloadResponse(BlockActionsPayload blocks)
The interaction payload can be used by your method as a passed in parameter (as well as the usual SlackContext object)
RespondsToCommand
This attribute ensures your method is triggered by a command
The command name is passed in as the first attribute parameter
[RespondsToSlashCommand("command2")]
public async Task ExampleAsyncCommand(SlashCommand command)
The command can then be passed in as a method parameter (as well as the usual SlackContext object)
Product
VersionsCompatible and additional computed target framework versions.
.NET
net5.0net5.0 was computed. net5.0-windowsnet5.0-windows was computed. net6.0net6.0 was computed. net6.0-androidnet6.0-android was computed. net6.0-iosnet6.0-ios was computed. net6.0-maccatalystnet6.0-maccatalyst was computed. net6.0-macosnet6.0-macos was computed. net6.0-tvosnet6.0-tvos was computed. net6.0-windowsnet6.0-windows was computed. net7.0net7.0 was computed. net7.0-androidnet7.0-android was computed. net7.0-iosnet7.0-ios was computed. net7.0-maccatalystnet7.0-maccatalyst was computed. net7.0-macosnet7.0-macos was computed. net7.0-tvosnet7.0-tvos was computed. net7.0-windowsnet7.0-windows was computed. net8.0net8.0 was computed. net8.0-androidnet8.0-android was computed. net8.0-browsernet8.0-browser was computed. net8.0-iosnet8.0-ios was computed. net8.0-maccatalystnet8.0-maccatalyst was computed. net8.0-macosnet8.0-macos was computed. net8.0-tvosnet8.0-tvos was computed. net8.0-windowsnet8.0-windows was computed. net9.0net9.0 was computed. net9.0-androidnet9.0-android was computed. net9.0-browsernet9.0-browser was computed. net9.0-iosnet9.0-ios was computed. net9.0-maccatalystnet9.0-maccatalyst was computed. net9.0-macosnet9.0-macos was computed. net9.0-tvosnet9.0-tvos was computed. net9.0-windowsnet9.0-windows was computed. net10.0net10.0 was computed. net10.0-androidnet10.0-android was computed. net10.0-browsernet10.0-browser was computed. net10.0-iosnet10.0-ios was computed. net10.0-maccatalystnet10.0-maccatalyst was computed. net10.0-macosnet10.0-macos was computed. net10.0-tvosnet10.0-tvos was computed. net10.0-windowsnet10.0-windows was computed.
.NET Core
netcoreapp2.0netcoreapp2.0 was computed. netcoreapp2.1netcoreapp2.1 was computed. netcoreapp2.2netcoreapp2.2 was computed. netcoreapp3.0netcoreapp3.0 was computed. netcoreapp3.1netcoreapp3.1 was computed.
.NET Standard
netstandard2.0netstandard2.0 is compatible. netstandard2.1netstandard2.1 was computed.
.NET Framework
net461net461 was computed. net462net462 was computed. net463net463 was computed. net47net47 was computed. net471net471 was computed. net472net472 was computed. net48net48 was computed. net481net481 was computed.
MonoAndroid
monoandroidmonoandroid was computed.
MonoMac
monomacmonomac was computed.
MonoTouch
monotouchmonotouch was computed.
Tizen
tizen40tizen40 was computed. tizen60tizen60 was computed.