slackapp

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package slackapp creates and installs the Slack app from a setup page, like the GitHub App installer does for the GitHub App: the page creates the app from a manifest, runs Slack's OAuth install, and saves the credentials where the installer saves the GitHub App's.

Index

Constants

View Source
const (
	PathSetup         = "/slack/setup"
	PathOAuthInstall  = "/slack/oauth/install"
	PathOAuthCallback = "/slack/oauth/callback"
	// PathCommands is where the application answers the slash command.
	PathCommands = "/slack/commands"
)

Paths the setup serves, under the service's base path.

View Source
const (
	EnvToken         = "APP_SLACK_TOKEN"
	EnvSigningSecret = "APP_SLACK_SIGNING_SECRET"
	EnvClientID      = "APP_SLACK_CLIENT_ID"
	EnvClientSecret  = "APP_SLACK_CLIENT_SECRET"
	// EnvTeam is the workspace the app is installed in, as "id|name". It
	// is not secret.
	EnvTeam = "APP_SLACK_TEAM"
)

The names the credentials are saved under, which are also the variables the application reads them from.

Variables

View Source
var BotScopes = []string{"chat:write", "chat:write.public", "commands"}

BotScopes are the OAuth scopes the app asks for when it is installed: posting messages, also to public channels it hasn't joined, and the slash command.

Functions

func Manifest

func Manifest(name, command, baseURL string) json.RawMessage

Manifest returns the Slack app manifest for a deployment whose external URL, including its base path, is baseURL.

Types

type API

type API interface {
	// CreateApp creates an app from a manifest with an app configuration
	// token.
	CreateApp(ctx context.Context, configToken string, manifest json.RawMessage) (CreatedApp, error)
	// SetIcon sets an app's icon with an app configuration token.
	SetIcon(ctx context.Context, configToken, appID string, png []byte) error
	// ExchangeCode finishes an OAuth install and returns its bot token.
	ExchangeCode(ctx context.Context, clientID, clientSecret, code, redirectURI string) (Installation, error)
}

API is the part of Slack's Web API the setup uses.

type CreatedApp

type CreatedApp struct {
	AppID         string
	ClientID      string
	ClientSecret  string
	SigningSecret string
}

CreatedApp is a new app's ID and credentials.

type EnvFileStore

type EnvFileStore struct {
	// contains filtered or unexported fields
}

EnvFileStore keeps credentials in an env file, the one the GitHub App installer writes. Saving replaces the lines of the saved names and keeps every other line as it is.

func NewEnvFileStore

func NewEnvFileStore(path string) *EnvFileStore

NewEnvFileStore creates a store that keeps credentials in the env file at path.

func (*EnvFileStore) Get

func (s *EnvFileStore) Get(_ context.Context, name string) (string, error)

Get returns a credential's value, or "" if the file or name is missing.

func (*EnvFileStore) Save

func (s *EnvFileStore) Save(_ context.Context, values map[string]string) error

Save writes credentials to the env file.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the setup pages. Like the GitHub App installer, it is meant to be enabled only until the app is installed. Until then, anyone who can reach it can create and install the app, so the installed app's credentials are never replaced, and it can't be moved to another workspace.

func New

func New(opts Options) (*Handler, error)

New creates a Handler.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the setup paths, which are relative to the base path.

type Installation

type Installation struct {
	BotToken string
	TeamID   string
	TeamName string
	AppID    string
	// UserID is who installed the app.
	UserID string
}

Installation is the result of an OAuth install.

type Options

type Options struct {
	// Name and Command are the app's name and slash command.
	Name    string
	Command string
	// PublicURL is the service's external URL, including its base path.
	// When empty, it is derived from each request and BasePath.
	PublicURL string
	BasePath  string
	Store     Store
	API       API
	// Icon is the app's icon, a PNG of 512 to 2000 pixels a side.
	Icon   []byte
	Logger *slog.Logger
	// OnInstalled runs after the bot token is saved, to load it.
	OnInstalled func(ctx context.Context)
	// Channels returns the channel IDs the app posts in, when they are
	// known.
	Channels func() []string
}

Options configures the setup Handler.

type SSMClient

type SSMClient interface {
	GetParameter(ctx context.Context, in *ssm.GetParameterInput, opts ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
	PutParameter(ctx context.Context, in *ssm.PutParameterInput, opts ...func(*ssm.Options)) (*ssm.PutParameterOutput, error)
}

SSMClient is the part of the SSM API the SSM store uses.

type SSMStore

type SSMStore struct {
	// contains filtered or unexported fields
}

SSMStore keeps each credential in a parameter named prefix + name, as SecureStrings, except the team, which isn't secret.

func NewSSMStore

func NewSSMStore(ctx context.Context, prefix, kmsKeyID string, client SSMClient) (*SSMStore, error)

NewSSMStore creates a store under prefix. kmsKeyID encrypts the parameters; empty uses the aws/ssm key. A nil client is created from the default AWS configuration, which makes no network calls.

func (*SSMStore) Get

func (s *SSMStore) Get(ctx context.Context, name string) (string, error)

Get returns a credential's value, or "" if its parameter doesn't exist.

func (*SSMStore) Save

func (s *SSMStore) Save(ctx context.Context, values map[string]string) error

Save writes each credential to its parameter.

type SlackAPI

type SlackAPI struct {
	// contains filtered or unexported fields
}

SlackAPI calls Slack's Web API.

func NewSlackAPI

func NewSlackAPI(httpClient *http.Client, apiURL string) *SlackAPI

NewSlackAPI creates a SlackAPI. apiURL overrides Slack's API URL, for tests; it ends with a slash.

func (*SlackAPI) CreateApp

func (s *SlackAPI) CreateApp(ctx context.Context, configToken string, manifest json.RawMessage) (CreatedApp, error)

CreateApp creates an app from a manifest.

func (*SlackAPI) ExchangeCode

func (s *SlackAPI) ExchangeCode(ctx context.Context, clientID, clientSecret, code, redirectURI string) (Installation, error)

ExchangeCode finishes an OAuth install.

func (*SlackAPI) SetIcon

func (s *SlackAPI) SetIcon(ctx context.Context, configToken, appID string, png []byte) error

SetIcon sets an app's icon.

type Store

type Store interface {
	// Get returns the saved value of a credential, or "".
	Get(ctx context.Context, name string) (string, error)
	// Save saves credentials, replacing saved values.
	Save(ctx context.Context, values map[string]string) error
}

Store reads and writes the Slack app's credentials.

Jump to

Keyboard shortcuts

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