Documentation
¶
Overview ¶
Package slack provides a DataSource connector that enumerates Slack channel messages for vectorization. It uses the Slack Web API (conversations.history) and requires a bot token with channels:history and channels:read.
Package slack provides a Messenger adapter for the Slack platform.
This file implements the HTTP Events API handler (eventsHTTPHandler), enabling Slack to receive events via HTTP push instead of Socket Mode. This allows the adapter to be mounted on a shared HTTP mux at a context path (e.g., /agents/{name}/slack/events) rather than requiring its own WebSocket connection or dedicated port.
The Events API is Slack's recommended approach for production apps that have a publicly accessible endpoint. It delivers events as signed HTTP POST requests. See: https://api.slack.com/events-api
Package slack provides a Messenger adapter for the Slack platform using Socket Mode for bi-directional communication without a public endpoint.
The adapter wraps github.com/slack-go/slack and its Socket Mode client. Incoming events are received over a WebSocket connection, and outgoing messages are sent via the Slack Web API.
Transport: Socket Mode (WebSocket — no public endpoint required).
Authentication ¶
Two tokens are required:
- An app-level token (xapp-…) with the connections:write scope for Socket Mode.
- A bot user OAuth token (xoxb-…) with chat:write and other desired scopes.
Usage ¶
m := slack.New(slack.Config{
AppToken: os.Getenv("SLACK_APP_TOKEN"),
BotToken: os.Getenv("SLACK_BOT_TOKEN"),
})
if err := m.Connect(ctx); err != nil { /* handle */ }
defer m.Disconnect(ctx)
Index ¶
- type Config
- type Messenger
- func (m *Messenger) Connect(ctx context.Context) (http.Handler, error)
- func (m *Messenger) ConnectionInfo() string
- func (m *Messenger) Disconnect(ctx context.Context) error
- func (m *Messenger) FormatApproval(req messenger.SendRequest, info messenger.ApprovalInfo) messenger.SendRequest
- func (m *Messenger) FormatClarification(req messenger.SendRequest, info messenger.ClarificationInfo) messenger.SendRequest
- func (m *Messenger) Platform() messenger.Platform
- func (m *Messenger) Receive(_ context.Context) (<-chan messenger.IncomingMessage, error)
- func (m *Messenger) Send(ctx context.Context, req messenger.SendRequest) (messenger.SendResponse, error)
- func (m *Messenger) UpdateMessage(ctx context.Context, req messenger.UpdateRequest) error
- type SlackConnector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// AppToken is the Slack app-level token (xapp-...) required for Socket Mode.
// Not needed when using HTTP Events API mode (SigningSecret + SharedMux).
AppToken string
// BotToken is the Slack bot user OAuth token (xoxb-...).
BotToken string
// SigningSecret is used to verify incoming HTTP Events API requests.
// When set together with WithSharedMux(), the adapter operates in HTTP
// push mode instead of Socket Mode: incoming events arrive as signed
// HTTP POST requests rather than over a WebSocket connection.
// See: https://api.slack.com/authentication/verifying-requests-from-slack
SigningSecret string
}
Config holds Slack-specific configuration.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger implements the messenger.Messenger interface for Slack. It supports two transport modes:
- Socket Mode (default): outbound WebSocket, no public endpoint required.
- HTTP Events API: inbound HTTP push, requires SigningSecret + SharedMux.
It manages the event routing, incoming message buffer, and connection state through an internal mutex.
func (*Messenger) Connect ¶
Connect establishes a connection to Slack and returns an optional http.Handler.
In HTTP Events API mode (SigningSecret set): returns a non-nil handler that the caller mounts at a context path. Events arrive as signed HTTP POST requests.
In Socket Mode (default): returns nil handler and opens an outbound WebSocket connection. No inbound HTTP required.
func (*Messenger) ConnectionInfo ¶
ConnectionInfo returns connection instructions for the Slack adapter.
func (*Messenger) Disconnect ¶
Disconnect gracefully shuts down the Slack connection.
func (*Messenger) FormatApproval ¶
func (m *Messenger) FormatApproval(req messenger.SendRequest, info messenger.ApprovalInfo) messenger.SendRequest
FormatApproval builds a Slack Block Kit message for an approval notification. This satisfies the messenger.ApprovalFormatter interface, keeping all Slack-specific formatting inside the Slack adapter.
func (*Messenger) FormatClarification ¶
func (m *Messenger) FormatClarification(req messenger.SendRequest, info messenger.ClarificationInfo) messenger.SendRequest
FormatClarification builds a Slack Block Kit message for a clarification question.
func (*Messenger) Send ¶
func (m *Messenger) Send(ctx context.Context, req messenger.SendRequest) (messenger.SendResponse, error)
Send delivers a message to a Slack channel or thread. If req.Type is SendTypeReaction, adds an emoji reaction to the message identified by ReplyToMessageID (format "channelID:ts"). If req.Metadata["blocks"] contains a []slack.Block, the message is sent with Block Kit formatting.
func (*Messenger) UpdateMessage ¶
UpdateMessage replaces the content of a previously sent Slack message using the chat.update API. Used to disarm approval/clarification buttons after resolution (e.g. replacing buttons with "✅ Approved by @user").
The MessageID must be in the "channelID:timestamp" format returned by Send. If Metadata["blocks"] is set, the blocks are used for the update.
type SlackConnector ¶
type SlackConnector struct {
// contains filtered or unexported fields
}
SlackConnector implements datasource.DataSource for Slack channels. It fetches conversation history for each channel in scope and returns normalized items (one per message) for the sync pipeline to vectorize.
func NewSlackConnector ¶
func NewSlackConnector(api *slack.Client) *SlackConnector
NewSlackConnector returns a DataSource that lists messages from Slack channels. The caller must provide an authenticated slack.Client (e.g. from slack.New(botToken)); the connector uses conversations.history and does not connect via Socket Mode.
func (*SlackConnector) ListItems ¶
func (c *SlackConnector) ListItems(ctx context.Context, scope datasource.Scope) ([]datasource.NormalizedItem, error)
ListItems fetches messages from each channel in scope.SlackChannelIDs and returns them as NormalizedItems. Each message becomes one item with ID "slack:channelID:timestamp" and content equal to the message text.
func (*SlackConnector) Name ¶
func (c *SlackConnector) Name() string
Name returns the source identifier for Slack.