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
- Variables
- func Manifest(name, command, baseURL string) json.RawMessage
- type API
- type CreatedApp
- type EnvFileStore
- type Handler
- type Installation
- type Options
- type SSMClient
- type SSMStore
- type SlackAPI
- func (s *SlackAPI) CreateApp(ctx context.Context, configToken string, manifest json.RawMessage) (CreatedApp, error)
- func (s *SlackAPI) ExchangeCode(ctx context.Context, clientID, clientSecret, code, redirectURI string) (Installation, error)
- func (s *SlackAPI) SetIcon(ctx context.Context, configToken, appID string, png []byte) error
- type Store
Constants ¶
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.
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 ¶
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 ¶
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.
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.
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 ¶
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.
type SlackAPI ¶
type SlackAPI struct {
// contains filtered or unexported fields
}
SlackAPI calls Slack's Web API.
func NewSlackAPI ¶
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.
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.