slack

package
v0.0.0-...-8e0f7c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package slack supports invoking the randomizer as a Slack slash command.

Index

Constants

View Source
const DefaultAWSParameterTTL = 2 * time.Minute

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// TokenProvider provides the expected value of the slash command verification
	// token generated by Slack. This can be obtained from the slash command
	// configuration.
	TokenProvider TokenProvider
	// StoreFactory provides a Store for the Slack channel in which the request
	// was made.
	StoreFactory store.Factory
	// Logger, if non-nil, will be used to report information about errors that
	// occur while handling each request.
	Logger *slog.Logger
}

App provides HTTP handling logic that allows the randomizer to be integrated as a slash command in a Slack workspace.

Note that App currently only supports static verification tokens to check that a request legitimately originated from Slack, and does not support the newer signed secrets functionality.

func (App) ServeHTTP

func (a App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles the POST request that Slack makes to invoke the randomizer slash command.

type TokenProvider

type TokenProvider func(ctx context.Context) (string, error)

TokenProvider provides the value of the slash command verification token generated by Slack.

func AWSParameter

func AWSParameter(name string, ttl time.Duration) TokenProvider

AWSParameter retrieves the expected value of the verification token from the AWS SSM Parameter Store, decrypting it if necessary, and caches the retrieved token value for the provided TTL.

func StaticToken

func StaticToken(token string) TokenProvider

StaticToken uses token as the expected value of the verification token.

func TokenProviderFromEnv

func TokenProviderFromEnv() (TokenProvider, error)

TokenProviderFromEnv returns a TokenProvider based on available environment variables.

If SLACK_TOKEN is set, it will return a static token provider.

If SLACK_TOKEN_SSM_NAME is set, it will return an AWS SSM token provider, with the TTL optionally set by SLACK_TOKEN_SSM_TTL.

Otherwise, it will return an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL