Documentation
¶
Overview ¶
Package slack (piece ③) connects Exhale to a Slack workspace over Socket Mode: a WebSocket the app opens outward, so no public URL or open port is needed (ADR 0001, 0007). Each team runs its own Slack app, created from the manifest in manifest.go.
Like the Telegram adapter it only renders action-layer messages (as Block Kit) and passes button presses and typed answers back. The app inside a message (ADR 0019) lives in the direct message with the bot and, as a permanent surface, in the app's Home tab.
For the action layer a Slack chat is always a person: ChatRef.ChatID is the Slack user id, whatever the button was pressed in (the DM, the Home tab or a shared channel). Questions that need a typed answer therefore always continue in the DM.
Index ¶
- Constants
- Variables
- func CreateURL() string
- type Adapter
- func (a *Adapter) Connected() bool
- func (a *Adapter) Edit(ctx context.Context, chatID, messageID string, m actions.Message) error
- func (a *Adapter) LastError() string
- func (a *Adapter) Name() string
- func (a *Adapter) Send(ctx context.Context, chatID string, m actions.Message) (string, error)
- func (a *Adapter) Serve(ctx context.Context) error
- func (a *Adapter) SetEngine(e *actions.Engine)
- func (a *Adapter) String() string
- func (a *Adapter) Workspace() Workspace
- type Config
- type Deliverer
- type Manager
- func (m *Manager) Configure(ctx context.Context, in Config) (Status, error)
- func (m *Manager) Deliverer(next Deliverer) Deliverer
- func (m *Manager) Edit(ctx context.Context, chatID, messageID string, msg actions.Message) error
- func (m *Manager) Name() string
- func (m *Manager) Remove(ctx context.Context) (Status, error)
- func (m *Manager) Send(ctx context.Context, chatID string, msg actions.Message) (string, error)
- func (m *Manager) Serve(ctx context.Context) error
- func (m *Manager) SetEngine(e *actions.Engine)
- func (m *Manager) Status(ctx context.Context) Status
- func (m *Manager) String() string
- type Status
- type Workspace
Constants ¶
const Manifest = `` /* 909-byte string literal not displayed */
Manifest describes the Slack app a team creates in its own workspace (api.slack.com/apps → Create New App → From a manifest). It asks for exactly what the adapter uses; docs/guides/slack.md explains each scope.
Socket Mode means no URL appears anywhere: events, button presses and the slash command all arrive over the WebSocket the app opens outward.
const Name = "slack"
Name is the channel name stored in channel links.
Variables ¶
var ErrNotRunning = errors.New("slack is not set up")
ErrNotRunning is returned when there is no Slack app to send through.
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is the Slack channel for one pair of tokens.
func New ¶
New creates the adapter. apiURL overrides the Web API URL (tests). SetEngine must be called before Serve.
func (*Adapter) Edit ¶
Edit replaces a message in place. The Home tab is edited by publishing its view again.
func (*Adapter) Serve ¶
Serve keeps the socket open until ctx is cancelled. The library reconnects when the socket drops or Slack asks for a refresh; Serve returns an error only when Slack rejects the tokens.
type Config ¶
type Config struct {
BotToken string `json:"botToken,omitempty" doc:"Bot User OAuth Token, xoxb-…"`
AppToken string `json:"appToken,omitempty" doc:"app-level token with connections:write, xapp-…"`
Channel *string `json:"channel,omitempty" doc:"channel name or id for reminders of shared subscriptions; empty to stop posting there"`
}
Config is what the owner sets from the web. Tokens are optional once the app is connected, so the channel can change on its own.
type Deliverer ¶
type Deliverer interface {
Deliver(ctx context.Context, item app.OutboxItem) error
}
Deliverer is the scheduler's delivery step.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the Slack adapter. It implements actions.Channel and the platform service interface.
func NewManager ¶
NewManager returns a manager. Tokens from the environment (both, or they are ignored) win over tokens saved from the web; apiURL overrides the Slack API URL (tests).
func (*Manager) Configure ¶
Configure checks new tokens with Slack, saves them and switches the app to them; it can also set or clear the team channel. It returns the new status.
func (*Manager) Deliverer ¶
Deliverer wraps the delivery step so that a reminder of a shared subscription is also posted once to the team channel. A failure there never fails the delivery: the scheduler would send the DMs again.
func (*Manager) Serve ¶
Serve runs the app for the current tokens and restarts it when they change, until ctx ends.
type Status ¶
type Status struct {
Configured bool `json:"configured"`
Source string `` /* 139-byte string literal not displayed */
Running bool `json:"running" doc:"the socket to Slack is open"`
Team string `json:"team,omitempty" doc:"workspace name"`
Bot string `json:"bot,omitempty" doc:"the bot's name in the workspace"`
AppURL string `json:"appUrl,omitempty" doc:"link that opens the app in Slack"`
Channel string `json:"channel,omitempty" doc:"channel where reminders of shared subscriptions are also posted"`
Error string `json:"error,omitempty" doc:"why the app is not connected, when Slack says so"`
Manifest string `json:"manifest" doc:"app manifest (YAML) to create the Slack app from"`
CreateURL string `json:"createUrl" doc:"opens Slack's create-app page with the manifest filled in"`
}
Status describes the Slack app for the settings UI. It never carries a token.